当前位置: 首页>>代码示例>>Python>>正文


Python VirtualMachine.create方法代码示例

本文整理汇总了Python中marvin.integration.lib.base.VirtualMachine.create方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualMachine.create方法的具体用法?Python VirtualMachine.create怎么用?Python VirtualMachine.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marvin.integration.lib.base.VirtualMachine的用法示例。


在下文中一共展示了VirtualMachine.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createInstance

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    def createInstance(self, service_off, account=None,
                        project=None, networks=None, api_client=None):
        """Creates an instance in account"""

        if api_client is None:
            api_client = self.apiclient

        self.debug("Deploying instance")
        try:
            if account:
                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)
            elif project:
                vm = VirtualMachine.create(
                     api_client,
                     self.services["virtual_machine"],
                     templateid=self.template.id,
                     projectid=project.id,
                     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)
开发者ID:Bhathiya90,项目名称:cloudstack,代码行数:37,代码来源:test_cpu_max_limits.py

示例2: test_deployvm_userdispersing

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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))
开发者ID:baishuo,项目名称:cloudstack,代码行数:59,代码来源:test_deploy_vms_with_varied_deploymentplanners.py

示例3: test_deployvm_userconcentrated

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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"
        )
开发者ID:andrew2king,项目名称:cloudstack,代码行数:59,代码来源:test_deploy_vms_with_varied_deploymentplanners.py

示例4: test_deploy_virtual_machines_static_offering

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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
开发者ID:dbac,项目名称:cloudstack,代码行数:57,代码来源:test_dynamic_compute_offering.py

示例5: create_vm

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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)
开发者ID:ebrahimsami01,项目名称:cloudstack,代码行数:29,代码来源:test_egress_fw_rules.py

示例6: test_01_deploy_vm_root_resize

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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);
开发者ID:baishuo,项目名称:cloudstack,代码行数:28,代码来源:test_deploy_vm_root_resize.py

示例7: test_02_deploy_vm_root_resize

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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);
开发者ID:baishuo,项目名称:cloudstack,代码行数:31,代码来源:test_deploy_vm_root_resize.py

示例8: test_deployvm_firstfit

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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")
开发者ID:jtperry,项目名称:cloudstack,代码行数:27,代码来源:test_deploy_vms_with_varied_deploymentplanners.py

示例9: test_05_remove_used_range

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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
开发者ID:Bhathiya90,项目名称:cloudstack,代码行数:35,代码来源:test_non_contiguous_vlan.py

示例10: setUp

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
 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
开发者ID:Aparna31,项目名称:cloudstack,代码行数:33,代码来源:test_vpn_users.py

示例11: setUp

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
 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
开发者ID:andrew2king,项目名称:cloudstack,代码行数:29,代码来源:test_vpn_users.py

示例12: test_add_static_nat_rule

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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
开发者ID:Blufe,项目名称:cloudstack,代码行数:60,代码来源:test_multiple_ips_per_nic.py

示例13: test_operations_non_root_admin_api_client

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    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
开发者ID:Blufe,项目名称:cloudstack,代码行数:60,代码来源:test_multiple_ips_per_nic.py

示例14: setUpClass

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    def setUpClass(cls):
        cls.api_client = super(TestServiceOfferings, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.services['mode'] = cls.zone.networktype

        cls.service_offering_1 = ServiceOffering.create(
            cls.api_client,
            cls.services["off"]
        )
        cls.service_offering_2 = ServiceOffering.create(
            cls.api_client,
            cls.services["off"]
        )
        template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["medium"]["zoneid"] = cls.zone.id
        cls.services["medium"]["template"] = template.id

        # Create VMs, NAT Rules etc
        cls.account = Account.create(
                            cls.api_client,
                            cls.services["account"],
                            domainid=domain.id
                            )

        cls.small_offering = ServiceOffering.create(
                                    cls.api_client,
                                    cls.services["service_offerings"]["small"]
                                    )

        cls.medium_offering = ServiceOffering.create(
                                    cls.api_client,
                                    cls.services["service_offerings"]["medium"]
                                    )
        cls.medium_virtual_machine = VirtualMachine.create(
                                       cls.api_client,
                                       cls.services["medium"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       serviceofferingid=cls.medium_offering.id,
                                       mode=cls.services["mode"]
                                    )
        cls._cleanup = [
                        cls.small_offering,
                        cls.medium_offering,
                        cls.account
                        ]
        return
开发者ID:Bhathiya90,项目名称:cloudstack,代码行数:59,代码来源:test_service_offerings.py

示例15: test_disable_static_nat

# 需要导入模块: from marvin.integration.lib.base import VirtualMachine [as 别名]
# 或者: from marvin.integration.lib.base.VirtualMachine import create [as 别名]
    def test_disable_static_nat(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
        #    enable static NAT rule for this public IP to the 1st secondary IP
        # 5. Disable the static nat rule and enable it again

        # Validations:
        # 1. Verify step 5 by listing seconday IP and checking the appropriate flag

        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)

        public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name,
                                           zoneid=self.zone.id,domainid=self.account.domainid,
                                           networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None)

        if value != VPC_NETWORK:
            FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id,
                                      protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
                                      startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])

        StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id,
                    network.id, vmguestip=ipaddress_1.ipaddress)

        self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, True)

        # Disabling static NAT
        StaticNATRule.disable(self.apiclient, public_ip.ipaddress.id)

        self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, False)

        StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id,
                    network.id, vmguestip=ipaddress_1.ipaddress)

        self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, True)

        public_ip.delete(self.apiclient)
        return
开发者ID:Blufe,项目名称:cloudstack,代码行数:59,代码来源:test_multiple_ips_per_nic.py


注:本文中的marvin.integration.lib.base.VirtualMachine.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。