forked from uncloud/uncloud
prefix is renamed to base_prefix, uncloud now respects base_prefix and put things under it
This commit is contained in:
parent
6046015c3d
commit
5a646aeac9
5 changed files with 21 additions and 48 deletions
|
@ -1,7 +1,7 @@
|
|||
[etcd]
|
||||
url = localhost
|
||||
port = 2379
|
||||
prefix = /
|
||||
base_prefix = /
|
||||
ca_cert
|
||||
cert_cert
|
||||
cert_key
|
||||
|
|
|
@ -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'],
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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, "/")
|
||||
|
||||
|
|
Loading…
Reference in a new issue