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


Python VmSnapshot.revertToSnapshot方法代码示例

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


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

示例1: test_02_take_VM_snapshot_with_data_disk

# 需要导入模块: from marvin.lib.base import VmSnapshot [as 别名]
# 或者: from marvin.lib.base.VmSnapshot import revertToSnapshot [as 别名]

#.........这里部分代码省略.........
        root_volume_vdis_after_create = self._get_vdis(root_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(root_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            root_volume_vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        data_volume_xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_data_volume_name)[0]

        data_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(data_volume_xen_sr)

        self._check_list(data_volume_xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        data_volume_vdis_after_create = self._get_vdis(data_volume_xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(data_volume_vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            data_volume_vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._check_list(list_vm_snapshots, 1, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(root_volume_id)

        self.assertNotEqual(
            root_volume_path_1,
            root_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        root_volume_xen_vdis = self.xen_session.xenapi.SR.get_VDIs(root_volume_xen_sr)

        self._check_list(root_volume_xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        root_volume_vdis_after_revert = self._get_vdis(root_volume_xen_vdis)

        self.assertNotEqual(
            root_volume_vdis_after_create.active_vdi["uuid"],
            root_volume_vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            root_volume_vdis_after_create.snapshot_vdi["uuid"],
            root_volume_vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
开发者ID:CIETstudents,项目名称:cloudstack,代码行数:70,代码来源:TestVMSnapshots.py

示例2: test_02_revert_vm_snapshots

# 需要导入模块: from marvin.lib.base import VmSnapshot [as 别名]
# 或者: from marvin.lib.base.VmSnapshot import revertToSnapshot [as 别名]
    def test_02_revert_vm_snapshots(self):
        """Test to revert VM snapshots
        """

        try:
            ssh_client = self.virtual_machine.get_ssh_client()

            cmds = [
                "rm -rf %s/%s" % (self.test_dir, self.random_data),
                "ls %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        if str(result[0]).index("No such file or directory") == -1:
            self.fail("Check the random data has be delete from temp file!")

        time.sleep(self.services["sleep"])

        list_snapshot_response = VmSnapshot.list(self.apiclient, vmid=self.virtual_machine.id, listall=True)

        self.assertEqual(
            isinstance(list_snapshot_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            list_snapshot_response,
            None,
            "Check if snapshot exists in ListSnapshot"
        )

        self.assertEqual(
            list_snapshot_response[0].state,
            "Ready",
            "Check the snapshot of vm is ready!"
        )

        VmSnapshot.revertToSnapshot(self.apiclient, list_snapshot_response[0].id)

        list_vm_response = list_virtual_machines(
            self.apiclient,
            id=self.virtual_machine.id
        )

        self.assertEqual(
            list_vm_response[0].state,
            "Stopped",
            "Check the state of vm is Stopped!"
        )

        cmd = startVirtualMachine.startVirtualMachineCmd()
        cmd.id = list_vm_response[0].id
        self.apiclient.startVirtualMachine(cmd)

        time.sleep(self.services["sleep"])

        try:
            ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)

            cmds = [
                "cat %s/%s" % (self.test_dir, self.random_data)
            ]

            for c in cmds:
                self.debug(c)
                result = ssh_client.execute(c)
                self.debug(result)

        except Exception:
            self.fail("SSH failed for Virtual machine: %s" %
                      self.virtual_machine.ipaddress)

        self.assertEqual(
            self.random_data_0,
            result[0],
            "Check the random data is equal with the ramdom file!"
        )
开发者ID:KarlHarrisSungardAS,项目名称:cloudstack,代码行数:87,代码来源:test_vm_snapshots.py

示例3: test_01_take_VM_snapshot

# 需要导入模块: from marvin.lib.base import VmSnapshot [as 别名]
# 或者: from marvin.lib.base.VmSnapshot import revertToSnapshot [as 别名]
    def test_01_take_VM_snapshot(self):
        self.virtual_machine.start(self.apiClient)

        root_volumes = list_volumes(self.apiClient, type="ROOT", listAll="true")

        self._check_list(root_volumes, 1, TestVMSnapshots._should_only_be_one_root_volume_err_msg)

        root_volume = root_volumes[0]

        volume_id = {'volumeid': root_volume.id}

        sf_iscsi_name_result = self.cs_api.getVolumeiScsiName(volume_id)
        sf_iscsi_name = sf_iscsi_name_result['apivolumeiscsiname']['volumeiScsiName']

        self._check_iscsi_name(sf_iscsi_name)

        root_volume_path_1 = self._get_path(volume_id)

        #######################################
        #######################################
        # STEP 1: Take snapshot of running VM #
        #######################################
        #######################################
        vm_snapshot = VmSnapshot.create(
            self.apiClient,
            vmid=self.virtual_machine.id,
            snapshotmemory="false",
            name="Test Snapshot",
            description="Test Snapshot Desc"
        )

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._verify_vm_snapshot(list_vm_snapshots, vm_snapshot)

        root_volume_path_2 = self._get_path(volume_id)

        self.assertEqual(
            root_volume_path_1,
            root_volume_path_2,
            TestVMSnapshots._path_should_not_have_changed_err_msg
        )

        xen_sr = self.xen_session.xenapi.SR.get_by_name_label(sf_iscsi_name)[0]

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        self._check_list(xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_create = self._get_vdis(xen_vdis)

        vdiSnapshotOf = self.xen_session.xenapi.VDI.get_record(vdis_after_create.snapshot_vdi["snapshot_of"])

        self.assertEqual(
            vdiSnapshotOf["uuid"],
            vdis_after_create.active_vdi["uuid"],
            TestVMSnapshots._snapshot_parent_not_correct_err_msg
        )

        #######################################
        #######################################
        ###  STEP 2: Revert VM to Snapshot  ###
        #######################################
        #######################################
        self.virtual_machine.stop(self.apiClient)

        VmSnapshot.revertToSnapshot(self.apiClient, vmsnapshotid=vm_snapshot.id)

        list_vm_snapshots = VmSnapshot.list(self.apiClient, listAll="true")

        self._check_list(list_vm_snapshots, 1, TestVMSnapshots._should_only_be_one_vm_snapshot_err_msg)

        root_volume_path_3 = self._get_path(volume_id)

        self.assertNotEqual(
            root_volume_path_1,
            root_volume_path_3,
            TestVMSnapshots._path_should_have_changed_err_msg
        )

        xen_vdis = self.xen_session.xenapi.SR.get_VDIs(xen_sr)

        self._check_list(xen_vdis, 3, TestVMSnapshots._should_be_three_vdis_err_msg)

        vdis_after_revert = self._get_vdis(xen_vdis)

        self.assertNotEqual(
            vdis_after_create.active_vdi["uuid"],
            vdis_after_revert.active_vdi["uuid"],
            TestVMSnapshots._active_vdis_should_not_be_the_same_err_msg
        )

        self.assertEqual(
            vdis_after_create.snapshot_vdi["uuid"],
            vdis_after_revert.snapshot_vdi["uuid"],
            TestVMSnapshots._snapshot_vdis_should_be_the_same_err_msg
        )

        self.assertEqual(
            vdis_after_create.base_vdi["uuid"],
#.........这里部分代码省略.........
开发者ID:CIETstudents,项目名称:cloudstack,代码行数:103,代码来源:TestVMSnapshots.py

示例4: test_change_service_offering_for_vm_with_snapshots

# 需要导入模块: from marvin.lib.base import VmSnapshot [as 别名]
# 或者: from marvin.lib.base.VmSnapshot import revertToSnapshot [as 别名]

#.........这里部分代码省略.........
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e))
        
        # 2) Take VM Snapshot
        self.debug("Taking VM Snapshot for VM - ID: %s" % virtual_machine.id)
        vm_snapshot = VmSnapshot.create(
            self.apiclient,
            virtual_machine.id,
        )
        
        # 3) Stop Virtual Machine
        self.debug("Stopping VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)
        
        # 4) Change service offering for VM with snapshots from Service Offering 1 to Service Offering 2
        self.debug("Changing service offering from Service Offering 1 to Service Offering 2 for VM - ID: %s" % virtual_machine.id)
        virtual_machine.change_service_offering(self.apiclient, self.service_offering_2.id)
        
        # 5) Start VM
        self.debug("Starting VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start virtual machine: %s, %s" % (virtual_machine.name, e))
        
        # Wait for vm to start
        timeout = self.wait_vm_start(self.apiclient, virtual_machine.id, self.services["timeout"],
                            self.services["sleep"])
        if timeout == 0:
            self.fail("The virtual machine %s failed to start even after %s minutes"
                   % (virtual_machine.name, self.services["timeout"]))
        
        list_vm_response = list_virtual_machines(
            self.apiclient,
            id=virtual_machine.id
        )
        self.assertEqual(
            isinstance(list_vm_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(list_vm_response),
            0,
            "Check VM avaliable in List Virtual Machines"
        )
        self.assertEqual(
            list_vm_response[0].state,
            "Running",
            "Check virtual machine is in running state"
        )
        self.assertEqual(
            list_vm_response[0].id,
            virtual_machine.id,
            "Check virtual machine id"
        )
        
        # 6) Verify service offering has changed
        try:
            ssh_client_2 = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client_2, self.service_offering_2)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e))
        
        # 7) Stop Virtual Machine
        self.debug("Stopping VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        time.sleep(30)
        # 8) Revert to VM Snapshot
        self.debug("Revert to vm snapshot: %s" % vm_snapshot.id)
        try:
            VmSnapshot.revertToSnapshot(
                self.apiclient,
                vm_snapshot.id
            )
        except Exception as e:
            self.fail("Failed to revert to VM Snapshot: %s - %s" % (vm_snapshot.id, e))
        
        # 9) Start VM
        self.debug("Starting VM - ID: %s" % virtual_machine.id)
        try:
            virtual_machine.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start virtual machine: %s, %s" % (virtual_machine.name, e))
            
        # 10) Verify service offering has changed to Service Offering 1 (from VM Snapshot)
        try:
            ssh_client_3 = virtual_machine.get_ssh_client(reconnect=True)
            self.checkCPUAndMemory(ssh_client_3, self.service_offering_1)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" % (virtual_machine.ipaddress, e))
        
        return
开发者ID:PCextreme,项目名称:cloudstack,代码行数:104,代码来源:test_vm_snapshots.py


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