本文整理汇总了Python中xbe.xbed.instance.InstanceManager类的典型用法代码示例。如果您正苦于以下问题:Python InstanceManager类的具体用法?Python InstanceManager怎么用?Python InstanceManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InstanceManager类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __prepare
def __prepare(self):
self.log.debug("initiating preparation")
# create the spool directory
self.__spool = self.__createSpool()
# create the instance
self.__inst = InstanceManager.getInstance().newInstance(self.__spool)
self.__inst.task = self
from xbe.xbed.task_activities import SetUpActivity, AcquireResourceActivity
from xbe.util.activity import ComplexActivity, ThreadedActivity
mac_pool = XBEDaemon.getInstance().macAddresses
jail_package = XBEDaemon.getInstance().opts.jail_package
mac_acquirer = ThreadedActivity(
AcquireResourceActivity(mac_pool))
setup_activity = ThreadedActivity(
SetUpActivity(self.__spool, jail_package), (self.__jsdl_doc, self.__activity_logs["stage-in"]))
complex_activity = ComplexActivity([setup_activity, mac_acquirer])
self.mgr.registerActivity(self, complex_activity,
on_finish=self._cb_stage_in_succeed,
on_fail=self._eb_stage_in_failed,
on_abort=None)
示例2: do_InstanceAlive
def do_InstanceAlive(self, xml, *a, **kw):
msg = message.MessageBuilder.from_xml(xml.getroottree())
inst_id = msg.inst_id()
inst = InstanceManager.getInstance().lookupByUUID(msg.inst_id())
if inst is not None:
inst.update_alive()
else:
log.warn("got alive message from suspicious source")
示例3: do_life_sign
def do_life_sign(self, life_sign):
self.log.debug("instance %s is alive", self._instanceID)
inst = InstanceManager.getInstance().lookupByUUID(self._instanceID)
if inst is not None:
inst.life_sign(self, life_sign)
else:
self.log.warn("unknown instance: %s", self._instanceID)
self.requestShutdown(None, None)
示例4: do_InstanceAvailable
def do_InstanceAvailable(self, xml, *args, **kw):
inst_avail = message.MessageBuilder.from_xml(xml.getroottree())
inst_id = inst_avail.inst_id()
inst = InstanceManager.getInstance().lookupByUUID(inst_id)
if inst is not None:
inst.available(self)
else:
log.warn("got available message from suspicious source")
示例5: do_ExecutionFailed
def do_ExecutionFailed(self, xml, *a, **kw):
msg = message.MessageBuilder.from_xml(xml.getroottree())
inst_id = msg.inst_id()
inst = InstanceManager.getInstance().lookupByUUID(inst_id)
if inst is not None:
log.debug("execution on instance %s failed: %s" % (inst_id, msg.reason()))
try:
inst.task.signalExecutionFailed(Exception("execution failed", msg))
except Exception, e:
log.warn("could not signal execution failure: %s" % e)
示例6: do_InstanceShuttingDown
def do_InstanceShuttingDown(self, xml, *a, **kw):
msg = message.MessageBuilder.from_xml(xml.getroottree())
inst_id = msg.inst_id()
inst = InstanceManager.getInstance().lookupByUUID(inst_id)
if inst is not None:
log.info("instance is shutting down...")
log.debug("execution on instance %s finished" % inst_id)
try:
inst.task.signalExecutionEnd(0)
except Exception, e:
log.warn("could not signal execution end: %s" % e)
示例7: do_ExecutionFinished
def do_ExecutionFinished(self, xml, *args, **kw):
msg = message.MessageBuilder.from_xml(xml.getroottree())
inst_id = msg.inst_id()
exitcode = msg.exitcode()
inst = InstanceManager.getInstance().lookupByUUID(inst_id)
if inst is not None:
log.debug("execution on instance %s finished" % inst_id)
try:
inst.task.signalExecutionEnd(exitcode)
except Exception, e:
log.warn("could not signal execution end: %s" % e)
示例8: do_failed
def do_failed(self, failed):
self.log.info("execution on instance has failed: %d", failed.reason)
# send a failed ack to the instance
ack = xbemsg.XbeMessage()
ack.header.conversation_id = self._conv_id
ack.failed_ack.task = failed.task
inst = InstanceManager.getInstance().lookupByUUID(self._instanceID)
if inst is not None:
inst.task.signalExecutionFailed(failed.reason)
return ack
示例9: setUp
def setUp(self):
self.mgr = InstanceManager()
示例10: TestInstanceManager
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()
#.........这里部分代码省略.........
示例11: __delete_instance
def __delete_instance(self, *a, **kw):
InstanceManager.getInstance().removeInstance(self.__inst)
del self.__inst.task
del self.__inst
示例12: do_status
def do_status(self, status):
self.log.info("received status information: %s", status)
inst = InstanceManager.getInstance().lookupByUUID(self._instanceID)
if inst is not None:
inst.task.signalStatus(status)