Add working --last-used-mac

{'create_vm': False, 'last_used_mac': True, 'get_new_mac': False, 'debug': False, 'conf_dir': '/home/nico/uncloud', 'etcd_host': 'etcd1.ungleich.ch', 'etcd_port': None, 'etcd_ca_cert': '/home/nico/vcs/ungleich-dot-cdist/files/etcd/ca.pem', 'etcd_cert_cert': '/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico.pem', 'etcd_cert_key': '/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico-key.pem'}
00:20:00:00:00:00
(venv) [19:02] diamond:uncloud% ./bin/uncloud-run-reinstall hack  --etcd-host etcd1.ungleich.ch --etcd-ca-cert /home/nico/vcs/ungleich-dot-cdist/files/etcd/ca.pem --etcd-cert-cert /home/nico/vcs/ungleich-dot-cdist/files/etcd/nico.pem --etcd-cert-key /home/nico/vcs/ungleich-dot-cdist/files/etcd/nico-key.pem --last-used-mac
This commit is contained in:
Nico Schottelius 2020-01-14 19:02:15 +01:00
commit 8078ffae5a
4 changed files with 132 additions and 102 deletions

View file

@ -25,48 +25,50 @@ import uuid
import os
from uncloud.hack.db import DB
from uncloud.hack.mac import MAC
class VM(object):
def __init__(self, config):
self.config = config
self.db = DB(config)
def __init__(self, config):
self.config = config
self.db = DB(config, prefix="/vm")
self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud"
self.qemu="/usr/bin/qemu-system-x86_64"
self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud"
self.qemu="/usr/bin/qemu-system-x86_64"
self.accel="kvm"
self.vm = {}
self.vm = {}
self.accel="kvm"
# self.mac=$(./mac-gen.py)
self.mac="42:00:00:00:00:42"
self.owner="nico"
self.bridge="br100"
self.owner="nico"
self.bridge="br100"
self.ifup = os.path.join(self.hackprefix, "ifup.sh")
self.ifdown = os.path.join(self.hackprefix, "ifdown.sh")
self.ifup = os.path.join(self.hackprefix, "ifup.sh")
self.ifdown = os.path.join(self.hackprefix, "ifdown.sh")
self.uuid = uuid.uuid4()
self.vm['uuid'] = str(self.uuid)
self.vm['memory']=1024
self.vm['cores']=2
self.vm['os_image'] = os.path.join(self.hackprefix, "alpine-virt-3.11.2-x86_64.iso")
def create(self):
self.uuid = uuid.uuid4()
self.vm['uuid'] = str(self.uuid)
self.vm['memory'] = 1024
self.vm['cores'] = 2
self.vm['os_image'] = os.path.join(self.hackprefix, "alpine-virt-3.11.2-x86_64.iso")
self.vm['commandline' ] = [ "sudo",
"{}".format(self.qemu),
"-name", "uncloud-{}".format(self.vm['uuid']),
"-machine", "pc,accel={}".format(self.accel),
"-m", "{}".format(self.vm['memory']),
"-smp", "{}".format(self.vm['cores']),
"-uuid", "{}".format(self.vm['uuid']),
"-drive", "file={},media=cdrom".format(self.vm['os_image']),
"-netdev", "tap,id=netmain,script={},downscript={}".format(self.ifup, self.ifdown),
"-device", "virtio-net-pci,netdev=netmain,id=net0,mac={}".format(self.mac)
]
self.mac=MAC().next()
def create(self):
self.db.set("vm/{}".format(str(self.vm['uuid'])),
self.vm, store_as_json=True)
self.vm['commandline' ] = [ "sudo",
"{}".format(self.qemu),
"-name", "uncloud-{}".format(self.vm['uuid']),
"-machine", "pc,accel={}".format(self.accel),
"-m", "{}".format(self.vm['memory']),
"-smp", "{}".format(self.vm['cores']),
"-uuid", "{}".format(self.vm['uuid']),
"-drive", "file={},media=cdrom".format(self.vm['os_image']),
"-netdev", "tap,id=netmain,script={},downscript={}".format(self.ifup, self.ifdown),
"-device", "virtio-net-pci,netdev=netmain,id=net0,mac={}".format(self.mac)
]
print(" ".join(self.vm['commandline']))
subprocess.run(self.vm['commandline'])
self.db.set(str(self.vm['uuid']),
self.vm,
as_json=True)
print(" ".join(self.vm['commandline']))
subprocess.run(self.vm['commandline'])