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


Python Template.create方法代码示例

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


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

示例1: test_01_check_template_size

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_01_check_template_size(self):
        """TS_BUG_009-Test the size of template created from root disk
        """


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

        #Create template from volume
        template = Template.create(
                                   self.apiclient,
                                   self.services["template"],
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid
                                )
        self.debug("Creating template with ID: %s" % template.id)
        # Volume and Template Size should be same
        self.assertEqual(
                             template.size,
                             self.volume.size,
                             "Check if size of template and volume are same"
                             )
        return
开发者ID:MountHuang,项目名称:cloudstack,代码行数:27,代码来源:test_blocker_bugs.py

示例2: test_01_create_template

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_01_create_template(self):
        """Test create public & private template
        """

        # Validate the following:
        # 1. database (vm_template table) should be updated
        #    with newly created template
        # 2. UI should show the newly added template
        # 3. ListTemplates API should show the newly added template

        #Create template from Virtual machine and Volume ID
        template = Template.create(
                                self.apiclient,
                                self.services["template"],
                                self.volume.id,
                                account=self.account.name,
                                domainid=self.account.domainid
                                )
        self.cleanup.append(template)

        self.debug("Created template with ID: %s" % template.id)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=template.id
                                    )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.displaytext,
                            self.services["template"]["displaytext"],
                            "Check display text of newly created template"
                        )
        name = template_response.name
        self.assertEqual(
                            name.count(self.services["template"]["name"]),
                            1,
                            "Check name of newly created template"
                        )
        self.assertEqual(
                            template_response.ostypeid,
                            self.services["template"]["ostypeid"],
                            "Check osTypeID of newly created template"
                        )
        return
开发者ID:krissterckx,项目名称:cloudstack,代码行数:61,代码来源:test_templates.py

示例3: test_05_use_private_template_in_project

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    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,代码行数:57,代码来源:test_project_resources.py

示例4: create_template

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
 def create_template(self, vm):
     self.debug("Creating guest VM template")
     list_volume = Volume.list(self.api_client, virtualmachineid=vm.id, type="ROOT", listall=True)
     if isinstance(list_volume, list):
         self.volume = list_volume[0]
     else:
         raise Exception("Exception: Unable to find root volume for VM with ID - %s" % vm.id)
     self.pw_enabled_template = Template.create(
         self.api_client,
         self.test_data["template"],
         self.volume.id,
         account=self.account.name,
         domainid=self.account.domainid,
     )
     self.assertEqual(self.pw_enabled_template.passwordenabled, True, "template is not passwordenabled")
     self.cleanup.append(self.pw_enabled_template)
     self.debug("Created guest VM template")
开发者ID:bheuvel,项目名称:cloudstack,代码行数:19,代码来源:test_nuage_password_reset.py

示例5: create_template

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def create_template(self, vm):
        self.debug("CREATE TEMPLATE")
        list_volume = Volume.list(self.apiclient,
                                  virtualmachineid=vm.id,
                                  type='ROOT',
                                  listall=True)
        if isinstance(list_volume, list):
            self.volume = list_volume[0]
        else:
            raise Exception("Exception: Unable to find root volume for VM: %s" % vm.id)

        self.test_data["template_pr"]["ostype"] = self.test_data["ostype_pr"]
        self.pw_enabled_template = Template.create(
            self.apiclient,
            self.test_data["template_pr"],
            self.volume.id,
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.assertEqual(self.pw_enabled_template.passwordenabled, True, "template is not passwordenabled")
        self.cleanup.append(self.pw_enabled_template)
开发者ID:DKrul,项目名称:cloudstack,代码行数:23,代码来源:test_nuage_password_reset.py

示例6: test_04_public_template_use_in_project

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_04_public_template_use_in_project(self):
        """Test Templates creation in projects
        """
        # 1. Create a project
        # 2. Verify Public templates can be used without any restriction
        # 3. Verify that template created in project can be used in project
        #    without any restrictions

        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.apiclient, self.services["template"], volumeid=volume.id, projectid=self.project.id
            )

            self.cleanup.append(template_1)
            # Verify Template state
            self.assertEqual(template_1.isready, True, "Check Template is in ready state or not")
        except Exception as e:
            self.fail("Exception occured: %s" % e)
        return
