當前位置: 首頁>>代碼示例>>Python>>正文


Python devices.Device類代碼示例

本文整理匯總了Python中tomato.devices.Device的典型用法代碼示例。如果您正苦於以下問題:Python Device類的具體用法?Python Device怎麽用?Python Device使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Device類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的tomato.devices.Device類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。