From 9ec9083c57f7d0005ce8cc513625b7798b3020c4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 8 Dec 2019 14:08:40 +0100 Subject: [PATCH 1/3] conf update Signed-off-by: Nico Schottelius --- conf/ucloud.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/ucloud.conf b/conf/ucloud.conf index 2a06c81..cebe58e 100644 --- a/conf/ucloud.conf +++ b/conf/ucloud.conf @@ -30,9 +30,9 @@ CERT_CERT = changeme CERT_KEY = changeme -FILE_PREFIX = file/ +FILE_PREFIX = files HOST_PREFIx = hosts -IMAGE_PREFIX = image/ +IMAGE_PREFIX = images IMAGE_STORE_PREFIX = imagestore/ NETWORK_PREFIX = networks From 5b44034602faa719939f268d0163461bdb2d0943 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 8 Dec 2019 14:15:36 +0100 Subject: [PATCH 2/3] cleanup --- bin/ucloud-run-reinstall | 0 scripts/ucloud | 11 +++-------- ucloud/api/main.py | 22 ++++++++++------------ ucloud/config.py | 3 +-- 4 files changed, 14 insertions(+), 22 deletions(-) mode change 100644 => 100755 bin/ucloud-run-reinstall diff --git a/bin/ucloud-run-reinstall b/bin/ucloud-run-reinstall old mode 100644 new mode 100755 diff --git a/scripts/ucloud b/scripts/ucloud index b8ef32d..0780fb4 100755 --- a/scripts/ucloud +++ b/scripts/ucloud @@ -18,21 +18,16 @@ if __name__ == "__main__": arg_parser.add_argument('component_args', nargs='*') args = arg_parser.parse_args() + if args.conf_dir: + os.environ['UCLOUD_CONF_DIR'] = args.conf_dir + try: name = args.component mod = importlib.import_module("ucloud.{}.main".format(name)) main = getattr(mod, "main") - if args.conf_dir: - print("setting conf") - os.environ['UCLOUD_CONF_DIR'] = args.conf_dir - main() - # except decouple.UndefinedValueError as e: - # print(e) - # sys.exit(1) - except Exception as e: logging.exception(e) print(e) diff --git a/ucloud/api/main.py b/ucloud/api/main.py index d3ddd5d..bbda7e9 100644 --- a/ucloud/api/main.py +++ b/ucloud/api/main.py @@ -28,7 +28,7 @@ class CreateVM(Resource): validator = schemas.CreateVMSchema(data) if validator.is_valid(): vm_uuid = uuid4().hex - vm_key = join_path(config['api']["VM_PREFIX"), vm_uuid) + vm_key = join_path(config['etcd']["VM_PREFIX"], vm_uuid) specs = { "cpu": validator.specs["cpu"], "ram": validator.specs["ram"], @@ -56,7 +56,7 @@ class CreateVM(Resource): # Create ScheduleVM Request r = RequestEntry.from_scratch( type=RequestType.ScheduleVM, uuid=vm_uuid, - request_prefix=config['api']["REQUEST_PREFIX") + request_prefix=config['etcd']["REQUEST_PREFIX"] ) request_pool.put(r) @@ -71,7 +71,7 @@ class VmStatus(Resource): validator = schemas.VMStatusSchema(data) if validator.is_valid(): vm = vm_pool.get( - join_path(config['api']["VM_PREFIX"), data["uuid"]) + join_path(config['etcd']["VM_PREFIX"], data["uuid"]) ) vm_value = vm.value.copy() vm_value["ip"] = [] @@ -79,7 +79,7 @@ class VmStatus(Resource): network_name, mac, tap = network_mac_and_tap network = etcd_client.get( join_path( - config['api']["NETWORK_PREFIX"), + config['etcd']["NETWORK_PREFIX"], data["name"], network_name, ), @@ -100,7 +100,7 @@ class CreateImage(Resource): validator = schemas.CreateImageSchema(data) if validator.is_valid(): file_entry = etcd_client.get( - join_path(config['api']["FILE_PREFIX"), data["uuid"]) + join_path(config['etcd']["FILE_PREFIX"], data["uuid"]) ) file_entry_value = json.loads(file_entry.value) @@ -113,7 +113,7 @@ class CreateImage(Resource): "visibility": "public", } etcd_client.put( - join_path(config['etcd']["IMAGE_PREFIX"), data["uuid"]), + join_path(config['etcd']["IMAGE_PREFIX"], data["uuid"]), json.dumps(image_entry_json), ) @@ -125,7 +125,7 @@ class ListPublicImages(Resource): @staticmethod def get(): images = etcd_client.get_prefix( - config['etcd']["IMAGE_PREFIX"), value_in_json=True + config['etcd']["IMAGE_PREFIX"], value_in_json=True ) r = { "images": [] @@ -148,7 +148,7 @@ class VMAction(Resource): if validator.is_valid(): vm_entry = vm_pool.get( - join_path(config['etcd']["VM_PREFIX"), data["uuid"]) + join_path(config['etcd']["VM_PREFIX"], data["uuid"]) ) action = data["action"] @@ -326,7 +326,7 @@ class GetSSHKeys(Resource): # {user_prefix}/{realm}/{name}/key/{key_name} etcd_key = join_path( - config['etcd']['USER_PREFIX'), + config['etcd']['USER_PREFIX'], data["realm"], data["name"], "key", @@ -430,9 +430,7 @@ class CreateNetwork(Resource): prefix = nb_prefix.available_prefixes.create( data={ - "prefix_length": config['network'][ - "PREFIX_LENGTH"] - ), + "prefix_length": config['network']["PREFIX_LENGTH"], "description": '{}\'s network "{}"'.format( data["name"], data["network_name"] ), diff --git a/ucloud/config.py b/ucloud/config.py index 834d51e..4a067cb 100644 --- a/ucloud/config.py +++ b/ucloud/config.py @@ -25,8 +25,7 @@ config_file = os.path.join(conf_dir, conf_name) config = configparser.ConfigParser() try: - with open(config_file, "r") as conf_fd: - conf.read(conf_fd) + config.read(config_file) except FileNotFoundError: log.warn("Configuration file not found - using defaults") From 0283894ba2eafd4dbb8eace1188d979334695069 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 8 Dec 2019 14:16:22 +0100 Subject: [PATCH 3/3] remove non-unknown vars --- conf/ucloud.conf | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/conf/ucloud.conf b/conf/ucloud.conf index cf7ff7e..ae33cf5 100644 --- a/conf/ucloud.conf +++ b/conf/ucloud.conf @@ -57,10 +57,5 @@ FILE_DIR = /var/lib/ucloud/files FILE_PREFIX = noclue-ahmed [ssh] -SSH_USERNAME = -SSH_PRIVATEKEY = - -# unkown vars: -IMAGE_DIR = -BASE_DIR = -IMAGE_STORE_PREFIX = +SSH_USERNAME = +SSH_PRIVATEKEY = \ No newline at end of file