def test_05_deploy_vm_on_cluster_override_pod(self): # Optional parameters pod, cluster and host pod = Pod.list(self.apiclient, zoneid=self.zone.id)[0] clusters = Cluster.list(self.apiclient, zoneid=self.zone.id, podid=pod.id) self.assertEqual(isinstance(clusters, list), True, "Check list response returns a valid list") cmd = deployVirtualMachine.deployVirtualMachineCmd() # Required parameters cmd.zoneid = self.zone.id cmd.serviceofferingid = self.service_offering.id template = get_template(self.apiclient, zone_id=self.zone.id, hypervisor=clusters[0].hypervisortype) cmd.templateid = template.id # Add optional deployment params cmd.podid = pod.id cmd.clusterid = clusters[0].id vm = self.apiclient.deployVirtualMachine(cmd) vm_host = Host.list(self.apiclient, id=vm.hostid) self.assertEqual(vm_host[0].clusterid, clusters[0].id, "VM was not deployed on the target cluster") self.destroy_vm(vm.id)
def deploy_vm(self, destination_id): cmd = deployVirtualMachine.deployVirtualMachineCmd() template = get_template(self.apiclient, self.zone.id, hypervisor=self.hypervisor) cmd.zoneid = self.zone.id cmd.templateid = template.id cmd.serviceofferingid = self.service_offering.id cmd.hostid = destination_id return self.apiclient.deployVirtualMachine(cmd)
def deploy_vm(self, hypervisor, extra_config=None): cmd = deployVirtualMachine.deployVirtualMachineCmd() if extra_config is not None: cmd.extraconfig = extra_config template = get_template(self.apiclient, self.zone.id, hypervisor=hypervisor) cmd.zoneid = self.zone.id cmd.templateid = template.id cmd.serviceofferingid = self.service_offering.id return self.apiclient.deployVirtualMachine(cmd)
def test_02_deploy_vm_on_specific_cluster(self): # Select deployment cluster clusters = Cluster.list(self.apiclient, ) target_cluster = clusters[0] target_id = target_cluster.id cluster_hypervisor = target_cluster.hypervisortype template = get_template(self.apiclient, hypervisor=cluster_hypervisor) # deploy vm on cluster cmd = deployVirtualMachine.deployVirtualMachineCmd() cmd.zoneid = target_cluster.zoneid cmd.serviceofferingid = self.service_offering.id cmd.templateid = template.id cmd.clusterid = target_id vm = self.apiclient.deployVirtualMachine(cmd) vm_host = Host.list(self.apiclient, id=vm.hostid) self.assertEqual(target_id, vm_host[0].clusterid, "VM was not deployed on the provided cluster") self.destroy_vm(vm.id)
def test_03_deploy_vm_on_specific_pod(self): pods = Pod.list(self.apiclient, ) target_pod = pods[0] # Get host by Pod ID host = Host.list(self.apiclient, podid=target_pod.id) # deploy vm on pod cmd = deployVirtualMachine.deployVirtualMachineCmd() cmd.zoneid = target_pod.zoneid cmd.serviceofferingid = self.service_offering.id template = get_template(self.apiclient, hypervisor=host[0].hypervisortype) cmd.templateid = template.id cmd.podid = target_pod.id vm = self.apiclient.deployVirtualMachine(cmd) vm_host = Host.list(self.apiclient, id=vm.hostid) self.assertEqual(target_pod.id, vm_host[0].podid, "VM was not deployed on the target pod") self.destroy_vm(vm.id)
def create_vm_custom(cls, apiclient, services, templateid=None, zoneid=None, serviceofferingid=None, method='GET', hypervisor=None, cpuNumber=None, cpuSpeed=None, memory=None, minIops=None, maxIops=None, hostid=None, rootdisksize=None, account=None, domainid=None): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() if serviceofferingid: cmd.serviceofferingid = serviceofferingid elif "serviceoffering" in services: cmd.serviceofferingid = services["serviceoffering"] if zoneid: cmd.zoneid = zoneid elif "zoneid" in services: cmd.zoneid = services["zoneid"] if hypervisor: cmd.hypervisor = hypervisor if hostid: cmd.hostid = hostid if "displayname" in services: cmd.displayname = services["displayname"] if "name" in services: cmd.name = services["name"] if templateid: cmd.templateid = templateid elif "template" in services: cmd.templateid = services["template"] cmd.details = [{}] if cpuNumber: cmd.details[0]["cpuNumber"] = cpuNumber if cpuSpeed: cmd.details[0]["cpuSpeed"] = cpuSpeed if memory: cmd.details[0]["memory"] = memory if minIops: cmd.details[0]["minIops"] = minIops if maxIops: cmd.details[0]["maxIops"] = maxIops if rootdisksize >= 0: cmd.details[0]["rootdisksize"] = rootdisksize if account: cmd.account = account if domainid: cmd.domainid = domainid virtual_machine = apiclient.deployVirtualMachine(cmd, method=method) return VirtualMachine(virtual_machine.__dict__, services)