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
|
|
@ -7,29 +7,29 @@ import requests
|
|||
|
||||
from pyotp import TOTP
|
||||
|
||||
from ucloud.config import vm_pool, config
|
||||
|
||||
from ucloud.shared import shared
|
||||
from ucloud.settings import settings
|
||||
|
||||
logger = logging.getLogger("ucloud.api.helper")
|
||||
|
||||
def check_otp(name, realm, token):
|
||||
try:
|
||||
data = {
|
||||
"auth_name": config['otp']['auth_name'],
|
||||
"auth_token": TOTP(config['otp']['auth_seed']).now(),
|
||||
"auth_realm": config['otp']['auth_realm'],
|
||||
"auth_name": settings['otp']['auth_name'],
|
||||
"auth_token": TOTP(settings['otp']['auth_seed']).now(),
|
||||
"auth_realm": settings['otp']['auth_realm'],
|
||||
"name": name,
|
||||
"realm": realm,
|
||||
"token": token,
|
||||
}
|
||||
except binascii.Error as err:
|
||||
logger.error(
|
||||
"Cannot compute OTP for seed: {}".format(config['otp']['auth_seed'])
|
||||
"Cannot compute OTP for seed: {}".format(settings['otp']['auth_seed'])
|
||||
)
|
||||
return 400
|
||||
|
||||
response = requests.post(
|
||||
config['otp']['verification_controller_url'], json=data
|
||||
settings['otp']['verification_controller_url'], json=data
|
||||
)
|
||||
return response.status_code
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ def resolve_vm_name(name, owner):
|
|||
result = next(
|
||||
filter(
|
||||
lambda vm: vm.value["owner"] == owner and vm.value["name"] == name,
|
||||
vm_pool.vms,
|
||||
shared.vm_pool.vms,
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
|
@ -81,7 +81,7 @@ def resolve_image_name(name, etcd_client):
|
|||
except Exception:
|
||||
raise ValueError("Image name not in correct format i.e {store_name}:{image_name}")
|
||||
|
||||
images = etcd_client.get_prefix(config['etcd']['image_prefix'], value_in_json=True)
|
||||
images = etcd_client.get_prefix(settings['etcd']['image_prefix'], value_in_json=True)
|
||||
|
||||
# Try to find image with name == image_name and store_name == store_name
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue