From b96e56b453bff53898bb105560881c88ffd63218 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 14 Jan 2020 11:05:42 +0100 Subject: [PATCH] Begin to integrate hack into the main script --- scripts/uncloud | 3 +- uncloud/hack/__init__.py | 0 uncloud/hack/hackcloud/__init__.py | 1 + uncloud/hack/hackcloud/db.py | 55 ++++++++++++++++++++++++------ uncloud/hack/hackcloud/vm.py | 53 ++++++++++++++++++++++++++++ uncloud/hack/hackcloud/vm.sh | 6 ++++ uncloud/hack/main.py | 10 ++++++ 7 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 uncloud/hack/__init__.py create mode 100644 uncloud/hack/hackcloud/__init__.py create mode 100755 uncloud/hack/hackcloud/vm.py create mode 100644 uncloud/hack/main.py diff --git a/scripts/uncloud b/scripts/uncloud index 1a6483b..70cb535 100755 --- a/scripts/uncloud +++ b/scripts/uncloud @@ -22,7 +22,8 @@ def exception_hook(exc_type, exc_value, exc_traceback): sys.excepthook = exception_hook # 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.append('cli') diff --git a/uncloud/hack/__init__.py b/uncloud/hack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/hack/hackcloud/__init__.py b/uncloud/hack/hackcloud/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/uncloud/hack/hackcloud/__init__.py @@ -0,0 +1 @@ + diff --git a/uncloud/hack/hackcloud/db.py b/uncloud/hack/hackcloud/db.py index 3d885e9..0e6bd0a 100644 --- a/uncloud/hack/hackcloud/db.py +++ b/uncloud/hack/hackcloud/db.py @@ -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 . +# +# + 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__': endpoints = [ "https://etcd1.ungleich.ch:2379", - "!https://etcd2.ungleich.ch:2379", + "https://etcd2.ungleich.ch:2379", "https://etcd3.ungleich.ch:2379" ] - clients = [] - - 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) + db = DB(url=endpoints) diff --git a/uncloud/hack/hackcloud/vm.py b/uncloud/hack/hackcloud/vm.py new file mode 100755 index 0000000..9dd80bf --- /dev/null +++ b/uncloud/hack/hackcloud/vm.py @@ -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 . +# +# + +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/hackcloud/vm.sh b/uncloud/hack/hackcloud/vm.sh index a0e111b..dd9be84 100755 --- a/uncloud/hack/hackcloud/vm.sh +++ b/uncloud/hack/hackcloud/vm.sh @@ -1,5 +1,10 @@ #!/bin/sh +# if [ $# -ne 1 ]; then +# echo "$0: owner" +# exit 1 +# fi + qemu=/usr/bin/qemu-system-x86_64 accel=kvm @@ -9,6 +14,7 @@ memory=1024 cores=2 uuid=$(uuidgen) mac=$(./mac-gen.py) +owner=nico export bridge=br100 diff --git a/uncloud/hack/main.py b/uncloud/hack/main.py new file mode 100644 index 0000000..ce105e8 --- /dev/null +++ b/uncloud/hack/main.py @@ -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']