本文整理汇总了Python中tomato.fault.check函数的典型用法代码示例。如果您正苦于以下问题:Python check函数的具体用法?Python check怎么用?Python check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _runAction
def _runAction(self, action, attrs, direct):
if action == "execute":
fault.check("cmd" in attrs, "Command not given")
try:
return self.execute(attrs["cmd"])
except exceptions.CommandError, exc:
raise fault.new(str(exc), fault.USER_ERROR)
示例2: interfacesRename
def interfacesRename(self, name, properties): #@UnusedVariable, pylint: disable-msg=W0613
fault.check(self.state != State.STARTED, "Changes of running KVMs are not supported")
iface = self.interfaceSetGet(name)
newName = properties["name"]
fault.check(re.match("eth(\d+)", newName), "Invalid interface name: %s" % name)
try:
if self.interfaceSetGet(newName):
raise fault.new("Duplicate interface name: %s" % newName, fault.USER_ERROR)
except Interface.DoesNotExist: #pylint: disable-msg=W0702
pass
if self.state == State.PREPARED:
connector = None
connectionAttributes = None
if iface.isConnected():
connector = iface.connection.connector
connectionAttributes = iface.connection.upcast().toDict(None)["attrs"]
connector.upcast().connectionsDelete(unicode(iface))
qm.deleteInterface(self.host, self.getVmid(), iface.name)
iface.name = newName
iface.save()
if self.state == State.PREPARED:
qm.addInterface(self.host, self.getVmid(), iface.name)
if connector:
connector.upcast().connectionsAdd(unicode(iface), connectionAttributes)
self.save()
示例3: stop
def stop(self, direct, noProcess=False):
fault.check(self.state != State.CREATED, "Connector must be started or prepared to be stopped but is %s: %s", (self.state, self.name))
proc = tasks.Process("stop")
proc.add(tasks.Task("renew", self.topology.renew))
proc.add(self.upcast().getStopTasks())
if noProcess:
return proc.start(direct)
return self.topology.startProcess(proc, direct)
示例4: configure
def configure(self, properties):
if self.state != State.CREATED:
fault.check(not "network_type" in properties, "Cannot change type of external network with prepared connections: %s", self.name)
fault.check(not "network_group" in properties, "Cannot change group of external network with prepared connections: %s", self.name)
Connector.configure(self, properties)
if self.getNetworkGroup() == "auto":
self.setNetworkGroup(None)
self.save()
示例5: checkImage
def checkImage(host, path):
assert host
assert fileutil.existsFile(host, path)
try:
res = host.execute("tar -tzvf %s ./sbin/init" % util.escape(path))
fault.check("0/0" in res, "Image contents not owned by root")
except exceptions.CommandError, err:
return err.errorMessage
示例6: destroy
def destroy(self, direct, noProcess=False):
fault.check(self.state != State.STARTED, "Connector must not be started to be destroyed but is %s: %s", (self.state, self.name))
proc = tasks.Process("destroy")
proc.add(tasks.Task("renew", self.topology.renew))
proc.add(self.upcast().getDestroyTasks())
if noProcess:
return proc.start(direct)
return self.topology.startProcess(proc, direct)
示例7: interfacesDelete
def interfacesDelete(self, name): #@UnusedVariable, pylint: disable-msg=W0613
fault.check(self.state != State.STARTED, "Changes of running KVMs are not supported")
iface = self.interfaceSetGet(name)
if iface.isConnected():
iface.connection.connector.upcast().connectionsDelete(unicode(iface))
if self.state == State.PREPARED:
qm.deleteInterface(self.host, self.getVmid(), iface.name)
iface.delete()
示例8: connectionsAdd
def connectionsAdd(self, iface_name, properties): #@UnusedVariable, pylint: disable-msg=W0613
iface = self.topology.interfacesGet(iface_name)
fault.check(iface.device.state != State.STARTED, "Cannot add connections to running device: %s -> %s", (iface_name, self.name) )
con = Connection ()
con.connector = self
con.interface = iface
con.init()
con.save()
示例9: configure
def configure(self, properties):
if "template" in properties:
fault.check(self.state == State.CREATED, "Cannot change template of prepared device: %s" % self.name)
Device.configure(self, properties)
if "template" in properties:
self.setTemplate(properties["template"])
self._assignTemplate()
self.save()
示例10: interfacesRename
def interfacesRename(self, name, properties):
iface = self.interfaceSetGet(name).upcast()
try:
fault.check(not self.interfaceSetGet(properties["name"]), "Duplicate interface name: %s" % properties["name"])
except Interface.DoesNotExist: #pylint: disable-msg=W0702
pass
iface.name = properties["name"]
iface.save()
示例11: _runAction
def _runAction(self, action, attrs, direct):
if action == "download_capture":
interface = self.topology.interfacesGet(attrs["iface"])
fault.check(interface, "No such interface: %s", attrs["iface"])
con = interface.connection.upcast()
assert con.connector.id == self.id
return con.downloadCaptureUri()
else:
return Connector._runAction(self, action, attrs, direct)
示例12: configure
def configure(self, properties):
if "template" in properties:
fault.check(self.state != State.STARTED, "Cannot change template of running device: %s" % self.name)
Device.configure(self, properties)
if "template" in properties:
self.setTemplate(properties["template"])
if self.state == State.PREPARED:
qm.useTemplate(self.host, self.getVmid(), self.getTemplate())
self.save()
示例13: _runAction
def _runAction(self, action, attrs, direct):
if action == "download_capture":
interface = self.topology.interfacesGet(attrs["iface"])
fault.check(interface, "No such interface: %s", attrs["iface"])
con = interface.connection.upcast()
assert con.connector.id == self.id
return tasks.runTask(tasks.Task("%s-download-capture-uri" % self, con.downloadCaptureUri, kwargs={"onlyLatest": "onlyLatest" in attrs and attrs["onlyLatest"]}))
else:
return Connector._runAction(self, action, attrs, direct)
示例14: _assignVtunData
def _assignVtunData(self):
host = None
for con in self.connectionSetAll():
if con.interface.device.host:
host = con.interface.device.host
break
fault.check(host, "Failed to assign a host for external access")
if not self.getExternalAccessPort():
self.external_access_port = resources.take(host, "port", self, self.EXTERNAL_ACCESS_PORT_SLOT)
self.save()
示例15: prepare
def prepare(self, direct, noProcess=False):
fault.check(self.state == State.CREATED, "Connector must be created to be prepared but is %s: %s", (self.state, self.name))
for con in self.connectionSetAll():
dev = con.interface.device
fault.check(dev.state != State.CREATED, "Device %s must be prepared before connector %s", (dev.name, self.name))
proc = tasks.Process("prepare")
proc.add(tasks.Task("renew", self.topology.renew))
proc.add(self.upcast().getPrepareTasks())
if noProcess:
return proc.start(direct)
return self.topology.startProcess(proc, direct)