From 5a646aeac951ad28b146769275a55a14576f161c Mon Sep 17 00:00:00 2001 From: meow Date: Tue, 7 Jan 2020 21:45:11 +0500 Subject: [PATCH] prefix is renamed to base_prefix, uncloud now respects base_prefix and put things under it --- conf/uncloud.conf | 2 +- uncloud/api/main.py | 4 ++-- uncloud/common/settings.py | 28 ++++++++++++++++------------ uncloud/configure/main.py | 8 ++------ uncloud/metadata/main.py | 27 --------------------------- 5 files changed, 21 insertions(+), 48 deletions(-) diff --git a/conf/uncloud.conf b/conf/uncloud.conf index 9995696..6a1b500 100644 --- a/conf/uncloud.conf +++ b/conf/uncloud.conf @@ -1,7 +1,7 @@ [etcd] url = localhost port = 2379 -prefix = / +base_prefix = / ca_cert cert_cert cert_key diff --git a/uncloud/api/main.py b/uncloud/api/main.py index 50bc201..d8beb49 100644 --- a/uncloud/api/main.py +++ b/uncloud/api/main.py @@ -59,7 +59,7 @@ class CreateVM(Resource): macs = [generate_mac() for _ in range(len(data['network']))] tap_ids = [ counters.increment_etcd_counter( - shared.etcd_client, '/v1/counter/tap' + shared.etcd_client, settings['etcd']['counter']['tap'] ) for _ in range(len(data['network'])) ] @@ -470,7 +470,7 @@ class CreateNetwork(Resource): network_entry = { 'id': counters.increment_etcd_counter( - shared.etcd_client, '/v1/counter/vxlan' + shared.etcd_client, settings['etcd']['counter']['vxlan'] ), 'type': data['type'], } diff --git a/uncloud/common/settings.py b/uncloud/common/settings.py index 7004055..9db4afe 100644 --- a/uncloud/common/settings.py +++ b/uncloud/common/settings.py @@ -36,15 +36,15 @@ class Settings(object): self.config_parser = CustomConfigParser(allow_no_value=True) self.config_parser.add_section('etcd') - self.config_parser.set('etcd', 'prefix', '/') - - self.config_key = join_path(self['etcd']['prefix'], '/uncloud/config/') + self.config_parser.set('etcd', 'base_prefix', '/') try: self.config_parser.read(self.config_file) except Exception as err: logger.error('%s', err) + self.config_key = join_path(self['etcd']['base_prefix'] + 'uncloud/config/') + self.read_internal_values() def get_etcd_client(self): @@ -78,18 +78,22 @@ class Settings(object): return wrapper def read_internal_values(self): - prefix = self['etcd']['prefix'] + base_prefix = self['etcd']['base_prefix'] self.config_parser.read_dict( { 'etcd': { - 'file_prefix': join_path(prefix, '/files/'), - 'host_prefix': join_path(prefix, '/hosts/'), - 'image_prefix': join_path(prefix, '/images/'), - 'image_store_prefix': join_path(prefix, '/imagestore/'), - 'network_prefix': join_path(prefix, '/networks/'), - 'request_prefix': join_path(prefix, '/requests/'), - 'user_prefix': join_path(prefix, '/users/'), - 'vm_prefix': join_path(prefix, '/vms/'), + 'file_prefix': join_path(base_prefix, 'files/'), + 'host_prefix': join_path(base_prefix, 'hosts/'), + 'image_prefix': join_path(base_prefix, 'images/'), + 'image_store_prefix': join_path(base_prefix, 'imagestore/'), + 'network_prefix': join_path(base_prefix, 'networks/'), + 'request_prefix': join_path(base_prefix, 'requests/'), + 'user_prefix': join_path(base_prefix, 'users/'), + 'vm_prefix': join_path(base_prefix, 'vms/'), + 'counter': { + 'vxlan': join_path(base_prefix, 'counters/vxlan'), + 'tap': join_path(base_prefix, 'counters/tap') + } } } ) diff --git a/uncloud/configure/main.py b/uncloud/configure/main.py index 64b40c0..f3e9717 100644 --- a/uncloud/configure/main.py +++ b/uncloud/configure/main.py @@ -40,18 +40,14 @@ ceph_storage_parser.add_argument('--ceph-image-pool', required=True) def update_config(section, kwargs): - uncloud_config = shared.etcd_client.get( - settings.config_key, value_in_json=True - ) + uncloud_config = shared.etcd_client.get(settings.config_key, value_in_json=True) if not uncloud_config: uncloud_config = {} else: uncloud_config = uncloud_config.value uncloud_config[section] = kwargs - shared.etcd_client.put( - settings.config_key, uncloud_config, value_in_json=True - ) + shared.etcd_client.put(settings.config_key, uncloud_config, value_in_json=True) def main(**kwargs): diff --git a/uncloud/metadata/main.py b/uncloud/metadata/main.py index d20122e..03469a5 100644 --- a/uncloud/metadata/main.py +++ b/uncloud/metadata/main.py @@ -84,33 +84,6 @@ class Root(Resource): data.value["metadata"]["ssh-keys"] += user_personal_ssh_keys return data.value["metadata"], 200 - @staticmethod - def post(): - return {"message": "Previous Implementation is deprecated."} - # data = etcd_client.get("/v1/metadata/{}".format(request.remote_addr), value_in_json=True) - # print(data) - # if data: - # for k in request.json: - # if k not in data.value: - # data.value[k] = request.json[k] - # if k.endswith("-list"): - # data.value[k] = [request.json[k]] - # else: - # if k.endswith("-list"): - # data.value[k].append(request.json[k]) - # else: - # data.value[k] = request.json[k] - # etcd_client.put("/v1/metadata/{}".format(request.remote_addr), - # data.value, value_in_json=True) - # else: - # data = {} - # for k in request.json: - # data[k] = request.json[k] - # if k.endswith("-list"): - # data[k] = [request.json[k]] - # etcd_client.put("/v1/metadata/{}".format(request.remote_addr), - # data, value_in_json=True) - api.add_resource(Root, "/")