• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python base.VirtualMachine类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createInstance

    def createInstance(self, service_off, networks=None, api_client=None):
        """Creates an instance in account"""
        self.debug("Deploying an instance in account: %s" %
                                                self.account.name)

        if api_client is None:
	        api_client = self.apiclient

        try:
            vm = VirtualMachine.create(
                                api_client,
                                self.services["virtual_machine"],
                                templateid=self.template.id,
                                accountid=self.account.name,
                                domainid=self.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)
开发者ID:MANIKANDANVEN,项目名称:cloudstack,代码行数:26,代码来源:test_memory_limits.py


示例2: test_03_vm_per_project

    def test_03_vm_per_project(self):
        """Test VM limit per project
        """
        # Validate the following
        # 1. Set max VM per project to 2
        # 2. Create account and start 2 VMs. Verify VM state is Up and Running
        # 3. Try to create 3rd VM instance. The appropriate error or alert
        #    should be raised

        self.debug(
            "Updating instance resource limits for project: %s" %
                                                        self.project.id)
        # Set usage_vm=1 for Account 1
        update_resource_limit(
                              self.apiclient,
                              0, # Instance
                              max=2,
                              projectid=self.project.id
                              )

        self.debug("Deploying VM for project: %s" % self.project.id)
        virtual_machine_1 = VirtualMachine.create(
                                self.apiclient,
                                self.services["server"],
                                templateid=self.template.id,
                                serviceofferingid=self.service_offering.id,
                                projectid=self.project.id
                                )
        self.cleanup.append(virtual_machine_1)
        # Verify VM state
        self.assertEqual(
                            virtual_machine_1.state,
                            'Running',
                            "Check VM state is Running or not"
                        )
        self.debug("Deploying VM for project: %s" % self.project.id)
        virtual_machine_2 = VirtualMachine.create(
                                self.apiclient,
                                self.services["server"],
                                templateid=self.template.id,
                                serviceofferingid=self.service_offering.id,
                                projectid=self.project.id
                                )
        self.cleanup.append(virtual_machine_2)
        # Verify VM state
        self.assertEqual(
                            virtual_machine_2.state,
                            'Running',
                            "Check VM state is Running or not"
                        )
        # Exception should be raised for second instance
        with self.assertRaises(Exception):
            VirtualMachine.create(
                                self.apiclient,
                                self.services["server"],
                                templateid=self.template.id,
                                serviceofferingid=self.service_offering.id,
                                projectid=self.project.id
                                )
        return
开发者ID:diejiazhao,项目名称:cloudstack,代码行数:60,代码来源:test_project_limits.py


示例3: test_01_create_template_volume

    def test_01_create_template_volume(self):
        """Test Create template from volume
        """

        # Validate the following:
        # 1. Deploy new VM using the template created from Volume
        # 2. VM should be in Up and Running state

        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.debug("creating an instance with template ID: %s" % self.template.id)
        self.cleanup.append(virtual_machine)
        vm_response = VirtualMachine.list(
            self.apiclient, id=virtual_machine.id, account=self.account.name, domainid=self.account.domainid
        )
        # Verify VM response to check whether VM deployment was successful
        self.assertNotEqual(len(vm_response), 0, "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, "Running", "Check the state of VM created from Template")
        return
开发者ID:MissionCriticalCloudOldRepos,项目名称:cosmic-core,代码行数:27,代码来源:test_templates.py


示例4: 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.virtual_machine_2 = 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"],
        )

        NATRule.create(
            self.apiclient, self.virtual_machine, self.services["natrule"], ipaddressid=self.public_ip.ipaddress.id
        )

        self.cleanup = [self.account]
        return
开发者ID:ktenzer,项目名称:cloudstack,代码行数:35,代码来源:test_haproxy.py


示例5: validate_vm_deployment

    def validate_vm_deployment(self):
        """Validates VM deployment on different hosts"""

        vms = VirtualMachine.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            networkid=self.network_1.id,
            listall=True,
        )
        self.assertEqual(isinstance(vms, list), True, "List VMs shall return a valid response")
        host_1 = vms[0].hostid
        self.debug("Host for network 1: %s" % vms[0].hostid)

        vms = VirtualMachine.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            networkid=self.network_2.id,
            listall=True,
        )
        self.assertEqual(isinstance(vms, list), True, "List VMs shall return a valid response")
        host_2 = vms[0].hostid
        self.debug("Host for network 2: %s" % vms[0].hostid)

        self.assertNotEqual(host_1, host_2, "Both the virtual machines should be deployed on diff hosts ")
        return
开发者ID:mariocar,项目名称:cloudstack,代码行数:27,代码来源:test_vpc_host_maintenance.py


示例6: 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
开发者ID:Accelerite,项目名称:cloudstack,代码行数:58,代码来源:testpath_volume_cuncurrent_snapshots.py


示例7: test_02_nicira_controller_redirect

    def test_02_nicira_controller_redirect(self):
        """
            Nicira clusters will redirect clients (in this case ACS) to the master node.
            This test assumes that a Nicira cluster is present and configured properly, and
            that it has at least two controller nodes. The test will check that ASC follows
            redirects by:
                - adding a Nicira Nvp device that points to one of the cluster's slave controllers,
                - create a VM in a Nicira backed network
            If all is well, no matter what controller is specified (slaves or master), the vm (and respective router VM)
            should be created without issues.
        """
        nicira_slave = self.determine_slave_conroller(self.nicira_hosts, self.nicira_master_controller)
        self.debug("Nicira slave controller is: %s " % nicira_slave)

        nicira_device = NiciraNvp.add(
            self.api_client,
            None,
            self.physical_network_id,
            hostname=nicira_slave,
            username=self.nicira_credentials['username'],
            password=self.nicira_credentials['password'],
            transportzoneuuid=self.transport_zone_uuid)
        self.test_cleanup.append(nicira_device)

        network_services = {
            'name'            : 'nicira_enabled_network',
            'displaytext'     : 'nicira_enabled_network',
            'zoneid'          : self.zone.id,
            'networkoffering' : self.network_offering.id
        }
        network = Network.create(
            self.api_client,
            network_services,
            accountid='admin',
            domainid=self.domain.id,
        )
        self.test_cleanup.append(network)

        virtual_machine = VirtualMachine.create(
            self.api_client,
            self.vm_services['small'],
            accountid='admin',
            domainid=self.domain.id,
            serviceofferingid=self.service_offering.id,
            networkids=[network.id],
            mode=self.vm_services['mode']
        )
        self.test_cleanup.append(virtual_machine)

        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)

        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')

        vm_response = list_vm_response[0]
        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
开发者ID:sven-schubert,项目名称:cloudstack,代码行数:58,代码来源:test_nicira_controller.py


示例8: test_06_pt_startvm_false_attach_iso

    def test_06_pt_startvm_false_attach_iso(self):
        """ Positive test for stopped VM test path - T5

        # 1.  Deploy VM in the network with specifying startvm parameter
        #     as False
        # 2.  List VMs and verify that VM is in stopped state
        # 3.  Register an ISO and attach it to the VM
        # 4.  Verify that ISO is attached to the VM
        """

        # Create VM in account
        virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.defaultTemplateId,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[self.networkid, ] if self.networkid else None,
            zoneid=self.zone.id,
            startvm=False,
            mode=self.zone.networktype
        )
        self.cleanup.append(virtual_machine)

        response = virtual_machine.getState(
            self.apiclient,
            VirtualMachine.STOPPED)
        self.assertEqual(response[0], PASS, response[1])

        iso = Iso.create(
            self.userapiclient,
            self.testdata["iso"],
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid=self.zone.id
        )

        iso.download(self.userapiclient)
        virtual_machine.attach_iso(self.userapiclient, iso)

        vms = VirtualMachine.list(
            self.userapiclient,
            id=virtual_machine.id,
            listall=True
        )
        self.assertEqual(
            validateList(vms)[0],
            PASS,
            "List vms should return a valid list"
        )
        vm = vms[0]
        self.assertEqual(
            vm.isoid,
            iso.id,
            "The ISO status should be reflected in list Vm call"
        )
        return
