• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python devices.Device类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tomato.devices.Device的典型用法代码示例。如果您正苦于以下问题:Python Device类的具体用法?Python Device怎么用?Python Device使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: 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()
开发者ID:david-hock,项目名称:ToMaTo,代码行数:8,代码来源:kvm.py


示例2: 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()
开发者ID:m3z,项目名称:ToMaTo,代码行数:9,代码来源:kvm.py


示例3: configure

	def configure(self, properties):
		if "template" in properties:
			fault.check(self.state == State.CREATED, "Cannot change template of prepared device: %s" % self.name)
		if "args" in properties:
			fault.check(self.state != State.STARTED, "Cannot change arguments of running device: %s" % self.name)
		Device.configure(self, properties)
		if "template" in properties:
			self.setTemplate(properties["template"])
			self._assignTemplate()
		if "args" in properties:
			self.setArgs(properties["args"])
			self._assignTemplate()
		self.save()
开发者ID:david-hock,项目名称:ToMaTo,代码行数:13,代码来源:prog.py


示例4: interfacesAdd

	def interfacesAdd(self, name, properties):
		fault.check(self.state != State.STARTED, "Repy does not support adding interfaces to running VMs: %s" % self.name)
		import re
		fault.check(re.match("eth(\d+)", name), "Invalid interface name: %s" % name)
		try:
			fault.check(not self.interfaceSetGet(name), "Duplicate interface name: %s" % name)
		except Interface.DoesNotExist: #pylint: disable-msg=W0702
			pass
		iface = Interface()
		iface.name = name
		iface.device = self
		iface.init()
		iface.save()
		Device.interfaceSetAdd(self, iface)
开发者ID:david-hock,项目名称:ToMaTo,代码行数:14,代码来源:prog.py


示例5: getStopTasks

	def getStopTasks(self):
		taskset = Device.getStopTasks(self)
		stop_vnc = tasks.Task("stop-vnc", self._stopVnc, reverseFn=self._fallbackStop)
		stop_vm = tasks.Task("stop-vm", self._stopVm, reverseFn=self._fallbackStop)
		unassign_vnc_port = tasks.Task("unassign-vnc-port", self._unassignVncPort, reverseFn=self._fallbackStop, after=stop_vnc)
		taskset.add([stop_vnc, stop_vm, unassign_vnc_port])
		return self._adaptTaskset(taskset)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:7,代码来源:openvz.py


示例6: getDestroyTasks

	def getDestroyTasks(self):
		taskset = Device.getDestroyTasks(self)
		destroy_vm = tasks.Task("destroy-vm", self._destroyVm, reverseFn=self._fallbackDestroy)
		unassign_vmid = tasks.Task("unassign-vmid", self._unassignVmid, after=destroy_vm, reverseFn=self._fallbackDestroy)
		unassign_host = tasks.Task("unassign-host", self._unassignHost, after=unassign_vmid, reverseFn=self._fallbackDestroy)
		taskset.add([destroy_vm, unassign_host, unassign_vmid])
		return self._adaptTaskset(taskset)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:7,代码来源:openvz.py


示例7: toDict

	def toDict(self, auth):
		res = Device.toDict(self, auth)
		res["attrs"].update(vmid=self.getVmid(), vnc_port=self.getVncPort(), template=self.getTemplate(),
			gateway4=self.getAttribute("gateway4"), gateway6=self.getAttribute("gateway6"))
		if auth:
			res["attrs"].update(root_password=self.getRootPassword(), vnc_password = self.vncPassword())
		return res
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:7,代码来源:openvz.py


示例8: interfacesAdd

	def interfacesAdd(self, name, properties): #@UnusedVariable, pylint: disable-msg=W0613
		fault.check(self.state != State.STARTED, "Changes of running KVMs are not supported")
		fault.check(re.match("eth(\d+)", name), "Invalid interface name: %s" % name)
		iface = Interface()
		try:
			if self.interfaceSetGet(name):
				raise fault.new("Duplicate interface name: %s" % name)
		except Interface.DoesNotExist: #pylint: disable-msg=W0702
			pass
		iface.name = name
		iface.device = self
		iface.init()
		if self.state == State.PREPARED:
			qm.addInterface(self.host, self.getVmid(), iface.name)
		iface.save()
		Device.interfaceSetAdd(self, iface)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:16,代码来源:kvm.py


示例9: interfacesAdd

	def interfacesAdd(self, name, properties):
		fault.check(self.state != State.STARTED, "OpenVZ does not support adding interfaces to running VMs: %s" % self.name)
		import re
		fault.check(re.match("eth(\d+)", name), "Invalid interface name: %s" % name)
		try:
			fault.check(not self.interfaceSetGet(name), "Duplicate interface name: %s" % name)
		except Interface.DoesNotExist: #pylint: disable-msg=W0702
			pass
		iface = ConfiguredInterface()
		iface.name = name
		iface.device = self
		iface.init()
		if self.state == State.PREPARED or self.state == State.STARTED:
			vzctl.addInterface(self.host, self.getVmid(), iface.name)
		iface.configure(properties)
		iface.save()
		Device.interfaceSetAdd(self, iface)
开发者ID:david-hock,项目名称:ToMaTo,代码行数:17,代码来源:openvz.py


示例10: getStartTasks

	def getStartTasks(self):
		taskset = Device.getStartTasks(self)
		start_vm = tasks.Task("start-vm", self._startVm, reverseFn=self._fallbackStop)
		for iface in self.interfaceSetAll():
			taskset.add(tasks.Task("start-interface-%s" % iface, self._startIface, args=(iface,), reverseFn=self._fallbackStop, after=start_vm))
		assign_vnc_port = tasks.Task("assign-vnc-port", self._assignVncPort, reverseFn=self._fallbackStop)
		start_vnc = tasks.Task("start-vnc", self._startVnc, reverseFn=self._fallbackStop, after=[start_vm, assign_vnc_port])
		taskset.add([start_vm, assign_vnc_port, start_vnc])
		return self._adaptTaskset(taskset)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:9,代码来源:kvm.py


示例11: getPrepareTasks

	def getPrepareTasks(self):
		taskset = Device.getPrepareTasks(self)
		assign_template = tasks.Task("assign-template", self._assignTemplate, reverseFn=self._fallbackDestroy)
		assign_host = tasks.Task("assign-host", self._assignHost, reverseFn=self._fallbackDestroy)
		assign_vmid = tasks.Task("assign-vmid", self._assignVmid, reverseFn=self._fallbackDestroy, after=assign_host)
		create_vm = tasks.Task("create-vm", self._createVm, reverseFn=self._fallbackDestroy, after=assign_vmid)
		configure_vm = tasks.Task("configure-vm", self._configureVm, reverseFn=self._fallbackDestroy, after=create_vm)
		create_interfaces = tasks.Task("create-interfaces", self._createInterfaces, reverseFn=self._fallbackDestroy, after=configure_vm)
		taskset.add([assign_template, assign_host, assign_vmid, create_vm, configure_vm, create_interfaces])
		return self._adaptTaskset(taskset)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:10,代码来源:openvz.py


示例12: getCapabilities

	def getCapabilities(self, user):
		capabilities = Device.getCapabilities(self, user)
		isUser = self.topology.checkAccess(Permission.ROLE_USER, user)
		capabilities["configure"].update({
			"template": self.state == State.CREATED,
			"args": self.state != State.STARTED,
		})
		capabilities.update(other={
			"console": isUser and self.getVncPort() and self.state == State.STARTED
		})
		return capabilities
开发者ID:david-hock,项目名称:ToMaTo,代码行数:11,代码来源:prog.py


示例13: getIdUsage

	def getIdUsage(self, host):
		ids = Device.getIdUsage(self, host)
		if self.vnc_port and self.host == host:
			ids["port"] = ids.get("port", set()) | set((self.vnc_port,))
		if self.vmid and self.host == host:
			ids["vmid"] = ids.get("vmid", set()) | set((self.vmid,))
		if self.hasAttribute("migration"):
			migration = self.getAttribute("migration")
			if host.name in migration:
				ids["vmid"] |= set((migration[host.name],))
		return ids
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:11,代码来源:openvz.py


示例14: getPrepareTasks

	def getPrepareTasks(self):
		taskset = Device.getPrepareTasks(self)
		assign_template = tasks.Task("assign-template", self._assignTemplate)
		assign_host = tasks.Task("assign-host", self._assignHost)
		assign_vmid = tasks.Task("assign-vmid", self._assignVmid, after=assign_host)
		create_vm = tasks.Task("create-vm", self._createVm, reverseFn=self._fallbackDestroy, after=assign_vmid)
		use_template = tasks.Task("use-template", self._useTemplate, reverseFn=self._fallbackDestroy, after=create_vm)
		configure_vm = tasks.Task("configure-vm", self._configureVm, reverseFn=self._fallbackDestroy, after=create_vm)
		for iface in self.interfaceSetAll():
			taskset.add(tasks.Task("create-interface-%s" % iface.name, self._createIface, args=(iface,), reverseFn=self._fallbackDestroy, after=create_vm))
		taskset.add([assign_template, assign_host, assign_vmid, create_vm, use_template, configure_vm])
		return self._adaptTaskset(taskset)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:12,代码来源:kvm.py


示例15: 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 "root_password" in properties:
			self.setRootPassword(properties["root_password"])
			if self.state == State.PREPARED or self.state == State.STARTED:
				vzctl.setUserPassword(self.host, self.getVmid(), self.getRootPassword(), username="root")
		if "gateway4" in properties:
			self.setAttribute("gateway4", properties["gateway4"])
			if self.state == State.STARTED:
				self._configureRoutes()
		if "gateway6" in properties:
			self.setAttribute("gateway6", properties["gateway6"])
			if self.state == State.STARTED:
				self._configureRoutes()
		if "template" in properties:
			self.setTemplate(properties["template"])
			self._assignTemplate()
			fault.check(self.getTemplate(), "Template not found: %s" % properties["template"])
		self.save()
开发者ID:david-hock,项目名称:ToMaTo,代码行数:21,代码来源:openvz.py


示例16: getStartTasks

	def getStartTasks(self):
		taskset = Device.getStartTasks(self)
		create_bridges = tasks.Task("create-bridges", self._createBridges, reverseFn=self._fallbackStop)
		start_vm = tasks.Task("start-vm", self._startVm, reverseFn=self._fallbackStop, after=create_bridges)
		check_interfaces_exist = tasks.Task("check-interfaces-exist", self._checkInterfacesExist, reverseFn=self._fallbackStop, after=start_vm)
		for iface in self.interfaceSetAll():
			ts = iface.upcast().getStartTasks()
			ts.prefix(iface).after(check_interfaces_exist)
			taskset.add(ts)
		configure_routes = tasks.Task("configure-routes", self._configureRoutes, reverseFn=self._fallbackStop, after=start_vm)
		assign_vnc_port = tasks.Task("assign-vnc-port", self._assignVncPort, reverseFn=self._fallbackStop)
		start_vnc = tasks.Task("start-vnc", self._startVnc, reverseFn=self._fallbackStop, after=[start_vm, assign_vnc_port])
		taskset.add([create_bridges, start_vm, check_interfaces_exist, configure_routes, assign_vnc_port, start_vnc])
		return self._adaptTaskset(taskset)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:14,代码来源:openvz.py


示例17: configure

	def configure(self, properties):
		#FIXME: default route does not work
		if "template" in properties:
			fault.check(self.state == State.CREATED, "Cannot change template of prepared device: %s" % self.name)
		Device.configure(self, properties)
		if "root_password" in properties:
			self.setRootPassword(properties["root_password"])
			if self.state == State.PREPARED or self.state == State.STARTED:
				vzctl.setUserPassword(self.host, self.getVmid(), self.getRootPassword(), username="root")
		if "gateway4" in properties:
			self.setAttribute("gateway4", properties["gateway4"])
			if self.getAttribute("gateway4") and self.state == State.STARTED:
				#Note: usage of self as host is intentional
				ifaceutil.setDefaultRoute(self, self.getAttribute("gateway4"))
		if "gateway6" in properties:
			self.setAttribute("gateway6", properties["gateway6"])
			if self.getAttribute("gateway6") and self.state == State.STARTED:
				#Note: usage of self as host is intentional
				ifaceutil.setDefaultRoute(self, self.getAttribute("gateway6"))
		if "template" in properties:
			self.setTemplate(properties["template"])
			self._assignTemplate()
			fault.check(self.getTemplate(), "Template not found: %s" % properties["template"])
		self.save()
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:24,代码来源:openvz.py


示例18: getCapabilities

	def getCapabilities(self, user):
		capabilities = Device.getCapabilities(self, user)
		isUser = self.topology.checkAccess(Permission.ROLE_USER, user)
		capabilities["configure"].update({
			"template": self.state == State.CREATED,
			"root_password": True,
			"gateway4": True,
			"gateway6": True,
		})
		capabilities["action"].update({
			"execute": isUser and self.state == State.STARTED,
		})
		capabilities.update(other={
			"console": isUser and self.getVncPort() and self.state == State.STARTED
		})
		return capabilities
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:16,代码来源:openvz.py


示例19: _runAction

	def _runAction(self, action, attrs, direct):
		if action == "execute":
			return self.execute(attrs["cmd"])
		else:
			return Device._runAction(self, action, attrs, direct)
开发者ID:joanmarkt,项目名称:ToMaTo,代码行数:5,代码来源:openvz.py


示例20: toDict

	def toDict(self, auth):
		res = Device.toDict(self, auth)
		res["attrs"].update(template=self.getConfiguredTemplate())
		if auth:
			res["attrs"].update(vnc_password=self.vncPassword(), vnc_port=self.getVncPort())
		return res
开发者ID:m3z,项目名称:ToMaTo,代码行数:6,代码来源:kvm.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python fault.check函数代码示例发布时间:2022-05-27
下一篇:
Python util.getCountry函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap