Skip to content

Commit 7dab9e2

Browse files
committed
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 - ipaddress(Only with VMware Tools installed on VM for VMware) 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 diskofferingid(UUID of disk offering for root disk) nicnetworklist(Map for NIC ID and corresponding Network UUID) nicipaddresslist(Map for NIC ID and corresponding IP address) 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 when offerings passed are incompatible with current host/pool) Response - Same response as that of deployVirtualMachine API A python 3 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 vSpehre 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 Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 666ec69 commit 7dab9e2

File tree

28 files changed

+3110
-283
lines changed

28 files changed

+3110
-283
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22+
import org.apache.cloudstack.acl.Role;
23+
import org.apache.cloudstack.acl.RolePermission;
24+
import org.apache.cloudstack.annotation.Annotation;
25+
import org.apache.cloudstack.config.Configuration;
26+
import org.apache.cloudstack.ha.HAConfig;
27+
import org.apache.cloudstack.usage.Usage;
28+
2229
import com.cloud.dc.DataCenter;
2330
import com.cloud.dc.Pod;
2431
import com.cloud.dc.StorageNetworkIpRange;
@@ -69,12 +76,6 @@
6976
import com.cloud.vm.Nic;
7077
import com.cloud.vm.NicSecondaryIp;
7178
import com.cloud.vm.VirtualMachine;
72-
import org.apache.cloudstack.acl.Role;
73-
import org.apache.cloudstack.acl.RolePermission;
74-
import org.apache.cloudstack.annotation.Annotation;
75-
import org.apache.cloudstack.config.Configuration;
76-
import org.apache.cloudstack.ha.HAConfig;
77-
import org.apache.cloudstack.usage.Usage;
7879

7980
public class EventTypes {
8081

@@ -96,6 +97,7 @@ public class EventTypes {
9697
public static final String EVENT_VM_MOVE = "VM.MOVE";
9798
public static final String EVENT_VM_RESTORE = "VM.RESTORE";
9899
public static final String EVENT_VM_EXPUNGE = "VM.EXPUNGE";
100+
public static final String EVENT_VM_IMPORT = "VM.IMPORT";
99101

100102
// Domain Router
101103
public static final String EVENT_ROUTER_CREATE = "ROUTER.CREATE";
@@ -594,6 +596,7 @@ public class EventTypes {
594596
entityEventDetails.put(EVENT_VM_MOVE, VirtualMachine.class);
595597
entityEventDetails.put(EVENT_VM_RESTORE, VirtualMachine.class);
596598
entityEventDetails.put(EVENT_VM_EXPUNGE, VirtualMachine.class);
599+
entityEventDetails.put(EVENT_VM_IMPORT, VirtualMachine.class);
597600

598601
entityEventDetails.put(EVENT_ROUTER_CREATE, VirtualRouter.class);
599602
entityEventDetails.put(EVENT_ROUTER_DESTROY, VirtualRouter.class);

api/src/main/java/com/cloud/vm/UserVmService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,8 @@ UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException
513513

514514
void collectVmNetworkStatistics (UserVm userVm);
515515

516+
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String instanceName, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
517+
final long accountId, final long userId, final ServiceOffering serviceOffering, final DiskOffering rootDiskOffering, final String sshPublicKey,
518+
final String hostName, final HypervisorType hypervisorType, final Map<String, String> customParameters, final VirtualMachine.PowerState powerState) throws InsufficientCapacityException;
519+
516520
}

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ public class ApiConstants {
4343
public static final String BYTES_WRITE_RATE_MAX = "byteswriteratemax";
4444
public static final String BYTES_WRITE_RATE_MAX_LENGTH = "byteswriteratemaxlength";
4545
public static final String BYPASS_VLAN_OVERLAP_CHECK = "bypassvlanoverlapcheck";
46+
public static final String CAPACITY = "capacity";
4647
public static final String CATEGORY = "category";
4748
public static final String CAN_REVERT = "canrevert";
4849
public static final String CA_CERTIFICATES = "cacertificates";
4950
public static final String CERTIFICATE = "certificate";
5051
public static final String CERTIFICATE_CHAIN = "certchain";
5152
public static final String CERTIFICATE_FINGERPRINT = "fingerprint";
5253
public static final String CERTIFICATE_ID = "certid";
54+
public static final String CONTROLLER = "controller";
55+
public static final String CONTROLLER_UNIT = "controllerunit";
5356
public static final String COPY_IMAGE_TAGS = "copyimagetags";
5457
public static final String CSR = "csr";
5558
public static final String PRIVATE_KEY = "privatekey";
@@ -69,6 +72,7 @@ public class ApiConstants {
6972
public static final String COMMAND = "command";
7073
public static final String CMD_EVENT_TYPE = "cmdeventtype";
7174
public static final String COMPONENT = "component";
75+
public static final String CPU_CORE_PER_SOCKET = "cpucorepersocket";
7276
public static final String CPU_NUMBER = "cpunumber";
7377
public static final String CPU_SPEED = "cpuspeed";
7478
public static final String CREATED = "created";
@@ -90,6 +94,7 @@ public class ApiConstants {
9094
public static final String DETAILS = "details";
9195
public static final String DEVICE_ID = "deviceid";
9296
public static final String DIRECT_DOWNLOAD = "directdownload";
97+
public static final String DISK = "disk";
9398
public static final String DISK_OFFERING_ID = "diskofferingid";
9499
public static final String NEW_DISK_OFFERING_ID = "newdiskofferingid";
95100
public static final String DISK_KBS_READ = "diskkbsread";
@@ -169,6 +174,7 @@ public class ApiConstants {
169174
public static final String PREVIOUS_ACL_RULE_ID = "previousaclruleid";
170175
public static final String NEXT_ACL_RULE_ID = "nextaclruleid";
171176
public static final String MOVE_ACL_CONSISTENCY_HASH = "aclconsistencyhash";
177+
public static final String IMAGE_PATH = "imagepath";
172178
public static final String INTERNAL_DNS1 = "internaldns1";
173179
public static final String INTERNAL_DNS2 = "internaldns2";
174180
public static final String INTERVAL_TYPE = "intervaltype";
@@ -222,6 +228,9 @@ public class ApiConstants {
222228
public static final String NETWORK_DOMAIN = "networkdomain";
223229
public static final String NETMASK = "netmask";
224230
public static final String NEW_NAME = "newname";
231+
public static final String NIC = "nic";
232+
public static final String NIC_NETWORK_LIST = "nicnetworklist";
233+
public static final String NIC_IP_ADDRESS_LIST = "nicipaddresslist";
225234
public static final String NUM_RETRIES = "numretries";
226235
public static final String OFFER_HA = "offerha";
227236
public static final String IS_SYSTEM_OFFERING = "issystem";
@@ -253,6 +262,7 @@ public class ApiConstants {
253262
public static final String PORTAL = "portal";
254263
public static final String PORTABLE_IP_ADDRESS = "portableipaddress";
255264
public static final String PORT_FORWARDING_SERVICE_ID = "portforwardingserviceid";
265+
public static final String POSITION = "position";
256266
public static final String POST_URL = "postURL";
257267
public static final String POWER_STATE = "powerstate";
258268
public static final String PRIVATE_INTERFACE = "privateinterface";
@@ -526,6 +536,7 @@ public class ApiConstants {
526536
public static final String CUSTOM_DISK_OFF_MAX_SIZE = "customdiskofferingmaxsize";
527537
public static final String DEFAULT_ZONE_ID = "defaultzoneid";
528538
public static final String LIVE_MIGRATE = "livemigrate";
539+
public static final String MIGRATE_ALLOWED = "migrateallowed";
529540
public static final String MIGRATE_TO = "migrateto";
530541
public static final String GUID = "guid";
531542
public static final String VSWITCH_TYPE_GUEST_TRAFFIC = "guestvswitchtype";

0 commit comments

Comments
 (0)