开发者ID:K0zka,项目名称:cloudstack,代码行数:58,代码来源:testpath_stopped_vm.py


示例9: test_Scale_VM

    def test_Scale_VM(self):
        """
        @desc:
        1. Enable dynamic scaling in Global settings
        2. Register an CentOS 7 tempplate(with tools) and tick dynamic scaling
        3. Deploy VM with this template
        4.Start the VM and try to change service offering

        """
        self.hypervisor = str(get_hypervisor_type(self.api_client)).lower()
        if self.hypervisor != "xenserver":
            self.skipTest("This test can be run only on xenserver")
        self.updateConfigurAndRestart("enable.dynamic.scale.vm","true")
        template = Template.register(
           self.userapiclient,
          self.services["CentOS7template"],
            zoneid=self.zone.id,
           account=self.account.name,
           domainid=self.account.domainid
        )
        self.assertIsNotNone(template,"Failed to register CentOS 7 template")
        self.debug(
           "Registered a template with format {} and id {}".format(
              self.services["CentOS7template"]["format"],template.id)
        )
        template.download(self.userapiclient)
        self.cleanup.append(template)
        vm = VirtualMachine.create(
            self.userapiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            templateid=template.id,
            zoneid=self.zone.id
        )
        self.assertIsNotNone(vm,"Failed to deploy virtual machine")
        self.cleanup.append(vm)
        response = VirtualMachine.list(self.userapiclient,id=vm.id)
        status = validateList(response)
        self.assertEqual(status[0],PASS,"list vm response returned invalid list")
        self.assertEqual(status[1].state,"Running", "vm is not running")

        service_offering = ServiceOffering.create(
                self.apiClient,
                self.services["service_offerings"]["big"]
            )
        time.sleep(self.services["sleep"])
        vm.scale(self.userapiclient,service_offering.id)
        scaleresponse = VirtualMachine.list(self.userapiclient,id=vm.id)
        scalestatus = validateList(scaleresponse)
        self.assertEqual(scalestatus[0],PASS,"list vm response returned invalid list")
        self.assertEqual(scalestatus[1].serviceofferingname,service_offering.name, " service offering is not same")
        self.assertEqual(scalestatus[1].serviceofferingid,service_offering.id, " service offering ids are not same")


        return
开发者ID:Accelerite,项目名称:cloudstack,代码行数:57,代码来源:test_escalations_instances.py


