Remove ucloud_common and put its files under ucloud.common subpackage.

Remove individual config.py used by every component and put them into single config.py ucloud/config.py
Use /etc/ucloud/ucloud.conf for Environment Variables
Refactoring and a lot of it
Make ucloud repo a package and different components of ucloud a subpackage for avoiding code duplication.
Improved logging.
This commit is contained in:
ahmadbilalkhalid 2019-11-18 22:39:57 +05:00
commit 6fa77bce4d
51 changed files with 890 additions and 567 deletions

View file

@ -2,14 +2,15 @@ import os
from flask import Flask, request
from flask_restful import Resource, Api
from config import etcd_client, VM_POOL, USER_PREFIX
from config import etcd_client, env_vars, vm_pool
app = Flask(__name__)
api = Api(app)
def get_vm_entry(mac_addr):
return next(filter(lambda vm: mac_addr in list(zip(*vm.network))[1], VM_POOL.vms), None)
return next(filter(lambda vm: mac_addr in list(zip(*vm.network))[1], vm_pool.vms), None)
# https://stackoverflow.com/questions/37140846/how-to-convert-ipv6-link-local-address-to-mac-address-in-python
@ -43,8 +44,8 @@ class Root(Resource):
return {'message': 'Metadata for such VM does not exists.'}, 404
else:
# {user_prefix}/{realm}/{name}/key
etcd_key = os.path.join(USER_PREFIX, data.value['owner_realm'],
# {env_vars.get('USER_PREFIX')}/{realm}/{name}/key
etcd_key = os.path.join(env_vars.get('USER_PREFIX'), data.value['owner_realm'],
data.value['owner'], 'key')
etcd_entry = etcd_client.get_prefix(etcd_key, value_in_json=True)
user_personal_ssh_keys = [key.value for key in etcd_entry]
@ -81,5 +82,10 @@ class Root(Resource):
api.add_resource(Root, '/')
if __name__ == '__main__':
def main():
app.run(debug=True, host="::", port="80")
if __name__ == '__main__':
main()