本文整理汇总了Python中marvin.integration.lib.base.VirtualMachine类的典型用法代码示例。如果您正苦于以下问题:Python VirtualMachine类的具体用法?Python VirtualMachine怎么用?Python VirtualMachine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualMachine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deployvm_firstfit
def test_deployvm_firstfit(self):
"""Test to deploy vm with a first fit offering
"""
# FIXME: How do we know that first fit actually happened?
self.service_offering_firstfit = ServiceOffering.create(
self.apiclient, self.services["service_offering"], deploymentplanner="FirstFitPlanner"
)
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_firstfit.id,
templateid=self.template.id,
)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.debug("Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id)
self.assertEqual(isinstance(list_vms, list), True, "List VM response was not a valid list")
self.assertNotEqual(len(list_vms), 0, "List VM response was empty")
vm = list_vms[0]
self.assertEqual(vm.state, "Running", msg="VM is not in Running state")
示例2: DestroyVM
def DestroyVM(self, id):
mocnictouse = mocnic("127.0.0.1")
vm = VirtualMachine({"id": id, "nic": [mocnictouse]}, self.services)
vm.delete(self.apiclient)
list_vm_response = VirtualMachine.list(
self.apiclient,
id=id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_vm_response),
0,
"Check VM avaliable in List Virtual Machines"
)
self.assertEqual(
list_vm_response[0].state,
"Destroyed",
"Check virtual machine is in destroyed state"
)
return
示例3: createInstance
def createInstance(self, account, service_off, networks=None, api_client=None):
"""Creates an instance in account"""
if api_client is None:
api_client = self.apiclient
self.debug("Deploying an instance in account: %s" %
account.name)
try:
vm = VirtualMachine.create(
api_client,
self.services["virtual_machine"],
templateid=self.template.id,
accountid=account.name,
domainid=account.domainid,
networkids=networks,
serviceofferingid=service_off.id)
vms = VirtualMachine.list(api_client, id=vm.id, listall=True)
self.assertIsInstance(vms,
list,
"List VMs should return a valid response")
self.assertEqual(vms[0].state, "Running",
"Vm state should be running after deployment")
return vm
except Exception as e:
self.fail("Failed to deploy an instance: %s" % e)
示例4: test_deployvm_userconcentrated
def test_deployvm_userconcentrated(self):
"""Test deploy VMs using user concentrated planner
"""
self.service_offering_userconcentrated = ServiceOffering.create(
self.apiclient,
self.services["service_offering"],
deploymentplanner='UserConcentratedPodPlanner'
)
self.virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_userconcentrated.id,
templateid=self.template.id
)
self.virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_userconcentrated.id,
templateid=self.template.id
)
list_vm_1 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_1.id)
list_vm_2 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_2.id)
self.assertEqual(
isinstance(list_vm_1, list),
True,
"List VM response was not a valid list"
)
self.assertEqual(
isinstance(list_vm_2, list),
True,
"List VM response was not a valid list"
)
vm1 = list_vm_1[0]
vm2 = list_vm_2[0]
self.assertEqual(
vm1.state,
"Running",
msg="VM is not in Running state"
)
self.assertEqual(
vm2.state,
"Running",
msg="VM is not in Running state"
)
self.assertNotEqual(
vm1.hostid,
vm2.hostid,
msg="VMs meant to be concentrated are deployed on the different hosts"
)
示例5: test_deployvm_userdispersing
def test_deployvm_userdispersing(self):
"""Test deploy VMs using user dispersion planner
"""
self.service_offering_userdispersing = ServiceOffering.create(
self.apiclient,
self.services["service_offering"],
deploymentplanner='UserDispersingPlanner'
)
self.virtual_machine_1 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_userdispersing.id,
templateid=self.template.id
)
self.virtual_machine_2 = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering_userdispersing.id,
templateid=self.template.id
)
list_vm_1 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_1.id)
list_vm_2 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_2.id)
self.assertEqual(
isinstance(list_vm_1, list),
True,
"List VM response was not a valid list"
)
self.assertEqual(
isinstance(list_vm_2, list),
True,
"List VM response was not a valid list"
)
vm1 = list_vm_1[0]
vm2 = list_vm_2[0]
self.assertEqual(
vm1.state,
"Running",
msg="VM is not in Running state"
)
self.assertEqual(
vm2.state,
"Running",
msg="VM is not in Running state"
)
vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid
vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid
if vm1clusterid == vm2clusterid:
self.debug("VMs (%s, %s) meant to be dispersed are deployed in the same cluster %s" % (
vm1.id, vm2.id, vm1clusterid))
示例6: test_deploy_virtual_machines_static_offering
def test_deploy_virtual_machines_static_offering(self, value):
"""Test deploy VM with static offering"""
# Steps:
# 1. Create admin/user account and create its user api client
# 2. Create a static compute offering
# 3. Deploy a VM with account api client and static service offering
# 4. Repeat step 3 but also pass custom values for cpu number, cpu speed and memory
# while deploying VM
# Validations:
# 1. Step 3 should succeed
# 2. Step 4 should fail
isadmin=True
if value == USER_ACCOUNT:
isadmin=False
# Create Account
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
apiclient = self.testClient.createUserApiClient(
UserName=self.account.name,
DomainName=self.account.domain)
self.cleanup.append(self.account)
# Create service offering
self.services["service_offering"]["cpunumber"] = 2
self.services["service_offering"]["cpuspeed"] = 256
self.services["service_offering"]["memory"] = 128
serviceOffering = ServiceOffering.create(self.apiclient,
self.services["service_offering"])
self.cleanup_co.append(serviceOffering)
# Deploy VM with static service offering
try:
VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering.id,
accountid=self.account.name,domainid=self.account.domainid)
except Exception as e:
self.fail("vm creation failed: %s" % e)
# Deploy VM with static service offering, also with custom values
try:
VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering.id,
customcpunumber=4,
customcpuspeed=512,
custommemory=256,
accountid=self.account.name,domainid=self.account.domainid)
self.fail("VM creation should have failed, it succeeded")
except Exception as e:
self.debug("vm creation failed as expected: %s" % e)
return
示例7: test_deploy_vm
def test_deploy_vm(self):
"""Test Deploy Virtual Machine
# Validate the following:
# 1. Virtual Machine is accessible via SSH
# 2. listVirtualMachines returns accurate information
"""
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id
)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s"\
% self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vms, list),
True,
"List VM response was not a valid list"
)
self.assertNotEqual(
len(list_vms),
0,
"List VM response was empty"
)
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"Virtual Machine ids do not match"
)
self.assertEqual(
vm.name,
self.virtual_machine.name,
"Virtual Machine names do not match"
)
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state"
)
示例8: test_05_remove_used_range
def test_05_remove_used_range(self):
"""
Test removing used vlan range
"""
# 1. Use a vlan id from existing range by deploying an instance which
# will create a network with vlan id from this range
# 4. Now try to remove this vlan range
# 5. Vlan range should not get removed, should throw error
account = Account.create(self.apiclient,self.services["account"],
domainid=self.domain.id)
self.debug("Deploying instance in the account: %s" % account.name)
try:
self.virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
accountid=account.name,domainid=account.domainid,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype)
self.debug("Deployed instance in account: %s" % account.name)
self.debug("Trying to remove vlan range : %s , This should fail" % self.vlan["partial_range"][0])
with self.assertRaises(Exception) as e:
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0])
self.debug("operation failed with exception: %s" % e.exception)
account.delete(self.apiclient)
except Exception as e:
self.fail("Exception in test case: %s" % e)
return
示例9: setUp
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.account = Account.create(
self.apiclient,
self.services["account"],
domainid=self.domain.id
)
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id
)
self.public_ip = PublicIPAddress.create(
self.apiclient,
self.virtual_machine.account,
self.virtual_machine.zoneid,
self.virtual_machine.domainid,
self.services["virtual_machine"]
)
self.cleanup = [
self.account,
]
return
示例10: setUp
def setUp(self):
try:
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.account = Account.create(
self.apiclient,
self.services["account"],
domainid=self.domain.id
)
self.cleanup = [
self.account,
]
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
templateid=self.template.id,
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id
)
self.public_ip = PublicIPAddress.create(
self.apiclient,
accountid=self.virtual_machine.account,
zoneid=self.virtual_machine.zoneid,
domainid=self.virtual_machine.domainid,
services=self.services["virtual_machine"]
)
return
except cloudstackAPIException as e:
self.tearDown()
raise e
示例11: test_01_deploy_vm_root_resize
def test_01_deploy_vm_root_resize(self):
"""Test proper failure to deploy virtual machine with rootdisksize of 0
"""
if (self.apiclient.hypervisor == 'kvm'):
newrootsize = 0
success = False
try:
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
)
except Exception as ex:
if "rootdisk size should be a non zero number" in str(ex):
success = True
else:
self.debug("virtual machine create did not fail appropriately. Error was actually : " + str(ex));
self.assertEqual(success, True, "Check if passing 0 as rootdisksize fails appropriately")
else:
self.debug("test 01 does not support hypervisor type " + self.apiclient.hypervisor);
示例12: test_02_deploy_vm_root_resize
def test_02_deploy_vm_root_resize(self):
"""Test proper failure to deploy virtual machine with rootdisksize less than template size
"""
if (self.apiclient.hypervisor == 'kvm'):
newrootsize = (self.template.size >> 30) - 1
self.assertEqual(newrootsize > 0, True, "Provided template is less than 1G in size, cannot run test")
success = False
try:
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
rootdisksize=newrootsize
)
except Exception as ex:
if "rootdisksize override is smaller than template size" in str(ex):
success = True
else:
self.debug("virtual machine create did not fail appropriately. Error was actually : " + str(ex));
self.assertEqual(success, True, "Check if passing rootdisksize < templatesize fails appropriately")
else:
self.debug("test 01 does not support hypervisor type " + self.apiclient.hypervisor);
示例13: create_vm
def create_vm(self, pfrule=False, egress_policy=True, RR=False):
self.create_network_offering(egress_policy, RR)
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
self.network = Network.create(self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id)
self.debug("Created network with ID: %s" % self.network.id)
self.debug("Deploying instance in the account: %s" % self.account.name)
project = None
try:
self.virtual_machine = VirtualMachine.create(self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype if pfrule else 'basic',
networkids=[str(self.network.id)],
projectid=project.id if project else None)
except Exception as e:
self.fail("Virtual machine deployment failed with exception: %s" % e)
self.debug("Deployed instance in account: %s" % self.account.name)
示例14: test_add_static_nat_rule
def test_add_static_nat_rule(self, value):
""" Add secondary IP to NIC of a VM"""
# Steps:
# 1. Create Account and create network in it (isoalted/ shared/ vpc)
# 2. Deploy a VM in this network and account
# 3. Add 2 secondary IPs to the default nic of VM
# 4. Acquire public IP, open firewall for it, and
# create static NAT rule for this public IP to the 1st secondary IP
# 5. Repeat step 4 for another public IP
# 6. Repeat step 4 for 2nd secondary IP
# 7. Repeat step 4 for invalid secondary IP
# 8. Try to remove 1st secondary IP (with active static nat rule)
# Validations:
# 1. Step 4 should succeed
# 2. Step 5 should succeed
# 3. Step 6 should succeed
# 4. Step 7 should fail
# 5. Step 8 should succeed
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id)
self.cleanup.append(self.account)
network = createNetwork(self, value)
try:
virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
networkids=[network.id],serviceofferingid=self.service_offering.id,
accountid=self.account.name,domainid=self.account.domainid)
except Exception as e:
self.fail("vm creation failed: %s" % e)
try:
ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
except Exception as e:
self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)
try:
ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
except Exception as e:
self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)
self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="staticnat"),
PASS, "Failure in creating NAT rule")
self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="staticnat"),
FAIL, "Failure in creating NAT rule")
self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_2.ipaddress, value, ruletype="staticnat"),
PASS, "Failure in creating NAT rule")
self.assertEqual(createNetworkRules(self, virtual_machine, network, "255.255.255.300", value, ruletype="staticnat"),
FAIL, "Failure in NAT rule creation")
try:
NIC.removeIp(self.apiclient, ipaddress_1.id)
self.fail("Ip address should not get removed when active static NAT rule is defined for it")
except Exception as e:
self.debug("Exception while removing secondary ip address as expected because static nat rule is present for it")
return
示例15: test_operations_non_root_admin_api_client
def test_operations_non_root_admin_api_client(self, value):
"""Test basic operations using non root admin apii client"""
# Steps:
# 1. Create Domain and Account in it
# 2. Create network in it (isoalted/ shared/ vpc)
# 3. Create User API client of this account
# 4. Deploy a VM in this network and account
# 5. Add secondary IP to the default nic of VM using non root admin api client
# 6. List secondary IPs using non root admin api client
# 7. Remove secondary IP using non root admin api client
# Validations:
# 1. All the operations should be successful
child_domain = Domain.create(self.apiclient,services=self.services["domain"],
parentdomainid=self.domain.id)
self.account = Account.create(self.apiclient,self.services["account"],domainid=child_domain.id)
self.cleanup.append(self.account)
self.cleanup.append(child_domain)
apiclient = self.testClient.createUserApiClient(UserName=self.account.name, DomainName=self.account.domain)
if(shouldTestBeSkipped(networkType=value, zoneType=self.mode)):
self.skipTest("Skipping test as %s network is not supported in basic zone" % value)
network = createNetwork(self, value)
try:
virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
networkids=[network.id],serviceofferingid=self.service_offering.id,
accountid=self.account.name,domainid=self.account.domainid)
except Exception as e:
self.fail("vm creation failed: %s" % e)
try:
ipaddress_1 = NIC.addIp(apiclient, id=virtual_machine.nic[0].id)
except Exception as e:
self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)
try:
NIC.list(apiclient, virtualmachineid=virtual_machine.id)
except Exception as e:
self.fail("Listing NICs for virtual machine %s failed with Exception %s" % (virtual_machine.id, e))
try:
NIC.list(apiclient, virtualmachineid=virtual_machine.id, nicid=virtual_machine.nic[0].id)
except Exception as e:
self.fail("Listing NICs for virtual machine %s and nic id %s failed with Exception %s" %
(virtual_machine.id, virtual_machine.nic[0].id, e))
try:
NIC.removeIp(apiclient, ipaddressid=ipaddress_1.id)
except Exception as e:
self.fail("Removing seondary IP %s from NIC failed as expected with Exception %s" % (ipaddress_1.id,e))
return