示例10: test_01_positive_tests_usage

    def test_01_positive_tests_usage(self):
        """ Check events in usage_events table when VM creation fails

        Steps:
        1. Create service offering with large resource numbers
        2. Try to deploy a VM
        3. VM creation should fail and VM should be in error state
        4. Destroy the VM with expunge parameter True
        5. Check the events for the account in usage_events table
        6. There should be VM.CREATE, VM.DESTROY, VOLUME.CREATE and
            VOLUME.DELETE events present in the table
        """
        # Create VM in account
        with self.assertRaises(Exception):
            VirtualMachine.create(
                self.apiclient,
                self.testdata["small"],
                templateid=self.template.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
            )

        vms = VirtualMachine.list(self.apiclient, account=self.account.name, domaind=self.account.domainid)

        self.assertEqual(validateList(vms)[0], PASS, "Vm list validation failed")

        self.assertEqual(vms[0].state.lower(), "error", "VM should be in error state")

        qresultset = self.dbclient.execute("select id from account where uuid = '%s';" % self.account.id)
        self.assertEqual(isinstance(qresultset, list), True, "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = qresultset[0]

        account_id = qresult[0]
        self.debug("select type from usage_event where account_id = '%s';" % account_id)

        qresultset = self.dbclient.execute("select type from usage_event where account_id = '%s';" % account_id)
        self.assertEqual(isinstance(qresultset, list), True, "Check DB query result set for valid data")

        self.assertNotEqual(len(qresultset), 0, "Check DB Query result set")
        qresult = str(qresultset)
        self.debug("Query result: %s" % qresult)

        # Check if VM.CREATE, VM.DESTROY events present in usage_event table
        self.assertEqual(qresult.count("VM.CREATE"), 1, "Check VM.CREATE event in events table")

        self.assertEqual(qresult.count("VM.DESTROY"), 1, "Check VM.DESTROY in list events")

        # Check if VOLUME.CREATE, VOLUME.DELETE events present in usage_event
        # table
        self.assertEqual(qresult.count("VOLUME.CREATE"), 1, "Check VOLUME.CREATE in events table")

        self.assertEqual(qresult.count("VOLUME.DELETE"), 1, "Check VM.DELETE in events table")
        return
开发者ID:tianshangjun,项目名称:cloudstack,代码行数:57,代码来源:test_usage_events.py


示例11: 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_offerings"]["tiny"],
            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:Accelerite,项目名称:cloudstack,代码行数:57,代码来源:test_deploy_vms_with_varied_deploymentplanners.py


示例12: test_validateState_fails_after_retry_limit

    def test_validateState_fails_after_retry_limit(self):
        retries = 3
        timeout = 2
        api_client = MockApiClient(retries, 'initial state', 'final state')
        vm = VirtualMachine({'id': 'vm_id', 'nic': [NIC({'ipaddress': '192.168.0.100'})]}, {})
        state = vm.validateState(api_client, 'final state', timeout=timeout, interval=1)

        self.assertEqual(state, [FAIL, 'VirtualMachine state not transited to final state, operation timed out'])
        self.assertEqual(retries, api_client.retry_counter)
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:9,代码来源:test_base.py


示例13: test_validateState_succeeds_at_retry_limit

    def test_validateState_succeeds_at_retry_limit(self):
        retries = 3
        timeout = 3
        api_client = MockApiClient(retries, 'initial state', 'final state')
        vm = VirtualMachine({'id': 'vm_id', 'nic': [NIC({'ipaddress': '192.168.0.100'})]}, {})
        state = vm.validateState(api_client, 'final state', timeout=timeout, interval=1)

        self.assertEqual(state, [PASS, None])
        self.assertEqual(retries, api_client.retry_counter)
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:9,代码来源:test_base.py


示例14: test_deploy_vm_start_failure

    def test_deploy_vm_start_failure(self):
        """Test Deploy Virtual Machine - start operation failure and retry

        # Validate the following:
        # 1. 1st VM creation failed
        # 2. Check there were 4 failed start operation retries (mock count = (6-4) = 2)
        # 3. 2nd VM creation succeeded
        # 4. Check there were 2 failed start operation retries (mock count = (2-2) = 0)
        # 5. ListVM returns accurate information
        """
        self.virtual_machine = None
        with self.assertRaises(Exception):
            self.virtual_machine = VirtualMachine.create(
                self.apiclient,
                self.testdata["virtual_machine2"],
                accountid=self.account.name,
                zoneid=self.zone.id,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                templateid=self.template.id)

        self.mock_start_failure = self.mock_start_failure.query(self.apiclient)
        self.assertEqual(
            self.mock_start_failure.count,
            2,
            msg="Start failure mock not executed")

        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.testdata["virtual_machine3"],
            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.assertTrue(isinstance(list_vms, list) and len(list_vms) > 0, msg="List VM response empty")
        vm = list_vms[0]
        self.assertEqual(
            vm.id,
            self.virtual_machine.id,
            "VM ids do not match")
        self.assertEqual(
            vm.name,
            self.virtual_machine.name,
            "VM names do not match")
        self.assertEqual(
            vm.state,
            "Running",
            msg="VM is not in Running state")

        self.mock_start_failure = self.mock_start_failure.query(self.apiclient)
        self.assertEqual(
            self.mock_start_failure.count,
            0,
            msg="Start failure mock not executed")
开发者ID:aali-dincloud,项目名称:cloudstack,代码行数:56,代码来源:test_deploy_vm.py


示例15: test_deploy_vm

    def test_deploy_vm(self):
        """Test Deploy Virtual Machine
 
        # Validate the following:
        # - listVirtualMachines returns accurate information
        """
        self.debug(
            "templatess: %s"\
            % self.template
        )
 
        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"
        )
开发者ID:realsystem,项目名称:my_scripts,代码行数:55,代码来源:test_deploy_vm.py


示例16: test_05_use_private_template_in_project

    def test_05_use_private_template_in_project(self):
        """Test use of private template in a project
        """
        # 1. Create a project
        # 2. Verify that in order to use somebody's Private template for vm
        #    creation in the project, permission to use the template has to
        #    be granted to the Project (use API 'updateTemplatePermissions'
        #    with project id to achieve that).

        try:
            self.debug("Deploying VM for with public template: %s" % self.template.id)
            virtual_machine_1 = VirtualMachine.create(
                self.apiclient,
                self.services["server"],
                templateid=self.template.id,
                serviceofferingid=self.service_offering.id,
                projectid=self.project.id,
            )
            self.cleanup.append(virtual_machine_1)
            # Verify VM state
            self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")
            virtual_machine_1.stop(self.apiclient)
            # Get the Root disk of VM
            volumes = list_volumes(self.apiclient, projectid=self.project.id, type="ROOT", listall=True)
            self.assertEqual(isinstance(volumes, list), True, "Check for list volume response return valid data")
            volume = volumes[0]

            self.debug("Creating template from volume: %s" % volume.id)
            # Create a template from the ROOTDISK
            template_1 = Template.create(self.userapiclient, self.services["template"], volumeid=volume.id)

            self.cleanup.append(template_1)
            # Verify Template state
            self.assertEqual(template_1.isready, True, "Check Template is in ready state or not")

            # Update template permissions to grant permission to project
            self.debug(
                "Updating template permissions:%s to grant access to project: %s" % (template_1.id, self.project.id)
            )

            template_1.updatePermissions(self.apiclient, op="add", projectids=self.project.id)
            self.debug("Deploying VM for with privileged template: %s" % self.template.id)
            virtual_machine_2 = VirtualMachine.create(
                self.apiclient,
                self.services["server"],
                templateid=template_1.id,
                serviceofferingid=self.service_offering.id,
                projectid=self.project.id,
            )
            self.cleanup.append(virtual_machine_2)
            # Verify VM state
            self.assertEqual(virtual_machine_2.state, "Running", "Check VM state is Running or not")
        except Exception as e:
            self.fail("Exception occured: %s" % e)
        return
开发者ID:maksimov,项目名称:cloudstack,代码行数:55,代码来源:test_project_resources.py


示例17: setUp

 def setUp(self):
     self.apiclient = self.testClient.getApiClient()
     self.dbclient = self.testClient.getDbConnection()
     self.cleanup = []
     # Deploy guest vm
     try:
         self.virtual_machine = VirtualMachine.create(
             self.apiclient,
             self.testdata["server_without_disk"],
             templateid=self.template.id,
             accountid=self.account.name,
             domainid=self.testdata["domainid"],
             zoneid=self.testdata["zoneid"],
             serviceofferingid=self.service_offering.id,
             mode=self.testdata["mode"],
         )
     except Exception as e:
         raise Exception(
             "Warning: Exception during vm deployment: {}".format(e))
     self.vm_response = VirtualMachine.list(
         self.apiclient,
         id=self.virtual_machine.id
     )
     self.assertEqual(
         isinstance(self.vm_response, list),
         True,
         "Check VM list response returned a valid list"
     )
     self.ip_range = list(
         netaddr.iter_iprange(
             unicode(
                 self.testdata["vlan_ip_range"]["startip"]), unicode(
                 self.testdata["vlan_ip_range"]["endip"])))
     self.nic_ip = netaddr.IPAddress(
         unicode(
             self.vm_response[0].nic[0].ipaddress))
     self.debug("vm got {} as ip address".format(self.nic_ip))
     self.assertIn(
         self.nic_ip,
         self.ip_range,
         "VM did not get the ip address from the new ip range"
     )
     ip_alias = self.dbclient.execute(
         "select ip4_address from nic_ip_alias;"
     )
     self.alias_ip = str(ip_alias[0][0])
     self.debug("alias ip : %s" % self.alias_ip)
     self.assertNotEqual(
         self.alias_ip,
         None,
         "Error in creating ip alias. Please check MS logs"
     )
     self.cleanup.append(self.virtual_machine)
     return
