Beispiel #1
0
def _stopEndpoint(endpoint):
	assert getState(endpoint) != generic.State.CREATED
	host = endpoint.getHost()
	assert host
	host.execute("tincd --net=%s -k" % _tincName(endpoint))
	util.waitFor(lambda :getState(endpoint) == generic.State.PREPARED, 5.0)
	assert getState(endpoint) == generic.State.PREPARED
Beispiel #2
0
def start(host, vmid):
	assert getState(host, vmid) == generic.State.PREPARED, "VM already running"
	res = _vzctl(host, vmid, "start", timeout=300)
	util.waitFor (lambda :getState(host, vmid) == generic.State.STARTED)
	if getState(host, vmid) != generic.State.STARTED:
		raise Exception("Failed to start VM: %s" % res)
	execute(host, vmid, "while fgrep -q boot /proc/1/cmdline; do sleep 1; done")
Beispiel #3
0
def start(host, port):
	assert host
	assert process.portFree(host, port)
	host.execute("vtund -s -f %s" % _configPath(port))
	util.waitFor(lambda :fileutil.existsFile(host, "/var/run/vtund.server.pid"), 5.0)
	assert fileutil.existsFile(host, "/var/run/vtund.server.pid")
	fileutil.copy(host, "/var/run/vtund.server.pid", _pidFile(port))
Beispiel #4
0
def start(host, vmid):
	assert getState(host, vmid) == generic.State.PREPARED, "VM already running"
	res = _vzctl(host, vmid, "start")
	util.waitFor (lambda :getState(host, vmid) == generic.State.STARTED)
	assert getState(host, vmid) == generic.State.STARTED, "OpenVZ device failed to start: %s" % res

	assert getState(host, vmid) == generic.State.STARTED, "Failed to start VM: %s" % res
	execute(host, vmid, "while fgrep -q boot /proc/1/cmdline; do sleep 1; done")
Beispiel #5
0
def _startEndpoint(endpoint):
	assert getState(endpoint) == generic.State.PREPARED
	host = endpoint.getHost()
	assert host
	assert process.portFree(host, endpoint.getPort())
	iface = _tincName(endpoint)
	host.execute("tincd --net=%s" % iface )
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)
Beispiel #6
0
def _startEndpoint(endpoint):
	state = getState(endpoint)
	assert state != generic.State.CREATED
	if state == generic.State.STARTED:
		_stopEndpoint(endpoint)
	host = endpoint.getHost()
	assert host
	if not process.portFree(host, endpoint.getPort()):
		process.killPortUser(host, endpoint.getPort())
	iface = _tincName(endpoint)
	host.execute("tincd --net=%s" % iface )
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)
Beispiel #7
0
def _setupRouting(endpoint):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	id = endpoint.getId()
	assert id
	assert ifaceutil.bridgeExists(host, bridge)
	tincname = _tincName(endpoint)
	assert ifaceutil.interfaceExists(host, tincname)
	assert not ifaceutil.interfaceBridge(host, tincname)
	#enable ip forwarding
	host.execute ("sysctl -q -w net.ipv6.conf.all.forwarding=1");
	host.execute ("sysctl -q -w net.ipv4.conf.all.forwarding=1");
	#add gateway addresses
	for gw in endpoint.getGateways():
		ifaceutil.addAddress(host, bridge, gw)
	#set bridge up
	ifaceutil.ifup(host, bridge)
	ifaceutil.connectInterfaces(host, bridge, tincname, id, endpoint.getGateways())
	for gw in endpoint.getGateways():
		ip = gw.split("/")[0]
		util.waitFor(lambda :ifaceutil.reachable(host, ip, iface=bridge))
		assert ifaceutil.reachable(host, ip, iface=bridge), "Cannot reach %s in interface %s" % (ip, bridge)
Beispiel #8
0
def waitForInterface(host, vmid, iface):
	util.waitFor(lambda :ifaceutil.interfaceExists(host, interfaceDevice(vmid, iface)), maxWait=2)
	assert ifaceutil.interfaceExists(host, interfaceDevice(vmid, iface)), "Interface does not exist"
Beispiel #9
0
def startVnc(host, vmid, port, password):
	assert getState(host, vmid) == generic.State.STARTED, "VM must be running to start vnc"
	if not process.portFree(host, port):
		process.killPortUser(host, port)
	host.execute("vncterm -timeout 0 -rfbport %d -passwd %s -c vzctl enter %d >/dev/null 2>&1 & echo $! > %s" % ( port, util.escape(password), vmid, _vncPidfile(vmid) ))		
	assert util.waitFor(lambda :not process.portFree(host, port))
Beispiel #10
0
def stop(host, port):
	assert getState(host, port) != generic.State.CREATED
	assert host
	process.killPidfile(host, _pidFile(port))
	util.waitFor(lambda :getState(host, port) == generic.State.PREPARED, 5.0)
	assert getState(host, port) == generic.State.PREPARED
Beispiel #11
0
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)

def _stopEndpoint(endpoint):
	state = getState(endpoint)
	if state != generic.State.STARTED:
		return
	host = endpoint.getHost()
	assert host
	try:
		host.execute("tincd --net=%s -k" % _tincName(endpoint))
	except exceptions.CommandError, exc:
		if exc.errorCode != 1: #tincd was not running
			raise
	util.waitFor(lambda :getState(endpoint) != generic.State.STARTED, 5.0)
	assert getState(endpoint) != generic.State.STARTED

def _setupRouting(endpoint):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	id = endpoint.getId()
	assert id
	assert ifaceutil.bridgeExists(host, bridge)
	tincname = _tincName(endpoint)
	assert ifaceutil.interfaceExists(host, tincname)
	assert not ifaceutil.interfaceBridge(host, tincname)
	#enable ip forwarding
	host.execute ("sysctl -q -w net.ipv6.conf.all.forwarding=1");
Beispiel #12
0
def startVnc(host, vmid, port, password):
	assert getState(host, vmid) == generic.State.STARTED, "VM must be running to start vnc"
	assert process.portFree(host, port)
	host.execute("vncterm -timeout 0 -rfbport %d -passwd %s -c tail -n +1 -f %s >/dev/null 2>&1 & echo $! > %s" % ( port, util.escape(password), _logFile(vmid), _vncPidFile(vmid) ))
	assert util.waitFor(lambda :not process.portFree(host, port))