add busybox udhcps functionality

This commit is contained in:
2013-08-16 04:08:36 +02:00
parent 0709f0d7bf
commit b8c240b824
3 changed files with 210 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import time
import sys
import pwd
from qmp import QEMUMonitorProtocol
from VMdhcpd import VMdhcpd
class VMHelper:
def __init__(self, filename):
@@ -94,6 +95,10 @@ class VMHelper:
cmd.append("-qmp")
cmd.append("unix:" + self.config['kvm']['qmpsocket'].replace("$VMID", vmid) + ",server,nowait")
if "runas" in self.config["kvm"]:
cmd.append("-runas")
cmd.append(self.config["kvm"]["runas"])
cmd += ["-name", vmid]
default_args = self.config['kvm']['default_args'].replace("$VMID", vmid)
@@ -244,8 +249,12 @@ class VMHelper:
commands.append(["ip6tables", "-A", "FORWARD", "-j", chain])
for cmd in commands:
subprocess.call(cmd, stdout=open("/dev/null"))
subprocess.call(cmd, stdout=open("/dev/null")
)
VMdhcpd(vmid, self.config).start()
def teardownNetwork(self, vmid):
if ('VMs' in self.config) and (vmid in self.config['VMs']):
config = self.config['VMs'][vmid]
@@ -271,6 +280,8 @@ class VMHelper:
for cmd in commands:
subprocess.call(cmd, stdout=open("/dev/null"))
VMdhcpd(vmid, self.config).stop()
def generateAuthorizedKeys(self):
userkeys = {}
keydir = os.path.join(self.config["ssh"]["homedir"], self.config["ssh"]["keydir"])
@@ -279,12 +290,17 @@ class VMHelper:
if len(fnsplit) == 2:
user = fnsplit[0]
with open(os.path.join(keydir,filename)) as f:
userkeys[user] = userkeys[user].append(f.readline().rstrip('\n')) if user in userkeys else [f.readline().rstrip('\n')]
keystring = f.readline().rstrip('\n')
if user in userkeys:
userkeys[user].append(keystring)
else:
userkeys[user] = [keystring]
authorized_keys = ""
for user, keys in userkeys.items():
prepend = 'no-agent-forwarding,no-user-rc,no-X11-forwarding,command="read",'
for vm, vals in self.config["VMs"].items():
if vals["owner"] in userkeys:
if vals["owner"] == user:
prepend += 'permitopen="localhost:{0}",'.format(vals["vnc"]["display"] + 5900)
prepend += 'permitopen="127.0.0.1:{0}",'.format(vals["vnc"]["display"] + 5900)
prepend += 'permitopen="[::1]:{0}",'.format(vals["vnc"]["display"] + 5900)