开发者ID:maksimov,项目名称:cloudstack,代码行数:40,代码来源:test_project_resources.py

示例7: test_02_create__template_new_resized_rootvolume_size

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_02_create__template_new_resized_rootvolume_size(self):
        """Test create Template resized root volume

        # Validate the following

        # 1. Deploy a VM without any disk offering (only root disk)
        # 2. Perform(resize)  of the root  volume
        # 3. Stop the vm
        # 4. Create a template from  resized  root volume
        """

        result = self.setupAccounts()
        self.assertEqual(result[0], PASS, result[1])
        apiclient = self.testClient.getUserApiClient(
            UserName=self.parentd_admin.name,
            DomainName=self.parentd_admin.domain)
        self.assertNotEqual(apiclient, FAILED, "Failed to get api client\
                            of account: %s" % self.parentd_admin.name)

        # deploy a vm
        try:
            if self.updateclone:

                self.virtual_machine = VirtualMachine.create(
                    apiclient, self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.services_offering_vmware.id,
                    mode=self.zone.networktype
                )
            else:
                self.virtual_machine = VirtualMachine.create(
                    apiclient, self.services["virtual_machine"],
                    accountid=self.parentd_admin.name,
                    domainid=self.parent_domain.id,
                    serviceofferingid=self.service_offering.id,
                    mode=self.zone.networktype
                )

            # listVirtual macine
            list_vms = VirtualMachine.list(apiclient,
                                           id=self.virtual_machine.id)
            self.debug("Verify listVirtualMachines response"
                       " for virtual machine: %s" % self.virtual_machine.id
                       )
            res = validateList(list_vms)
            self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list response")
            self.cleanup.append(self.virtual_machine)
            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"
            )
            # get root vol from created vm, verify it is correct size
            list_volume_response = Volume.list(
                apiclient,
                virtualmachineid=
                self.virtual_machine.id,
                type='ROOT',
                listall='True'
            )
            res = validateList(list_volume_response)
            self.assertNotEqual(res[2], INVALID_INPUT, "listVolumes returned invalid object in response")
            rootvolume = list_volume_response[0]
            newsize = (rootvolume.size >> 30) + 2
            result = self.chk_volume_resize(apiclient, vm)
            if result:
                try:
                    # create a template from stopped VM instances root volume
                    if vm.state == "Running":
                        self.virtual_machine.stop(apiclient)
                    template_from_root = Template.create(
                        apiclient,
                        self.services["template"],
                        volumeid=rootvolume.id,
                        account=self.parentd_admin.name,
                        domainid=self.parent_domain.id)
                    list_template_response = Template.list(
                        apiclient,
                        id=template_from_root.id,
                        templatefilter="all")
                    res = validateList(list_template_response)
                    self.assertNotEqual(res[2], INVALID_INPUT, "Check if template exists in ListTemplates")
                    # Deploy new virtual machine using template
                    self.virtual_machine2 = VirtualMachine.create(
                        apiclient,
                        self.services["virtual_machine"],
                        templateid=template_from_root.id,
                        accountid=self.parentd_admin.name,
#.........这里部分代码省略.........
开发者ID:Accelerite,项目名称:cloudstack,代码行数:103,代码来源:test_rootvolume_resize.py

示例8: test_01_positive_test_1

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_01_positive_test_1(self):
        """
        positive test for volume life cycle
        # 1. Deploy a vm [vm1] with shared storage and data disk
        # 2. Deploy a vm [vm2]with shared storage without data disk
        # 3.
        # 4. Create a new volume and attache to vm2
        # 5. Detach data disk from vm1 and download it
        #  Variance(1-9)
        # 6. Upload volume by providing url of downloaded volume in step 5
        # 7. Attach the volume to a different vm - vm2
        # 8. Try to delete an attached volume
        # 9. Create template from root volume of VM1
        # 10. Create new VM using the template created in step 9
        # 11. Delete the template
        # 12. Detach the disk from VM2 and re-attach the disk to VM1
        # 13.
        # 14.
        # 15.Migrate volume(detached) and then attach to a vm and live-migrate
        # 16.Upload volume of size smaller  than storage.max.volume.upload.size(leaving the negative case)
        # 17.NA
        # 18.
        # 19.NA
        # 20.Detach data disks from VM2 and delete volume

        """
        # 1. Deploy a vm [vm1] with shared storage and data disk
        self.virtual_machine_1 = VirtualMachine.create(self.userapiclient,
                                                       self.testdata["small"],
                                                       templateid=self.template.id,
                                                       accountid=self.account.name,
                                                       domainid=self.account.domainid,
                                                       serviceofferingid=self.service_offering_1.id,
                                                       zoneid=self.zone.id,
                                                       diskofferingid=self.disk_offering_1.id,
                                                       mode=self.testdata["mode"]
                                                       )
        verify_vm(self, self.virtual_machine_1.id)
        # List data volume for vm1
        list_volume = Volume.list(self.userapiclient,
                                  virtualmachineid=self.virtual_machine_1.id,
                                  type='DATADISK'
                                  )
        self.assertEqual(validateList(list_volume)[0], PASS, "Check List volume response for vm id  %s" % self.virtual_machine_1.id)
        list_data_volume_for_vm1 = list_volume[0]
        self.assertEqual(len(list_volume), 1, "There is no data disk attached to vm id:%s" % self.virtual_machine_1.id)
        self.assertEqual(list_data_volume_for_vm1.virtualmachineid, str(self.virtual_machine_1.id), "Check if volume state (attached) is reflected")
        # 2. Deploy a vm [vm2]with shared storage without data disk
        self.virtual_machine_2 = VirtualMachine.create(self.userapiclient,
                                                       self.testdata["small"],
                                                       templateid=self.template.id,
                                                       accountid=self.account.name,
                                                       domainid=self.account.domainid,
                                                       serviceofferingid=self.service_offering_1.id,
                                                       zoneid=self.zone.id,
                                                       mode=self.testdata["mode"]
                                                       )
        verify_vm(self, self.virtual_machine_2.id)

        #4. Create a new volume and attache to vm2
        self.volume = Volume.create(self.userapiclient,
                                    services=self.testdata["volume"],
                                    diskofferingid=self.disk_offering_1.id,
                                    zoneid=self.zone.id
                                    )

        list_data_volume = Volume.list(self.userapiclient,
                                       id=self.volume.id
                                       )
        self.assertEqual(validateList(list_data_volume)[0], PASS, "Check List volume response for volume %s" % self.volume.id)
        self.assertEqual(list_data_volume[0].id, self.volume.id, "check list volume response for volume id:  %s" % self.volume.id)
        self.debug("volume id %s got created successfully" % list_data_volume[0].id)
        # Attach volume to vm2
        self.virtual_machine_2.attach_volume(self.userapiclient,
                                             self.volume
                                             )
        verify_attach_volume(self, self.virtual_machine_2.id, self.volume.id)

        #Variance
        if self.zone.localstorageenabled:
            # V1.Create vm3 with local storage offering
            self.virtual_machine_local_3=VirtualMachine.create(self.userapiclient,
                                                               self.testdata["small"],
                                                               templateid=self.template.id,
                                                               accountid=self.account.name,
                                                               domainid=self.account.domainid,
                                                               serviceofferingid=self.service_offering_2.id,
                                                               zoneid=self.zone.id,
                                                               mode=self.testdata["mode"]
                                                               )
            verify_vm(self, self.virtual_machine_local_3.id)

            # V2.create two data disk on local storage
            self.local_volumes = []
            for i in range(2):

                    local_volume = Volume.create(self.userapiclient,
                                                 services=self.testdata["volume"],
                                                 diskofferingid=self.disk_offering_local.id,
                                                 zoneid=self.zone.id
#.........这里部分代码省略.........
开发者ID:woduxi,项目名称:cloudstack,代码行数:103,代码来源:testpath_volumelifecycle.py

示例9: test_01_data_persistency_root_disk

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_01_data_persistency_root_disk(self):
        """
        Test the timing issue of root disk data sync

        # 1. Write data to root disk of a VM
        # 2. Create a template from the root disk of VM
        # 3. Create a new VM from this template
        # 4. Check that the data is present in the new VM

        This is to test that data is persisted on root disk of VM or not
        when template is created immediately from it
        """

        ssh = self.virtual_machine.get_ssh_client()

        sampleText = "This is sample data"

        cmds = [
                "cd /root/",
                "touch testFile.txt",
                "chmod 600 testFile.txt",
                "echo %s >> testFile.txt" % sampleText
                ]
        for c in cmds:
            ssh.execute(c)

        #Stop virtual machine
        self.virtual_machine.stop(self.api_client)

        list_volume = Volume.list(
                            self.api_client,
                            virtualmachineid=self.virtual_machine.id,
                            type='ROOT',
                            listall=True)

        if isinstance(list_volume, list):
            self.volume = list_volume[0]
        else:
            raise Exception(
                "Exception: Unable to find root volume for VM: %s" %
                self.virtual_machine.id)

        self.services["template"]["ostype"] = self.services["ostype"]
        #Create templates for Edit, Delete & update permissions testcases
        customTemplate = Template.create(
                self.userapiclient,
                self.services["template"],
                self.volume.id,
                account=self.account.name,
                domainid=self.account.domainid
            )
        self.cleanup.append(customTemplate)
        # Delete the VM - No longer needed
        self.virtual_machine.delete(self.apiclient)

        virtual_machine = VirtualMachine.create(
                                    self.apiclient,
                                    self.services["virtual_machine"],
                                    templateid=customTemplate.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    serviceofferingid=self.service_offering.id,
                                    mode=self.services["mode"]
                                    )

        ssh = virtual_machine.get_ssh_client()

        response = ssh.execute("cat /root/testFile.txt")
        res = str(response[0])

        self.assertEqual(res, sampleText, "The data %s does not match\
                with sample test %s" %
                (res, sampleText))
        return
开发者ID:PCextreme,项目名称:cloudstack,代码行数:76,代码来源:test_blocker_bugs.py

示例10: test_09_copy_delete_template

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_09_copy_delete_template(self):
	cmd = listZones.listZonesCmd()
        zones = self.apiclient.listZones(cmd)
        if not isinstance(zones, list):
            raise Exception("Failed to find zones.")
        if len(zones) < 2:
            self.skipTest(
                "Skipping test due to there are less than two zones.")
        return
			
	self.sourceZone = zones[0]
	self.destZone = zones[1]
            
        template = Template.create(
                                self.apiclient,
                                self.services["template"],
                                self.volume.id,
                                account=self.account.name,
                                domainid=self.account.domainid
                                )
        self.cleanup.append(template)

        self.debug("Created template with ID: %s" % template.id)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=template.id
                                    )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
	#Copy template from zone1 to zone2
        copytemplate = Template.copy(
            cls.apiclient,
            zoneid=cls.sourceZone.id,
            destzoneid = cls.destZone.id
        )
        cls._cleanup.append(cls.copytemplate)

        list_template_response = Template.list(
            self.apiclient,
	    templatefilter=self.services["template"]["templatefilter"],
            id=self.template.id,
            zoneid=self.destZone.id
        )
        self.assertEqual(
            list_template_response,
            None,
            "Check template available in List Templates"
        )

        self.deltemplate = list_template_response[0]

        self.debug("Deleting template: %s" % self.deltemplate)
        # Delete the template
        self.deltemplate.delete(self.apiclient)
        self.debug("Delete template: %s successful" % self.deltemplate)

        copytemplate = Template.copy(
            self.apiclient,
            zoneid=self.sourceZone.id,
            destzoneid = self.destZone.id
        )

        removed = cls.dbclient.execute("select removed from template_zone_ref where zone_id='%s' and template_id='%s';" % self.destZone.id, self.template.id)

        self.assertEqual(
            removed,
            NULL,
            "Removed state is not correct."
        )
        return
开发者ID:krissterckx,项目名称:cloudstack,代码行数:85,代码来源:test_templates.py

示例11: test_19_template_tag

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_19_template_tag(self):
        """ Test creation, listing and deletion tag on templates
        """

        try:
            
            noffering=NetworkOffering.list(
                     self.user_api_client,
                     name="DefaultIsolatedNetworkOfferingWithSourceNatService"
                     )
            vm4network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

            list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm4network.id
                                            )
            self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )

            vm_1 = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=self.template.id,
                                    networkids=vm4network.id,
                                    serviceofferingid=self.service_offering.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
            time.sleep(600)
            self.debug("Stopping the virtual machine: %s" % vm_1.name)
            # Stop virtual machine
            vm_1.stop(self.user_api_client)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        timeout = self.services["timeout"]
        while True:
            list_volume = Volume.list(
                self.user_api_client,
                virtualmachineid=vm_1.id,
                type='ROOT',
                listall=True
            )
            if isinstance(list_volume, list):
                break
            elif timeout == 0:
                raise Exception("List volumes failed.")

            time.sleep(5)
            timeout = timeout - 1

        self.volume = list_volume[0]

        self.debug("Creating template from ROOT disk of virtual machine: %s" %
                   vm_1.name)
        # Create template from volume
        template = Template.create(
            self.user_api_client,
            self.services["template"],
            self.volume.id
        )
        self.cleanup.append(template)
        self.debug("Created the template(%s). Now restarting the userVm: %s" %
                   (template.name, vm_1.name))
        vm_1.start(self.user_api_client)

        self.debug("Creating a tag for the template")
        tag = Tag.create(
            self.user_api_client,
            resourceIds=template.id,
            resourceType='Template',
            tags={'OS': 'windows8'}
        )
        self.debug("Tag created: %s" % tag.__dict__)

        tags = Tag.list(
            self.user_api_client,
            listall=True,
            resourceType='Template',
            key='OS',
            value='windows8'
        )
        self.assertEqual(
            isinstance(tags, list),
            True,
            "List tags should not return empty response"
        )
        self.assertEqual(
#.........这里部分代码省略.........
开发者ID:EdwardBetts,项目名称:blackhole,代码行数:103,代码来源:test_interop_xd_ccp.py

示例12: test_02_template_permissions

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_02_template_permissions(self):
        """
        @Desc: Test to create Public Template by registering or by snapshot and volume when
        Global parameter 'allow.public.user.template' is set to  False
        @steps:
        1.Set Global parameter 'allow.public.user.template' as False. Restart Management server
        2. Create a domain
        3. Create a domain admin and a domain user
        4. Create a vm as domain user
        5. take snapshot of root disk as user vm
        6. try to create public template from snapshot . It should fail
        7. stop the VM
        8. take the public template from volume. it should fail
        9. register a public template as a domain user . it should fail
        10. create a VM  as domain admin
        11. create a snapshot of root disk as domain admin
        12 create a public template of the snapshot .it should fail
        13. Register a public template as domain admin. it should fail
        14 Stop the vm as domain admin
        15. Create a template from volume as domain admin . it should fail

        """
        self.updateConfigurAndRestart("allow.public.user.templates", "false")
        
        user_account = Account.create(
            self.apiclient,
            self.testdata["account2"],
            admin=False,
            domainid=self.domain.id
        )
        admin_user = self.account.user[0]
        self.admin_api_client = self.testClient.getUserApiClient(
            admin_user.username,
            self.domain.name)
        user = user_account.user[0]
        self.user_api_client = self.testClient.getUserApiClient(
            user.username,
            self.domain.name)

        self.testdata["templates"]["ispublic"] = True
        # Register new public template as domain user
        # Exception should be raised for registering public template
        try:
            template = Template.register(
                self.user_api_client,
                self.testdata["templates"],
                zoneid=self.zone.id,
                account=user_account.name,
                domainid=user_account.domainid,
                hypervisor=self.hypervisor
            )
            self.updateConfigurAndRestart("allow.public.user.templates", "true")
            self.fail("Template creation passed for user")
        except CloudstackAPIException  as e:
            self.assertRaises("Exception Raised : %s" % e)
        # Register new public template as domain admin
        # Exception should be raised for registering public template
        try:
            template = Template.register(
                self.admin_api_client,
                self.testdata["templates"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
                hypervisor=self.hypervisor
            )
            self.updateConfigurAndRestart("allow.public.user.templates", "true")
            self.fail("Template creation passed for domain admin")
        except CloudstackAPIException  as e:
            self.assertRaises("Exception Raised : %s" % e)

        user_vm_created = VirtualMachine.create(
            self.user_api_client,
            self.testdata["virtual_machine"],
            accountid=user_account.name,
            domainid=user_account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.assertIsNotNone(user_vm_created,
                             "VM creation failed"
        )
        # Get the Root disk of VM
        volume = list_volumes(
            self.user_api_client,
            virtualmachineid=user_vm_created.id,
            type='ROOT',
            listall=True
        )
        snapshot_created = Snapshot.create(
            self.user_api_client,
            volume[0].id,
            account=user_account.name,
            domainid=user_account.domainid
        )
        self.assertIsNotNone(
            snapshot_created,
            "Snapshot creation failed"
        )
        self.debug("Creating a template from snapshot: %s" % snapshot_created.id)
        #
#.........这里部分代码省略.........
开发者ID:EdwardBetts,项目名称:blackhole,代码行数:103,代码来源:test_escalation_templates.py

示例13: test_07_templates_per_project

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
    def test_07_templates_per_project(self):
        """Test Templates limit per project
        """
        # 1. set max no of templates per project to 1.
        # 2. Create a template in this project. Both template should be in
        #    ready state
        # 3. Try create 2nd template in the project. It should give the user
        #    appropriate error and an alert should be generated.

        # Reset the volume limits
        update_resource_limit(
                              self.apiclient,
                              2, # Volume
                              max=5,
                              projectid=self.project.id
                              )
        self.debug(
            "Updating template resource limits for domain: %s" %
                                        self.account.domainid)
        # Set usage_vm=1 for Account 1
        update_resource_limit(
                              self.apiclient,
                              4, # Template
                              max=1,
                              projectid=self.project.id
                              )

        self.debug("Deploying VM for account: %s" % self.account.name)
        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,
                            virtualmachineid=virtual_machine_1.id,
                            projectid=self.project.id,
                            type='ROOT'
                            )
        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,
                            projectid=self.project.id
                            )

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

        # Exception should be raised for second template
        with self.assertRaises(Exception):
            Template.create(
                            self.userapiclient,
                            self.services["template"],
                            volumeid=volume.id,
                            projectid=self.project.id
                            )
        return
开发者ID:vanadinite,项目名称:cloudstack,代码行数:85,代码来源:test_project_limits.py

示例14: test01_template_download_URL_expire

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
 def test01_template_download_URL_expire(self):
     """
     @Desc:Template files are deleted from secondary storage after download URL expires
     Step1:Deploy vm with default cent os template
     Step2:Stop the vm
     Step3:Create template from the vm's root volume
     Step4:Extract Template and wait for the download url to expire
     Step5:Deploy another vm with the template created at Step3
     Step6:Verify that vm deployment succeeds
     """
     params = ["extract.url.expiration.interval", "extract.url.cleanup.interval"]
     wait_time = 0
     for param in params:
         config = Configurations.list(self.apiClient, name=param)
         self.assertEqual(validateList(config)[0], PASS, "Config list returned invalid response")
         wait_time = wait_time + int(config[0].value)
     self.debug("Total wait time for url expiry: %s" % wait_time)
     # Creating Virtual Machine
     self.virtual_machine = VirtualMachine.create(
         self.userapiclient,
         self.services["virtual_machine"],
         accountid=self.account.name,
         domainid=self.account.domainid,
         serviceofferingid=self.service_offering.id,
     )
     self.assertIsNotNone(self.virtual_machine, "Virtual Machine creation failed")
     self.cleanup.append(self.virtual_machine)
     # Stop virtual machine
     self.virtual_machine.stop(self.userapiclient)
     list_volume = Volume.list(
         self.userapiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True
     )
     self.assertEqual(validateList(list_volume)[0], PASS, "list volumes with type ROOT returned invalid list")
     self.volume = list_volume[0]
     self.create_template = Template.create(
         self.userapiclient,
         self.services["template"],
         volumeid=self.volume.id,
         account=self.account.name,
         domainid=self.account.domainid,
     )
     self.assertIsNotNone(self.create_template, "Failed to create template from root volume")
     self.cleanup.append(self.create_template)
     """
     Extract template
     """
     try:
         Template.extract(self.userapiclient, self.create_template.id, "HTTP_DOWNLOAD", self.zone.id)
     except Exception as e:
         self.fail("Extract template failed with error %s" % e)
     self.debug("Waiting for %s seconds for url to expire" % repr(wait_time + 20))
     time.sleep(wait_time + 20)
     self.debug("Waited for %s seconds for url to expire" % repr(wait_time + 20))
     """
     Deploy vm with the template created from the volume. After url expiration interval only
     url should be deleted not the template. To validate this deploy vm with the template
     """
     try:
         self.vm = VirtualMachine.create(
             self.userapiclient,
             self.services["virtual_machine"],
             accountid=self.account.name,
             domainid=self.account.domainid,
             serviceofferingid=self.service_offering.id,
             templateid=self.create_template.id,
         )
         self.cleanup.append(self.vm)
     except Exception as e:
         self.fail(
             "Template is automatically deleted after URL expired.\
                   So vm deployment failed with error: %s"
             % e
         )
     return
开发者ID:tianshangjun,项目名称:cloudstack,代码行数:76,代码来源:test_escalations_templates.py

示例15: Template

# 需要导入模块: from marvin.lib.base import Template [as 别名]
# 或者: from marvin.lib.base.Template import create [as 别名]
        if zone.allocationstate == 'Enabled':
          services = {}
          services["displaytext"] = "Debian"
          services["name"] = "deb"
          if options.upload_tmpl is not None:
            services["hypervisor"] = "KVM"
            services["format"] = "QCOW2"
            services["url"] = options.upload_tmpl
          if options.upload_iso is not None:
            services["url"] = options.upload_iso
          services["ostype"] = "Debian GNU/Linux 7(64-bit)"
          services["zoneid"] = zone.id
          tmp_dict = {}
          if options.upload_tmpl is not None:
            my_templ = Template(tmp_dict)
            if my_templ.register(apiClient, services) == FAILED:
              print "Uploading template failed"
              tc_run_logger.debug("\n=== Uploading template failed ===");
              exit(1)
          if options.upload_iso is not None:
            my_templ = Iso(tmp_dict)
            if my_templ.create(apiClient, services) == FAILED:
              print "Uploading template failed"
              tc_run_logger.debug("\n=== Uploading template failed ===");
              exit(1)
        else:
          print "Zone is not ready"
    else:
      print "No zones"
  exit(0)
开发者ID:realsystem,项目名称:my_scripts,代码行数:32,代码来源:upload_templates.py


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