Begin to integrate hack into the main script

This commit is contained in:
Nico Schottelius 2020-01-14 11:05:42 +01:00
parent 9f02b31b1b
commit b96e56b453
7 changed files with 117 additions and 11 deletions

View file

@ -22,7 +22,8 @@ def exception_hook(exc_type, exc_value, exc_traceback):
sys.excepthook = exception_hook sys.excepthook = exception_hook
# the components that use etcd # the components that use etcd
ETCD_COMPONENTS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata', 'configure'] ETCD_COMPONENTS = ['api', 'scheduler', 'host', 'filescanner',
'imagescanner', 'metadata', 'configure', 'hack']
ALL_COMPONENTS = ETCD_COMPONENTS.copy() ALL_COMPONENTS = ETCD_COMPONENTS.copy()
ALL_COMPONENTS.append('cli') ALL_COMPONENTS.append('cli')

0
uncloud/hack/__init__.py Normal file
View file

View file

@ -0,0 +1 @@

View file

@ -1,17 +1,52 @@
#!/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 <http://www.gnu.org/licenses/>.
#
#
import etcd3 import etcd3
class DB(object):
def __init__(self, urls):
self.urls = urls
self.prefix = "/nicohack/"
def connect(self):
self.clients = []
for endpoint in self.urls:
client = etcd3.client(host=endpoint,
ca_cert="/home/nico/vcs/ungleich-dot-cdist/files/etcd/ca.pem",
cert_cert="/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico.pem",
cert_key="/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico-key.pem")
clients.append(client)
def get_value(self, key):
pass
def set_value(self, key, val):
pass
if __name__ == '__main__': if __name__ == '__main__':
endpoints = [ "https://etcd1.ungleich.ch:2379", endpoints = [ "https://etcd1.ungleich.ch:2379",
"!https://etcd2.ungleich.ch:2379", "https://etcd2.ungleich.ch:2379",
"https://etcd3.ungleich.ch:2379" ] "https://etcd3.ungleich.ch:2379" ]
clients = [] db = DB(url=endpoints)
for endpoint in endpoints:
client = etcd3.client(host=endpoint,
ca_cert="/home/nico/vcs/ungleich-dot-cdist/files/etcd/ca.pem",
cert_cert="/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico.pem",
cert_key="/home/nico/vcs/ungleich-dot-cdist/files/etcd/nico-key.pem")
clients.append(client)

53
uncloud/hack/hackcloud/vm.py Executable file
View file

@ -0,0 +1,53 @@
#!/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 <http://www.gnu.org/licenses/>.
#
#
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)

View file

@ -1,5 +1,10 @@
#!/bin/sh #!/bin/sh
# if [ $# -ne 1 ]; then
# echo "$0: owner"
# exit 1
# fi
qemu=/usr/bin/qemu-system-x86_64 qemu=/usr/bin/qemu-system-x86_64
accel=kvm accel=kvm
@ -9,6 +14,7 @@ memory=1024
cores=2 cores=2
uuid=$(uuidgen) uuid=$(uuidgen)
mac=$(./mac-gen.py) mac=$(./mac-gen.py)
owner=nico
export bridge=br100 export bridge=br100

10
uncloud/hack/main.py Normal file
View file

@ -0,0 +1,10 @@
import argparse
arg_parser = argparse.ArgumentParser('hack', add_help=False)
arg_parser.add_argument('--create-vm')
def main(arguments):
print(arguments)!
debug = arguments['debug']
port = arguments['port']