Write VM to etcd
This commit is contained in:
parent
c0e6d6a0d8
commit
1b36c2f96f
5 changed files with 93 additions and 36 deletions
|
|
@ -24,34 +24,49 @@ import subprocess
|
|||
import uuid
|
||||
import os
|
||||
|
||||
class VM(object):
|
||||
def __init__(self):
|
||||
self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud"
|
||||
from uncloud.hack.db import DB
|
||||
|
||||
class VM(object):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.db = DB(config)
|
||||
|
||||
self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud"
|
||||
self.qemu="/usr/bin/qemu-system-x86_64"
|
||||
|
||||
self.vm = {}
|
||||
|
||||
self.accel="kvm"
|
||||
self.memory=1024
|
||||
self.cores=2
|
||||
self.uuid=uuid.uuid4()
|
||||
|
||||
# self.mac=$(./mac-gen.py)
|
||||
self.mac="42:00:00:00:00:42"
|
||||
self.owner="nico"
|
||||
self.bridge="br100"
|
||||
self.os_image = os.path.join(self.hackprefix, "alpine-virt-3.11.2-x86_64.iso")
|
||||
|
||||
self.ifup = os.path.join(self.hackprefix, "ifup.sh")
|
||||
self.ifdown = os.path.join(self.hackprefix, "ifdown.sh")
|
||||
|
||||
def create(self):
|
||||
p = [ "sudo",
|
||||
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.uuid),
|
||||
"-name", "uncloud-{}".format(self.vm['uuid']),
|
||||
"-machine", "pc,accel={}".format(self.accel),
|
||||
"-m", "{}".format(self.memory),
|
||||
"-smp", "{}".format(self.cores),
|
||||
"-uuid", "{}".format(self.uuid),
|
||||
"-drive", "file={},media=cdrom".format(self.os_image),
|
||||
"-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(p))
|
||||
subprocess.run(p)
|
||||
|
||||
def create(self):
|
||||
self.db.set("vm/{}".format(str(self.vm['uuid'])),
|
||||
self.vm, store_as_json=True)
|
||||
|
||||
print(" ".join(self.vm['commandline']))
|
||||
subprocess.run(self.vm['commandline'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue