shwstppr opened a new pull request #3606: VM ingestion
URL: https://github.com/apache/cloudstack/pull/3606
 
 
   ## Description
   Documentation PR: https://github.com/apache/cloudstack-documentation/pull/84
   FS Doc: https://cwiki.apache.org/confluence/display/CLOUDSTACK/VM+Ingestion
   
   VM ingestion feature allows CloudStack to discover, on-board, import 
existing VMs in an infra. The feature currently works only for VMware, with a 
hypervisor agnostic framework which may be extended for KVM and XenServer in 
future.
   Two new APIs have been added, `listUnmanagedInstances` and 
`importUnmanagedInstance`.
   ### listUnmanagedInstances
   API will list all unmanaged virtual machine for a give cluster. Optionally, 
name for an existing unmanaged virtual machine can be given to retrieve VM 
details.
   **API request params -** 
   `clusterid`(UUID of cluster)
   `name`(instance name)
   **Response -**
   `clusterid`
   `hostid`
   `name`
   `osdisplayname`
   `memory`
   `powerstate`
   `cpuCoresPerSocket`
   `cpunumber`
   `cpuspeed`
   `disk`
       - `id`
       - `capacity`
       - `controller`
       - `controllerunit`
       - `imagepath`
       - `position`
   `nic`
       - `id`
       - `macaddress`
       - `networkname`
       - `vlanid`
       - `pcislot`
   
   ### importUnmanagedInstance
   API will import an exisitng unmanaged virtual machine into CloudStack for a 
