small changes in vm.py to make it more generic

This commit is contained in:
Dominique Roux 2020-01-23 21:17:09 +01:00
parent d5a7f8ef59
commit 46a04048b5

View file

@ -32,27 +32,35 @@ class VM(object):
self.config = config self.config = config
self.db = DB(config, prefix="/vm") self.db = DB(config, prefix="/vm")
self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud" #TODO: Select generic
self.qemu="/usr/bin/qemu-system-x86_64" self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud" #TODO: Should be removed midterm
self.accel="kvm" self.qemu="/usr/bin/qemu-system-x86_64" #TODO: should be in config
self.accel="kvm" #TODO: should be config
self.vm = {} self.vm = {}
self.owner="nico" #TODO: this should be generic
self.bridge="br100" self.vm['owner']="nico" #TODO: Should in config.arguments
#self.config['vni_hex'] = "{:x}".format(self.config.vni)
#self.config['bridgedev'] = "br{}".format(self.config['vni_hex'])
self.vni_hex = "{:x}".format(self.config.arguments['vni'])
self.bridgedev = "br{}".format(self.vni_hex)
#TODO: Touch later! (when necessary)
self.ifup = os.path.join(self.hackprefix, "ifup.sh") self.ifup = os.path.join(self.hackprefix, "ifup.sh")
self.ifdown = os.path.join(self.hackprefix, "ifdown.sh") self.ifdown = os.path.join(self.hackprefix, "ifdown.sh")
def create(self): def create(self):
self.uuid = uuid.uuid4() self.uuid = uuid.uuid4()
#TODO: This all should be generic
self.vm['uuid'] = str(self.uuid) self.vm['uuid'] = str(self.uuid)
self.vm['memory'] = 1024 self.vm['memory'] = 1024
self.vm['cores'] = 2 self.vm['cores'] = 2
self.vm['os_image'] = os.path.join(self.hackprefix, "alpine-virt-3.11.2-x86_64.iso") self.vm['os_image'] = os.path.join(self.hackprefix, "alpine-virt-3.11.2-x86_64.iso")
self.mac=MAC().next() self.mac=MAC(self.config).get_next()
self.vm['commandline' ] = [ "sudo", self.vm['commandline' ] = [ "sudo",
"{}".format(self.qemu), "{}".format(self.qemu),
@ -62,7 +70,7 @@ class VM(object):
"-smp", "{}".format(self.vm['cores']), "-smp", "{}".format(self.vm['cores']),
"-uuid", "{}".format(self.vm['uuid']), "-uuid", "{}".format(self.vm['uuid']),
"-drive", "file={},media=cdrom".format(self.vm['os_image']), "-drive", "file={},media=cdrom".format(self.vm['os_image']),
"-netdev", "tap,id=netmain,script={},downscript={}".format(self.ifup, self.ifdown), "-netdev", "tap,id=netmain,script={},downscript={},ifname={}".format(self.ifup, self.ifdown),self.mac,
"-device", "virtio-net-pci,netdev=netmain,id=net0,mac={}".format(self.mac) "-device", "virtio-net-pci,netdev=netmain,id=net0,mac={}".format(self.mac)
] ]