Refactoring, Removal of most global vars, config default path is ~/ucloud/
This commit is contained in:
parent
bc58a6ed9c
commit
04993e4106
23 changed files with 673 additions and 726 deletions
|
|
@ -2,15 +2,15 @@ import os
|
|||
|
||||
from flask import Flask, request
|
||||
from flask_restful import Resource, Api
|
||||
|
||||
from ucloud.config import etcd_client, config, vm_pool
|
||||
from ucloud.settings import settings
|
||||
from ucloud.shared import shared
|
||||
|
||||
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], shared.vm_pool.vms), None)
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/37140846/how-to-convert-ipv6-link-local-address-to-mac-address-in-python
|
||||
|
|
@ -43,10 +43,10 @@ class Root(Resource):
|
|||
if not data:
|
||||
return {'message': 'Metadata for such VM does not exists.'}, 404
|
||||
else:
|
||||
etcd_key = os.path.join(config['etcd']['user_prefix'],
|
||||
etcd_key = os.path.join(settings['etcd']['user_prefix'],
|
||||
data.value['owner_realm'],
|
||||
data.value['owner'], 'key')
|
||||
etcd_entry = etcd_client.get_prefix(etcd_key, value_in_json=True)
|
||||
etcd_entry = shared.etcd_client.get_prefix(etcd_key, value_in_json=True)
|
||||
user_personal_ssh_keys = [key.value for key in etcd_entry]
|
||||
data.value['metadata']['ssh-keys'] += user_personal_ssh_keys
|
||||
return data.value['metadata'], 200
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue