Exemple #1
0
	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()
Exemple #2
0
	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)
Exemple #3
0
	def _prepareDev(self):
		#assign host
		if not self.host:
			self.host = self.hostOptions().best()
			fault.check(self.host, "No matching host found")
			self.save()		
		host = self.host
		
		self._assignTemplate()
		
		self._assignBridges()
		
		if not self.getVmid():
			self.host.takeId("vmid", self.setVmid)
			fault.check(self.getVmid(), "No free vmid")
		vmid = self.getVmid()
		
		state = qm.getState(host, vmid)
		if state == State.STARTED:
			qm.stop(host, vmid)
			state = qm.getState(host, vmid)
		if state == State.PREPARED:
			qm.destroy(host, vmid)
			state = qm.getState(host, vmid)
		assert state == State.CREATED
		
		#nothing happened until here
		
		qm.create(host, vmid)
		try:
			qm.useTemplate(host, vmid, self.getTemplate())
			self._configureVm()
			for iface in self.interfaceSetAll():
				qm.addInterface(host, vmid, iface.name)
			self.state = State.PREPARED
			self.save()
		except:
			try:
				qm.destroy(host, vmid)
			except:
				pass
			raise
Exemple #4
0
	def _createIface(self, iface):
		qm.addInterface(self.host, self.getVmid(), iface.name)