diff --git a/uncloud/hack/hackcloud/vm.py b/uncloud/hack/hackcloud/vm.py
deleted file mode 100755
index 9dd80bf..0000000
--- a/uncloud/hack/hackcloud/vm.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-#
-# 2020 Nico Schottelius (nico.schottelius at ungleich.ch)
-#
-# This file is part of uncloud.
-#
-# uncloud is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# uncloud is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with uncloud. If not, see .
-#
-#
-
-import subprocess
-import uuid
-
-from . import db
-
-qemu="/usr/bin/qemu-system-x86_64"
-accel="kvm"
-memory=1024
-cores=2
-uuid=uuid.uuid4()
-
-#mac=$(./mac-gen.py)
-mac=""
-
-owner="nico"
-
-bridge="br100"
-
-if __name__ == '__main__':
- p = ["qemu",
- "-name", "uncloud-{}".format(uuid),
- "-machine", "pc,accel={}".format(accel),
- "-m", "{}".format(memory),
- "-smp", "{}".format(cores),
- "-uuid", "{}".format(uuid),
- "-drive", "file=alpine-virt-3.11.2-x86_64.iso,media=cdrom",
- "-netdev", "tap,id=netmain,script=./ifup.sh,downscript=./ifdown.sh",
- "-device", "virtio-net-pci,netdev=netmain,id=net0,mac={}".format(mac)
- ]
- print(" ".join(p))
- subprocess.run(p)
diff --git a/uncloud/hack/main.py b/uncloud/hack/main.py
index 2ce19da..4baed98 100644
--- a/uncloud/hack/main.py
+++ b/uncloud/hack/main.py
@@ -1,10 +1,17 @@
import argparse
+from uncloud.hack.vm import VM
+
arg_parser = argparse.ArgumentParser('hack', add_help=False)
-arg_parser.add_argument('--create-vm')
+arg_parser.add_argument('--create-vm', action='store_true')
def main(arguments):
print(arguments)
+ if arguments['create_vm']:
+ print("Creating VM")
+ vm = VM()
+ vm.create()
+
#debug = arguments['debug']
#port = arguments['port']
diff --git a/uncloud/hack/vm.py b/uncloud/hack/vm.py
new file mode 100755
index 0000000..988ea2b
--- /dev/null
+++ b/uncloud/hack/vm.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# 2020 Nico Schottelius (nico.schottelius at ungleich.ch)
+#
+# This file is part of uncloud.
+#
+# uncloud is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# uncloud is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with uncloud. If not, see .
+#
+#
+
+import subprocess
+import uuid
+import os
+
+class VM(object):
+ def __init__(self):
+ self.hackprefix="/home/nico/vcs/uncloud/uncloud/hack/hackcloud"
+
+ self.qemu="/usr/bin/qemu-system-x86_64"
+ 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",
+ "{}".format(self.qemu),
+ "-name", "uncloud-{}".format(self.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),
+ "-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)