given cluster and virtual machine name. Service offering for the VM, disk 
offerings for volumes and networks for NICs of the VM can be mapped. Some 
optional parameters like projectid, domainid, hostname, details, etc can also 
be given. Appropritate networks, service offering and disk offerings need to be 
present before import and cannot be created on the fly during the API call.
   **API request params -** 
   `clusterid`(UUID of cluster)
   `name`(instance name)
   `displayname`
   `hostname`
   `domainid`
   `projectid`
   `templateid`
   `serviceofferingid`
   `nicnetworklist`(Map for NIC ID and corresponding Network UUID)
   `datadiskofferinglist`(Map for disk ID and corresponding disk offering UUID)
   `details`(Map for VM details)
   `migrateallowed`(VM and its volumes are allowed to migrate to different 
host/pool 
   **Response -** 
   Same response as that of `deployVirtualMachine` API
   
   A python based script (scripts/vm/hypervisor/vmware/discover_networks.py) 
has been created to aid migrations. It leverages VMware’s pyvmomi library 
(https://github.com/vmware/pyvmomi) and allows listing all networks for a 
vCenter host or cluster.
   
   This script can take following arguments,
   ```
   -h, --help show this help message and exit
   -s HOST, --host HOST vSphere service to connect to
   -o PORT, --port PORT Port to connect on
   -u USER, --user USER User name to use
   -p PASSWORD, --password PASSWORD Password to use
   -c CLUSTER, --cluster CLUSTER Cluster for which discover networks
   -S, --disable_ssl_verification Disable ssl host certificate verification
   -d, --debug Debug log messages
   ```
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Put an `x` in all the 
boxes that apply: -->
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [x] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   ## API sample calls:
   **List**
   ```
   > list unmanagedinstances clusterid=079a19c2-2710-4ed6-9110-027dd5e0f262 
   {
     "count": 2,
     "unmanagedinstance": [
       {
         "clusterid": "079a19c2-2710-4ed6-9110-027dd5e0f262",
         "cpucorespersocket": 1,
         "cpunumber": 1,
         "cpuspeed": 0,
         "disk": [
           {
             "capacity": 2097152,
             "controller": "ide",
             "controllerunit": 0,
             "id": "51-3001",
             "imagepath": "[8aca30d6f7803420973f01cc91c1c011] 
test-unmanaged/test-unmanaged_64.vmdk",
             "label": "Hard disk 1",
             "position": 1
           },
           {
             "capacity": 5242880,
             "controller": "scsi",
             "controllerunit": 0,
             "id": "51-2000",
             "imagepath": "[8aca30d6f7803420973f01cc91c1c011] 
test-unmanaged/test-unmanaged_63.vmdk",
             "label": "Hard disk 2",
             "position": 0
           }
         ],
         "hostid": "4ab4147a-7e40-4abe-a0e2-2fac1aa6f0bf",
         "memory": 512,
         "name": "test-unmanaged",
         "nic": [
           {
             "id": "Network adapter 1",
             "macaddress": "02:00:39:7c:00:24",
             "networkname": "cloud.guest.1212.200.1-vSwitch1",
             "vlanid": 1212
           }
         ],
         "osdisplayname": "CentOS 4/5 or later (64-bit)",
         "powerstate": "POWERED_ON"
       }
     ]
   }
   ```
   **Import**
   ```
   > import unmanagedinstance name=test-unmanaged 
templateid=200f3fe9-c845-11e9-b69f-1e003c0107c4 
clusterid=079a19c2-2710-4ed6-9110-027dd5e0f262 
serviceofferingid=c4c5b9e8-8a4a-422d-bccc-2f1bcc166c59 
datadiskofferinglist[0].disk=51-2000 
datadiskofferinglist[0].diskOffering=e9eb069f-2946-4e26-8d81-07aebba868d1 
displayname=NewVm nicNetworkList[0].nic="Network adapter 1" 
nicNetworkList[0].network=4c44312b-f009-4d33-b942-989169f3d2fc
   {
     "virtualmachine": {
       "account": "admin",
       "affinitygroup": [],
       "cpunumber": 1,
       "cpuspeed": 500,
       "created": "2019-09-05T11:32:04+0000",
       "details": {},
       "diskofferingid": "e9eb069f-2946-4e26-8d81-07aebba868d1",
       "diskofferingname": "Custom",
       "displayname": "NewVm",
       "displayvm": true,
       "domain": "ROOT",
       "domainid": "20088b4d-c845-11e9-b69f-1e003c0107c4",
       "guestosid": "2015cd08-c845-11e9-b69f-1e003c0107c4",
       "haenable": false,
       "hostid": "4ab4147a-7e40-4abe-a0e2-2fac1aa6f0bf",
       "hostname": "10.2.2.144",
       "hypervisor": "VMware",
       "id": "4fda861e-e693-4227-a8aa-1b4ce90d5041",
       "instancename": "test-unmanaged",
       "isdynamicallyscalable": false,
       "memory": 512,
       "name": "test-unmanaged",
       "nic": [
         {
           "broadcasturi": "vlan://1212",
           "extradhcpoption": [],
           "id": "61952f25-7efa-4bc2-aa92-ecd38c122e65",
           "isdefault": true,
           "isolationuri": "vlan://1212",
           "macaddress": "02:00:39:7c:00:24",
           "networkid": "4c44312b-f009-4d33-b942-989169f3d2fc",
           "networkname": "lol",
           "secondaryip": [],
           "traffictype": "Guest",
           "type": "L2"
         }
       ],
       "ostypeid": "2015cd08-c845-11e9-b69f-1e003c0107c4",
       "passwordenabled": false,
       "rootdeviceid": 0,
       "rootdevicetype": "ROOT",
       "securitygroup": [],
       "serviceofferingid": "c4c5b9e8-8a4a-422d-bccc-2f1bcc166c59",
       "serviceofferingname": "Small Instance",
       "state": "Stopped",
       "tags": [],
       "templatedisplaytext": "CentOS 5.3(64-bit) no GUI (vSphere)",
       "templateid": "200f3fe9-c845-11e9-b69f-1e003c0107c4",
       "templatename": "CentOS 5.3(64-bit) no GUI (vSphere)",
       "userid": "4dfc315c-c845-11e9-b69f-1e003c0107c4",
       "username": "admin",
       "zoneid": "db18d224-279d-4c08-aeef-0cb7030d0edb",
       "zonename": "pr3540-t341-vmware-65u2"
     }
   }
   ```
   
   **Usage of list_vcenter_networks script**
   ```
   ./discover_networks.py -s 192.168.1.170 -u [email protected] -p 
password -S
   
   {
     "count": 4,
     "networks": [
       {
         "cluster": "p1-c1",
         "host": "10.2.3.184",
         "portgroup": "cloud.guest.409.200.1-vSwitch1",
         "switch": "vSwitch1",
         "virtualmachines": [
           {
             "device": {
               "label": "Network adapter 1",
               "macaddress": "02:00:37:b5:00:06"
             },
             "name": "i-2-8-VM"
           },
           {
             "device": {
               "label": "Network adapter 1",
               "macaddress": "02:00:24:72:00:02"
             },
             "name": "r-4-VM"
           }
         ],
         "vlanid": "409"
       },
       {
         "cluster": "p1-c1",
         "host": "10.2.3.184",
         "portgroup": "cloud.public.7.200.1-vSwitch1",
         "switch": "vSwitch1",
         "virtualmachines": [
           {
             "device": {
               "label": "Network adapter 3",
               "macaddress": "1e:00:6f:00:00:03"
             },
             "name": "r-4-VM"
           }
         ],
         "vlanid": "7"
       },
       {
         "cluster": "p1-c1",
         "host": "10.2.3.184",
         "portgroup": "cloud.private.untagged.0.1-vSwitch0",
         "switch": "vSwitch0",
         "virtualmachines": [
           {
             "device": {
               "label": "Network adapter 1",
               "macaddress": "02:00:13:e1:00:01"
             },
             "name": "s-1-VM"
           },
           {
             "device": {
               "label": "Network adapter 2",
               "macaddress": "1e:00:07:00:00:19"
             },
             "name": "s-1-VM"
           },
           {
             "device": {
               "label": "Network adapter 1",
               "macaddress": "02:00:22:40:00:02"
             },
             "name": "v-2-VM"
           },
           {
             "device": {
               "label": "Network adapter 2",
               "macaddress": "1e:00:a6:00:00:1a"
             },
             "name": "v-2-VM"
           },
           {
             "device": {
               "label": "Network adapter 2",
               "macaddress": "02:00:72:27:00:04"
             },
             "name": "r-4-VM"
           }
         ],
         "vlanid": "0"
       },
       {
         "cluster": "p1-c1",
         "host": "10.2.3.184",
         "portgroup": "cloud.public.7.0.1-vSwitch1",
         "switch": "vSwitch1",
         "virtualmachines": [
           {
             "device": {
               "label": "Network adapter 3",
               "macaddress": "1e:00:41:00:00:01"
             },
             "name": "s-1-VM"
           },
           {
             "device": {
               "label": "Network adapter 3",
               "macaddress": "1e:00:a6:00:00:02"
             },
             "name": "v-2-VM"
           },
           {
             "device": {
               "label": "Network adapter 4",
               "macaddress": "02:00:50:56:00:05"
             },
             "name": "r-4-VM"
           },
           {
             "device": {
               "label": "Network adapter 5",
               "macaddress": "02:00:20:3d:00:06"
             },
             "name": "r-4-VM"
           }
         ],
         "vlanid": "7"
       }
     ]
   }
   ```
   
   ## How Has This Been Tested?
   <!-- Please describe in detail how you tested your changes. -->
   <!-- Include details of your testing environment, and the tests you ran to 
-->
   <!-- see how your change affects other areas of the code, etc. -->
   
   - A VMware added to running CloudStack with multiple hosts.
   - A new vitrual machine deployed from VMware vCenter with multiple disks, 
networks in the cluster.
   - At this point CloudStack does not show or control newly deployed virtual 
machine.
   - `listUnmanagedInstances` API is executed for the cluster. It shows newly 
deployed VM (deployed from vCenter)
   - Import API, `importUnmanagedInstance`, is executed, with appropriate 
service offering, network- VM NIC details and custom disk offerings for this 
unmanaged VM
   - On successful completion of import API, UI is verified showing imported 
VM. `listVirtualMachines` API is called to verify showing new VM and `cloud` 
database is checked for containing new records in `vm_instance`, `volumes`, 
`nics` tables.
   - Lifecycle tasks were performed on the imported VM - stop, start, reboot, 
migrate, attach new disk.
   
   
   <!-- Please read the 
[CONTRIBUTING](https://github.com/apache/cloudstack/blob/master/CONTRIBUTING.md)
 document -->
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to