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


Python InstanceManager.newInstance方法代码示例

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


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

示例1: TestInstanceManager

# 需要导入模块: from xbe.xbed.instance import InstanceManager [as 别名]
# 或者: from xbe.xbed.instance.InstanceManager import newInstance [as 别名]
class TestInstanceManager(unittest.TestCase):
    def setUp(self):
        self.mgr = InstanceManager()

    def test_spool_directory(self):
        """tests the creation of a new instance.

        Does *not* check the creation of a backend instance.

        """
        log.debug("testing creation of spool directory")
        inst = self.mgr.newInstance()

        # check if the spool directory has been created
        self.assertTrue(os.access(inst.getSpool(), os.F_OK))
        inst.cleanUp()

    def test_lookup_instance(self):
        """tests the registration of the new instance."""
        log.debug("testing instance lookup")
        # check that the instance has been registered
        inst = self.mgr.newInstance()
        
        self.assertEqual(inst, self.mgr.lookupByUUID(inst.uuid()))
        inst.cleanUp()

    def test_remove_instance(self):
        """tests the removal of an instance."""
        log.debug("testing instance removal")

        inst = self.mgr.newInstance()
        self.assertEqual(inst, self.mgr.lookupByUUID(inst.uuid()))
        self.mgr.removeInstance(inst)
        self.assertEqual(None, self.mgr.lookupByUUID(inst.uuid()))
        inst.cleanUp()

    def test_successful_instance_creation(self):
        """tests the creation of a backend instance.

        some files are required (will be staged in):
            files = { "image" : "/srv/xen-images/domains/ttylinux/disk.img",
                      "kernel": "/srv/xen-images/domains/ttylinux/kernel",
                      "initrd": "/srv/xen-images/domains/ttylinux/initrd" }
        
        """
        log.debug("testing instance creation (tiny)")

        # create new instance
        inst = self.mgr.newInstance()

        src_files = { "root" : "/srv/xen-images/domains/ttylinux/disk.img",
                      "kernel": "/srv/xen-images/domains/ttylinux/kernel",
                      "initrd": "/srv/xen-images/domains/ttylinux/initrd" }
        for name, path in src_files.iteritems():
            self.assertTrue(os.access(path, os.F_OK))
            inst.addFile("file://%s" % path, name)

        inst.start()
        state = inst.getBackendState()

        from xbe.xbed.backend import status
        self.assertTrue(state in (status.BE_INSTANCE_RUNNING, status.BE_INSTANCE_BLOCKED))

        # shut the instance down
        inst.stop()
        self.assertTrue(inst.getBackendState() in (status.BE_INSTANCE_NOSTATE, status.BE_INSTANCE_SHUTOFF))

        inst.cleanUp()

    def test_successful_instance_creation_2(self):
        """tests the creation of a backend instance.

        with networking

        some files are required (will be staged in):
            files = { "image" : "/srv/xen-images/domains/xenhobel-1/disk.img",
                      "kernel": "/srv/xen-images/domains/xenhobel-1/kernel",
                      "initrd": "/srv/xen-images/domains/xenhobel-1/initrd" }
        
        """
        log.debug("testing instance creation (big)")

        # create new instance
        inst = self.mgr.newInstance()

        src_files = { "image" : "file:///srv/xen-images/domains/xenhobel-1/disk.img",
                      "kernel": "file:///srv/xen-images/domains/xenhobel-1/kernel",
                      "initrd": "file:///srv/xen-images/domains/xenhobel-1/initrd" }
        inst.addFiles(src_files)
        inst.config.setKernel(inst.getFile("kernel"))
        inst.config.setInitrd(inst.getFile("initrd"))

        # create swap image
        disk.makeSwap(inst.getFile("swap"), 128)

        inst.config.addDisk(inst.getFile("image"), "sda1")
        inst.config.addDisk(inst.getFile("swap"), "sda2")
        inst.config.setMac("00:16:3e:00:00:01")

        inst.start()
#.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:xenbee-svn,代码行数:103,代码来源:test_instance.py


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