本文整理汇总了Python中marvin.lib.common.list_virtual_machines函数的典型用法代码示例。如果您正苦于以下问题:Python list_virtual_machines函数的具体用法?Python list_virtual_machines怎么用?Python list_virtual_machines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了list_virtual_machines函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_01_add_vm_to_subdomain
def test_01_add_vm_to_subdomain(self):
""" Test Sub domain allowed to launch VM when a Domain level zone is created"""
# Validate the following
# 1. Verify VM created by Account_1 is in Running state
# 2. Verify VM created by Account_2 is in Running state
vm_response = list_virtual_machines(
self.apiclient,
id=self.vm_1.id
)
self.assertEqual(
isinstance(vm_response, list),
True,
"Check List VM for a valid response"
)
self.assertNotEqual(
len(vm_response),
0,
"Check List Template response"
)
for vm in vm_response:
self.debug("VM ID: %s and state: %s" % (vm.id, vm.state))
self.assertEqual(
vm.state,
'Running',
"Check State of Virtual machine"
)
vm_response = list_virtual_machines(
self.apiclient,
id=self.vm_2.id
)
self.assertNotEqual(
len(vm_response),
0,
"Check List Template response"
)
for vm in vm_response:
self.debug("VM ID: %s and state: %s" % (vm.id, vm.state))
self.assertEqual(
vm.state,
'Running',
"Check State of Virtual machine"
)
return
示例2: create_vm_in_aff_grps
def create_vm_in_aff_grps(self, api_client=None, ag_list=[], projectid=None):
self.debug('Creating VM in AffinityGroups=%s' % ag_list)
if api_client is None:
api_client = self.api_client
if projectid is None:
projectid = self.project.id
vm = VirtualMachine.create(
api_client,
self.services["virtual_machine"],
projectid=projectid,
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
affinitygroupnames=ag_list
)
self.debug('Created VM=%s in Affinity Group=%s' % (vm.id, tuple(ag_list)))
list_vm = list_virtual_machines(self.api_client, id=vm.id, projectid=projectid)
self.assertEqual(isinstance(list_vm, list), True,"Check list response returns an invalid list %s" % list_vm)
self.assertNotEqual(len(list_vm),0, "Check VM available in TestDeployVMAffinityGroups")
self.assertEqual(list_vm[0].id, vm.id,"Listed vm does not have the same ids")
vm_response = list_vm[0]
self.assertEqual(vm.state, 'Running',msg="VM is not in Running state")
self.assertEqual(vm.projectid, projectid,msg="VM is not in project")
self.assertNotEqual(vm_response.hostid, None, "Host id was null for vm %s" % vm_response)
return vm, vm_response.hostid
示例3: check_vm_is_moved_in_account_domainid
def check_vm_is_moved_in_account_domainid(self, account):
list_vm_response = list_virtual_machines(self.api_client,
id=self.virtual_machine.id,
account=account.name,
domainid=account.domainid)
self.debug('VM=%s moved to account=%s and domainid=%s' % (list_vm_response, account.name, account.domainid))
self.assertNotEqual(len(list_vm_response), 0, 'Unable to move VM to account=%s domainid=%s' % (account.name, account.domainid))
示例4: test_08_removeNic_in_sharedNetwork_scope_all_as_domain_parentAdmin
def test_08_removeNic_in_sharedNetwork_scope_all_as_domain_parentAdmin(
self):
"""Validate that Parent domain admin is able to remove a NIC which is
added by child domain user
"""
self.api_client.connection.apiKey = self.user_d1_apikey
self.api_client.connection.securityKey = self.user_d1_secretkey
self.debug("Removing NIC od shared Network as user d1")
vm_list = list_virtual_machines(self.api_client, id=self.vmvpc1.id)
vm_list_validation_result = validateList(vm_list)
self.assertEqual(vm_list_validation_result[0], PASS,
"vm list validation failed due to %s" %
vm_list_validation_result[2])
self.debug("virtual machine nics: %s" % vm_list[0].nic)
for nic in vm_list[0].nic:
if nic.networkid == self.shared_network_all.id:
reqNic = nic
self.vmvpc1.remove_nic(self.api_client, reqNic.id)
if not self.verify_nic(self.shared_network_all, self.vmvpc1):
self.debug(
"virtual machine has mot NIC is SharedNetwork: %s" %
self.shared_network_all.name)
else:
self.fail("network %s NIC is present in the virtual Machine %s" %
(self.shared_network_all.name, self.vmvpc1.id))
示例5: 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
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,
)
self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id, self.account.name))
# Checking if VM is running or not, in case it is deployed in error state, test case fails
self.vm_list = list_virtual_machines(self.apiclient, id=self.virtual_machine.id)
self.assertEqual(validateList(self.vm_list)[0], PASS, "vm list validation failed, vm list is %s" % self.vm_list)
self.assertEqual(
str(self.vm_list[0].state).lower(),
"running",
"VM state should be running, it is %s" % self.vm_list[0].state,
)
self.public_ip = PublicIPAddress.create(
self.apiclient,
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
networkid=self.network.id,
)
# Open up firewall port for SSH
FireWallRule.create(
self.apiclient,
ipaddressid=self.public_ip.ipaddress.id,
protocol=self.services["natrule"]["protocol"],
cidrlist=["0.0.0.0/0"],
startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"],
)
self.debug("Creating NAT rule for VM ID: %s" % self.virtual_machine.id)
# Create NAT rule
NATRule.create(self.apiclient, self.virtual_machine, self.services["natrule"], self.public_ip.ipaddress.id)
return
示例6: test_01_native_to_native_network_migration
def test_01_native_to_native_network_migration(self):
"""
Verify Migration for an isolated network nativeOnly
1. create native non-persistent isolated network
2. migrate to other non-persistent isolated network
3. migrate back to first native non-persistent network
4. deploy VM in non-persistent isolated network
5. migrate to native persistent isolated network
6. migrate back to native non-persistent network
"""
isolated_network = Network.create(
self.apiclient,
self.test_data["isolated_network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering_all.id,
zoneid=self.zone.id
)
self.migrate_network(
self.network_offering_nouserdata,
isolated_network, resume=False)
self.migrate_network(
self.network_offering_all,
isolated_network, resume=False)
deployVmResponse = VirtualMachine.create(
self.apiclient,
services=self.test_data["virtual_machine_userdata"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[str(isolated_network.id)],
templateid=self.template.id,
zoneid=self.zone.id
)
vms = list_virtual_machines(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
id=deployVmResponse.id
)
self.assert_(len(vms) > 0, "There are no Vms deployed in the account"
" %s" % self.account.name)
vm = vms[0]
self.assert_(vm.id == str(deployVmResponse.id),
"Vm deployed is different from the test")
self.assert_(vm.state == "Running", "VM is not in Running state")
self.migrate_network(
self.network_offering_nouserdata,
isolated_network, resume=False)
self.migrate_network(
self.network_offering_all,
isolated_network, resume=False)
示例7: MigrateRootVolume
def MigrateRootVolume(self,
vm,
destinationHost,
expectexception=False):
""" Migrate given volume to type of storage pool mentioned in migrateto:
Inputs:
1. vm: VM to be migrated
is to be migrated
2. expectexception: If exception is expected while migration
3. destinationHost: Destination host where the VM\
should get migrated
"""
if expectexception:
with self.assertRaises(Exception):
VirtualMachine.migrate(
vm,
self.apiclient,
hostid=destinationHost.id,
)
else:
VirtualMachine.migrate(
vm,
self.apiclient,
hostid=destinationHost.id,
)
migrated_vm_response = list_virtual_machines(
self.apiclient,
id=vm.id
)
self.assertEqual(
isinstance(migrated_vm_response, list),
True,
"Check list virtual machines response for valid list"
)
self.assertNotEqual(
migrated_vm_response,
None,
"Check if virtual machine exists in ListVirtualMachines"
)
migrated_vm = migrated_vm_response[0]
vm_list = VirtualMachine.list(
self.apiclient,
id=migrated_vm.id
)
self.assertEqual(
vm_list[0].hostid,
destinationHost.id,
"Check volume is on migrated pool"
)
return
示例8: verify_vm
def verify_vm(self, vmid):
list_vm = list_virtual_machines(self.userapiclient,
account=self.account.name,
domainid=self.account.domainid,
id=vmid
)
self.assertEqual(validateList(list_vm)[0], PASS, "Check List vm response for vmid: %s" % vmid)
self.assertGreater(len(list_vm), 0, "Check the list vm response for vm id: %s" % vmid)
vm = list_vm[0]
self.assertEqual(vm.id, str(vmid), "Vm deployed is different from the test")
self.assertEqual(vm.state, "Running", "VM is not in Running state")
self.debug("VM got created successfully %s" % vmid)
示例9: test_deployvm_multinic
def test_deployvm_multinic(self):
"""Test userdata update when non default nic is without userdata for deploy and update
"""
self.userdata = base64.b64encode(self.userdata)
network1 = Network.create(
self.apiclient,
self.test_data["isolated_network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering_all.id,
zoneid=self.zone.id,
)
self.test_data["network_without_acl"]["netmask"] = "255.255.255.128"
network2 = Network.create(
self.apiclient,
self.test_data["network_without_acl"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering_nouserdata.id,
gateway="10.2.1.1",
zoneid=self.zone.id,
)
deployVmResponse = VirtualMachine.create(
self.apiclient,
services=self.test_data["virtual_machine_userdata"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[str(network1.id), str(network2.id)],
templateid=self.template.id,
zoneid=self.zone.id,
)
vms = list_virtual_machines(
self.apiclient, account=self.account.name, domainid=self.account.domainid, id=deployVmResponse.id
)
self.assert_(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
vm = vms[0]
self.assert_(vm.id == str(deployVmResponse.id), "Vm deployed is different from the test")
self.assert_(vm.state == "Running", "VM is not in Running state")
try:
updateresponse = deployVmResponse.update(self.apiclient, userdata=self.userdata)
except Exception as e:
self.fail("Failed to update userdata: %s" % e)
self.debug("virtual machine update response is: %s" % updateresponse)
示例10: create_vm
def create_vm(self,
account,
domain,
isRunning=False,
project =None,
limit =None,
pfrule =False,
lbrule =None,
natrule =None,
volume =None,
snapshot =False):
#TODO: Implemnt pfrule/lbrule/natrule
self.debug("Deploying instance in the account: %s" % account.name)
self.virtual_machine = VirtualMachine.create(self.apiclient,
self.services["virtual_machine"],
accountid=account.name,
domainid=domain.id,
serviceofferingid=self.service_offering.id,
mode=self.zone.networktype if pfrule else 'basic',
projectid=project.id if project else None)
self.debug("Deployed instance in account: %s" % account.name)
list_virtual_machines(self.apiclient,
id=self.virtual_machine.id)
if snapshot:
volumes = list_volumes(self.apiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True)
self.snapshot = Snapshot.create(self.apiclient,
volumes[0].id,
account=account.name,
domainid=account.domainid)
if volume:
self.virtual_machine.attach_volume(self.apiclient,
volume)
if not isRunning:
self.virtual_machine.stop(self.apiclient)
self.cleanup.append(self.virtual_machine)
示例11: verify_nic
def verify_nic(self, network, vm):
"""verify required nic is present in the VM"""
self.debug(
"Going to verify if %s Network nic is present in virtual machine "
"%s" % (network.name, vm.id))
vm_list = list_virtual_machines(self.api_client, id=vm.id)
vm_list_validation_result = validateList(vm_list)
self.assertEqual(vm_list_validation_result[0], PASS,
"vm list validation failed due to %s" %
vm_list_validation_result[2])
self.debug("virtual machine nics: %s" % vm_list[0].nic)
# filter nic of virtual machine based on Network
nics = [x for x in vm_list[0].nic if x.networkid == network.id]
self.debug("Filtered nics list: %s:" % nics)
if len(nics) == 1:
return True
else:
return False
示例12: tearDown
def tearDown(self):
try:
if self.egressruleid:
self.debug('remove egress rule id=%s' % self.egressruleid)
self.deleteEgressRule()
self.debug("Cleaning up the resources")
#below components is not a part of cleanup because to mandate the order and to cleanup network
try:
for vm in self.cleanup_vms:
if str(vm.state).lower() != "error":
vm.delete(self.api_client)
except Exception as e:
self.fail("Warning: Exception during virtual machines cleanup : %s" % e)
# Wait for VMs to expunge
wait_for_cleanup(self.api_client, ["expunge.delay", "expunge.interval"])
if len(self.cleanup_vms) > 0:
retriesCount = 10
while True:
vms = list_virtual_machines(self.api_client, id=self.virtual_machine.id)
if vms is None:
break
elif retriesCount == 0:
self.fail("Failed to expunge vm even after 10 minutes")
time.sleep(60)
retriesCount -= 1
try:
for network in self.cleanup_networks:
network.delete(self.api_client)
except Exception as e:
self.fail("Warning: Exception during networks cleanup : %s" % e)
self.debug("Sleep for Network cleanup to complete.")
wait_for_cleanup(self.apiclient, ["network.gc.wait", "network.gc.interval"])
cleanup_resources(self.apiclient, reversed(self.cleanup))
self.debug("Cleanup complete!")
except Exception as e:
self.fail("Warning! Cleanup failed: %s" % e)
示例13: create_another_vm
def create_another_vm(self):
self.debug("Deploying instance in the account: %s and network: %s" % (self.account.name, self.network.id))
project = None
self.virtual_machine1 = 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,
networkids=[str(self.network.id)],
projectid=project.id if project else None)
self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id,self.account.name))
# Checking if VM is running or not, in case it is deployed in error state, test case fails
self.vm_list = list_virtual_machines(self.apiclient, id=self.virtual_machine.id)
self.assertEqual(validateList(self.vm_list)[0], PASS, "vm list validation failed, vm list is %s" % self.vm_list)
self.assertEqual(str(self.vm_list[0].state).lower(),'running',"VM state should be running, it is %s" % self.vm_list[0].state)
示例14: test_deploy_vm_l2network
def test_deploy_vm_l2network(self):
"""Creates an l2 network and verifies user is able to deploy a VM in it"""
# Validate the following:
# 1. Deploys a VM
# 2. There are no network services available since this is L2 Network
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
templateid=self.template.id,
serviceofferingid=self.service_offering.id,
networkids=self.l2_network.id,
zoneid=self.zone.id
)
self.cleanup.insert(0, self.virtual_machine)
list_vm = list_virtual_machines(
self.apiclient,
id = self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vm, list),
True,
"Check if virtual machine is present"
)
self.assertEqual(
list_vm[0].nic[0].type,
'L2',
"Check Correct Network type is available"
)
self.assertFalse(
'gateway' in str(list_vm[0].nic[0])
)
self.assertFalse(
'ipaddress' in str(list_vm[0].nic[0])
)
return
示例15: test_deployvm_userdata
def test_deployvm_userdata(self):
"""Test userdata as GET, size > 2k
"""
deployVmResponse = VirtualMachine.create(
self.apiClient,
services=self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id,
zoneid=self.zone.id
)
vms = list_virtual_machines(
self.apiClient,
account=self.account.name,
domainid=self.account.domainid,
id=deployVmResponse.id
)
self.assert_(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
vm = vms[0]
self.assert_(vm.id == str(deployVmResponse.id), "Vm deployed is different from the test")
self.assert_(vm.state == "Running", "VM is not in Running state")