开发者ID:Tosta-Mixta,项目名称:cloudstack,代码行数:54,代码来源:test_multiple_ip_ranges.py


示例18: test_deploy_multiple_vm

    def test_deploy_multiple_vm(self, value):
        """Test Deploy multiple VMs with & verify the usage
        # Validate the following
        # 1. Deploy multiple VMs with this service offering
        # 2. Update Resource count for the root admin Primary Storage usage
        # 3. Primary Storage usage should list properly
        # 4. Destroy one VM among multiple VM's and verify that primary storage count
        #  decreases by equivalent amount
        """

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine_2 = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
                            accountid=self.account.name, domainid=self.account.domainid,
                            diskofferingid=self.disk_offering.id,
                            serviceofferingid=self.service_offering.id)

        expectedCount = (self.initialResourceCount * 2) #Total 2 vms
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine_3 = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
                            accountid=self.account.name, domainid=self.account.domainid,
                            diskofferingid=self.disk_offering.id,
                            serviceofferingid=self.service_offering.id)

        expectedCount = (self.initialResourceCount * 3) #Total 3 vms
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        self.debug("Destroying instance: %s" % self.virtualMachine_2.name)
        try:
    	    self.virtualMachine_2.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        self.assertTrue(isVmExpunged(self.apiclient, self.virtualMachine_2.id), "VM not expunged \
                in allotted time")

        expectedCount -= (self.template.size / (1024 ** 3))
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
	return
开发者ID:Accelerite,项目名称:cloudstack,代码行数:53,代码来源:test_ps_limits.py


示例19: test_01_deploy_vm_no_startvm

    def test_01_deploy_vm_no_startvm(self):
        """Test Deploy Virtual Machine with no startVM parameter
        """

        # Validate the following:
        # 1. deploy Vm  without specifying the startvm parameter
        # 2. Should be able to login to the VM.
        # 3. listVM command should return the deployed VM.State of this VM
        #    should be "Running".

        self.debug("Deploying instance in the account: %s" % self.account.name)
        self.virtual_machine_1 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            diskofferingid=self.disk_offering.id,
            startvm=False,
        )

        response = self.virtual_machine_1.getState(self.apiclient, VirtualMachine.STOPPED)
        self.assertEqual(response[0], PASS, response[1])
        self.debug("Checking the router state after VM deployment")
        routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True)
        self.assertEqual(routers, None, "List routers should return empty response")
        self.debug("Deploying another instance (startvm=true) in the account: %s" % self.account.name)
        self.virtual_machine_2 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            diskofferingid=self.disk_offering.id,
            startvm=True,
        )

        response = self.virtual_machine_2.getState(self.apiclient, VirtualMachine.RUNNING)
        self.assertEqual(response[0], PASS, response[1])
        self.debug("Checking the router state after VM deployment")
        routers = Router.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True)
        self.assertEqual(isinstance(routers, list), True, "List routers should not return empty response")
        for router in routers:
            self.debug("Router state: %s" % router.state)
            self.assertEqual(
                router.state, "Running", "Router should be in running state when instance is running in the account"
            )
        self.debug("Destroying the running VM:%s&quo 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base.VmSnapshot类代码示例发布时间:2022-05-27
下一篇:
Python base.VPC类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap