Esempio n. 1
0
	def _createBridges(self):
		for iface in self.interfaceSetAll():
			if iface.isConnected():
				bridge = self.getBridge(iface)
				assert bridge, "Interface has no bridge %s" % iface
				ifaceutil.bridgeCreate(self.host, bridge)
				ifaceutil.ifup(self.host, bridge)
Esempio n. 2
0
	def _startDev(self):
		host = self.host
		vmid = self.id
		state = repy.getState(host, vmid)
		if not self.getVncPort():
			self.host.takeId("port", self.setVncPort)
		if state == State.CREATED:
			self._prepareDev()
			state = repy.getState(host, vmid)
		for iface in self.interfaceSetAll():
			bridge = self.getBridge(iface)
			assert bridge, "Interface has no bridge %s" % iface
			ifaceutil.bridgeCreate(self.host, bridge)
			ifaceutil.ifup(self.host, bridge)
		try: 
			if state == State.PREPARED:
				ifaces = [iface.name for iface in self.interfaceSetAll()]
				repy.start(host, vmid, ifaces, self.getArgs())
			for iface in self.interfaceSetAll():
				repy.waitForInterface(self.host, self.id, iface.name)
				ifaceutil.ifup(self.host, self.interfaceDevice(iface))
				self.connectToBridge(iface, self.getBridge(iface))
			self._startVnc()
			self.state = State.STARTED
			self.save()
		except:
			try:
				repy.stop(host, vmid)
			except:
				pass
			raise
Esempio n. 3
0
File: openvz.py Progetto: m3z/ToMaTo
	def _startDev(self):
		host = self.host
		vmid = self.getVmid()
		state = vzctl.getState(host, vmid)
		if state == State.CREATED:
			self._prepareDev()
			state = vzctl.getState(host, vmid)
		for iface in self.interfaceSetAll():
			bridge = self.getBridge(iface)
			assert bridge, "Interface has no bridge %s" % iface
			ifaceutil.bridgeCreate(self.host, bridge)
			ifaceutil.ifup(self.host, bridge)
		try: 
			if state == State.PREPARED:
				vzctl.start(host, vmid)
			for iface in self.interfaceSetAll():
				assert util.waitFor(lambda: ifaceutil.interfaceExists(host, self.interfaceDevice(iface)))
				self.connectToBridge(iface, self.getBridge(iface))
				iface.upcast()._configureNetwork()
			self._startVnc()
			self.state = State.STARTED
			self.save()
		except:
			try:
				vzctl.stop(host, vmid)
			except:
				pass
			raise
Esempio n. 4
0
 def _configLink(self):
     host = self.getHost()
     iface = self.internalInterface()
     self._assignIfb()
     assert self.hasIfbId()
     ifb = "ifb%d" % self.getIfbId()
     ifaceutil.ifup(host, ifb)
     tc.setLinkEmulation(
         host,
         iface,
         bandwidth=float(self.getNetemProp("bandwidth", "to")),
         delay=float(self.getNetemProp("delay", "to")),
         jitter=float(self.getNetemProp("jitter", "to")),
         delay_correlation=float(self.getNetemProp("delay_correlation", "to")),
         distribution=self.getNetemProp("distribution", "to"),
         loss=float(self.getNetemProp("lossratio", "to")),
         loss_correlation=float(self.getNetemProp("lossratio_correlation", "to")),
         duplicate=float(self.getNetemProp("duplicate", "to")),
         corrupt=float(self.getNetemProp("corrupt", "to")),
     )
     tc.setLinkEmulation(
         host,
         ifb,
         bandwidth=float(self.getNetemProp("bandwidth", "from")),
         delay=float(self.getNetemProp("delay", "from")),
         jitter=float(self.getNetemProp("jitter", "from")),
         delay_correlation=float(self.getNetemProp("delay_correlation", "from")),
         distribution=self.getNetemProp("distribution", "from"),
         loss=float(self.getNetemProp("lossratio", "from")),
         loss_correlation=float(self.getNetemProp("lossratio_correlation", "from")),
         duplicate=float(self.getNetemProp("duplicate", "from")),
         corrupt=float(self.getNetemProp("corrupt", "from")),
     )
     tc.setIncomingRedirect(host, iface, ifb)
Esempio n. 5
0
	def _configLink(self):
		host = self.getHost()
		iface = self.internalInterface()
		assert not self.getAttribute("ifb_id", None) is None
		ifb = "ifb%d" % self.getAttribute("ifb_id", None)
		ifaceutil.ifup(host, ifb)
		tc.setLinkEmulation(host, iface, 
			bandwidth=self.getNetemProp("bandwidth", "to"),
			delay=self.getNetemProp("delay", "to"),
			jitter=self.getNetemProp("jitter", "to"),
			delay_correlation=self.getNetemProp("delay_correlation", "to"),
			distribution=self.getNetemProp("distribution", "to"),
			loss=self.getNetemProp("lossratio", "to"),
			loss_correlation=self.getNetemProp("lossratio_correlation", "to"),
			duplicate=self.getNetemProp("duplicate", "to"),
			corrupt=self.getNetemProp("corrupt", "to"),
		)
		tc.setLinkEmulation(host, ifb,
			bandwidth=self.getNetemProp("bandwidth", "from"),
			delay=self.getNetemProp("delay", "from"),
			jitter=self.getNetemProp("jitter", "from"),
			delay_correlation=self.getNetemProp("delay_correlation", "from"),
			distribution=self.getNetemProp("distribution", "from"),
			loss=self.getNetemProp("lossratio", "from"),
			loss_correlation=self.getNetemProp("lossratio_correlation", "from"),
			duplicate=self.getNetemProp("duplicate", "from"),
			corrupt=self.getNetemProp("corrupt", "from"),
		)
		tc.setIncomingRedirect(host, iface, ifb)
Esempio n. 6
0
	def connectToBridge(self):
		dev = self.device.upcast()
		bridge = dev.getBridge(self)
		if self.isConnected():
			if not ifaceutil.bridgeExists(dev.host, bridge):
				ifaceutil.bridgeCreate(dev.host, bridge)
			ifaceutil.bridgeConnect(dev.host, bridge, self.interfaceName())
			ifaceutil.ifup(dev.host, self.interfaceName())
Esempio n. 7
0
	def _configureNetwork(self):
		dev = self.device.upcast()
		#Note usage of dev instead of host is intentional
		if self.hasAttribute("ip4address"):
			ifaceutil.addAddress(dev, self.name, self.getAttribute("ip4address"))
			ifaceutil.ifup(dev, self.name) 
		if self.hasAttribute("ip6address"):
			ifaceutil.addAddress(dev, self.name, self.getAttribute("ip6address"))
			ifaceutil.ifup(dev, self.name) 
		if self.hasAttribute("use_dhcp") and util.parse_bool(self.getAttribute("use_dhcp")):
			ifaceutil.startDhcp(dev, self.name)
Esempio n. 8
0
	def connectToBridge(self, iface, bridge):
		ifaceutil.bridgeCreate(self.host, bridge)
		ifaceutil.bridgeConnect(self.host, bridge, self.interfaceDevice(iface))
		ifaceutil.ifup(self.host, bridge)