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
|
|
@ -1,6 +1,8 @@
|
|||
import os
|
||||
|
||||
from ucloud.config import etcd_client, config
|
||||
from ucloud.shared import shared
|
||||
from ucloud.settings import settings
|
||||
|
||||
|
||||
class Optional:
|
||||
pass
|
||||
|
|
@ -47,6 +49,6 @@ class VmUUIDField(Field):
|
|||
self.validation = self.vm_uuid_validation
|
||||
|
||||
def vm_uuid_validation(self):
|
||||
r = etcd_client.get(os.path.join(config['etcd']['vm_prefix'], self.uuid))
|
||||
r = shared.etcd_client.get(os.path.join(settings['etcd']['vm_prefix'], self.uuid))
|
||||
if not r:
|
||||
self.add_error("VM with uuid {} does not exists".format(self.uuid))
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ import os
|
|||
|
||||
from uuid import uuid4
|
||||
|
||||
from ucloud.config import etcd_client, config
|
||||
from ucloud.shared import shared
|
||||
from ucloud.settings import settings
|
||||
|
||||
data = {
|
||||
"is_public": True,
|
||||
|
|
@ -13,4 +14,4 @@ data = {
|
|||
"attributes": {"list": [], "key": [], "pool": "images"},
|
||||
}
|
||||
|
||||
etcd_client.put(os.path.join(config['etcd']['image_store_prefix'], uuid4().hex), json.dumps(data))
|
||||
shared.etcd_client.put(os.path.join(settings['etcd']['image_store_prefix'], uuid4().hex), json.dumps(data))
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -10,10 +10,9 @@ from flask_restful import Resource, Api
|
|||
from ucloud.common import counters
|
||||
from ucloud.common.vm import VMStatus
|
||||
from ucloud.common.request import RequestEntry, RequestType
|
||||
from ucloud.config import (
|
||||
etcd_client, request_pool, vm_pool,
|
||||
host_pool, config, image_storage_handler
|
||||
)
|
||||
from ucloud.settings import settings
|
||||
from ucloud.shared import shared
|
||||
|
||||
from . import schemas
|
||||
from .helper import generate_mac, mac2ipv6
|
||||
from . import logger
|
||||
|
|
@ -31,7 +30,7 @@ class CreateVM(Resource):
|
|||
validator = schemas.CreateVMSchema(data)
|
||||
if validator.is_valid():
|
||||
vm_uuid = uuid4().hex
|
||||
vm_key = join_path(config['etcd']['vm_prefix'], vm_uuid)
|
||||
vm_key = join_path(settings['etcd']['vm_prefix'], vm_uuid)
|
||||
specs = {
|
||||
"cpu": validator.specs["cpu"],
|
||||
"ram": validator.specs["ram"],
|
||||
|
|
@ -39,7 +38,7 @@ class CreateVM(Resource):
|
|||
"hdd": validator.specs["hdd"],
|
||||
}
|
||||
macs = [generate_mac() for _ in range(len(data["network"]))]
|
||||
tap_ids = [counters.increment_etcd_counter(etcd_client, "/v1/counter/tap")
|
||||
tap_ids = [counters.increment_etcd_counter(shared.etcd_client, "/v1/counter/tap")
|
||||
for _ in range(len(data["network"]))]
|
||||
vm_entry = {
|
||||
"name": data["vm_name"],
|
||||
|
|
@ -54,14 +53,14 @@ class CreateVM(Resource):
|
|||
"network": list(zip(data["network"], macs, tap_ids)),
|
||||
"metadata": {"ssh-keys": []},
|
||||
}
|
||||
etcd_client.put(vm_key, vm_entry, value_in_json=True)
|
||||
shared.etcd_client.put(vm_key, vm_entry, value_in_json=True)
|
||||
|
||||
# Create ScheduleVM Request
|
||||
r = RequestEntry.from_scratch(
|
||||
type=RequestType.ScheduleVM, uuid=vm_uuid,
|
||||
request_prefix=config['etcd']['request_prefix']
|
||||
request_prefix=settings['etcd']['request_prefix']
|
||||
)
|
||||
request_pool.put(r)
|
||||
shared.request_pool.put(r)
|
||||
|
||||
return {"message": "VM Creation Queued"}, 200
|
||||
return validator.get_errors(), 400
|
||||
|
|
@ -73,16 +72,16 @@ class VmStatus(Resource):
|
|||
data = request.json
|
||||
validator = schemas.VMStatusSchema(data)
|
||||
if validator.is_valid():
|
||||
vm = vm_pool.get(
|
||||
join_path(config['etcd']['vm_prefix'], data["uuid"])
|
||||
vm = shared.vm_pool.get(
|
||||
join_path(settings['etcd']['vm_prefix'], data["uuid"])
|
||||
)
|
||||
vm_value = vm.value.copy()
|
||||
vm_value["ip"] = []
|
||||
for network_mac_and_tap in vm.network:
|
||||
network_name, mac, tap = network_mac_and_tap
|
||||
network = etcd_client.get(
|
||||
network = shared.etcd_client.get(
|
||||
join_path(
|
||||
config['etcd']['network_prefix'],
|
||||
settings['etcd']['network_prefix'],
|
||||
data["name"],
|
||||
network_name,
|
||||
),
|
||||
|
|
@ -102,8 +101,8 @@ class CreateImage(Resource):
|
|||
data = request.json
|
||||
validator = schemas.CreateImageSchema(data)
|
||||
if validator.is_valid():
|
||||
file_entry = etcd_client.get(
|
||||
join_path(config['etcd']['file_prefix'], data["uuid"])
|
||||
file_entry = shared.etcd_client.get(
|
||||
join_path(settings['etcd']['file_prefix'], data["uuid"])
|
||||
)
|
||||
file_entry_value = json.loads(file_entry.value)
|
||||
|
||||
|
|
@ -115,8 +114,8 @@ class CreateImage(Resource):
|
|||
"store_name": data["image_store"],
|
||||
"visibility": "public",
|
||||
}
|
||||
etcd_client.put(
|
||||
join_path(config['etcd']['image_prefix'], data["uuid"]),
|
||||
shared.etcd_client.put(
|
||||
join_path(settings['etcd']['image_prefix'], data["uuid"]),
|
||||
json.dumps(image_entry_json),
|
||||
)
|
||||
|
||||
|
|
@ -127,8 +126,8 @@ class CreateImage(Resource):
|
|||
class ListPublicImages(Resource):
|
||||
@staticmethod
|
||||
def get():
|
||||
images = etcd_client.get_prefix(
|
||||
config['etcd']['image_prefix'], value_in_json=True
|
||||
images = shared.etcd_client.get_prefix(
|
||||
settings['etcd']['image_prefix'], value_in_json=True
|
||||
)
|
||||
r = {
|
||||
"images": []
|
||||
|
|
@ -150,8 +149,8 @@ class VMAction(Resource):
|
|||
validator = schemas.VmActionSchema(data)
|
||||
|
||||
if validator.is_valid():
|
||||
vm_entry = vm_pool.get(
|
||||
join_path(config['etcd']['vm_prefix'], data["uuid"])
|
||||
vm_entry = shared.vm_pool.get(
|
||||
join_path(settings['etcd']['vm_prefix'], data["uuid"])
|
||||
)
|
||||
action = data["action"]
|
||||
|
||||
|
|
@ -159,25 +158,25 @@ class VMAction(Resource):
|
|||
action = "schedule"
|
||||
|
||||
if action == "delete" and vm_entry.hostname == "":
|
||||
if image_storage_handler.is_vm_image_exists(vm_entry.uuid):
|
||||
r_status = image_storage_handler.delete_vm_image(vm_entry.uuid)
|
||||
if shared.storage_handler.is_vm_image_exists(vm_entry.uuid):
|
||||
r_status = shared.storage_handler.delete_vm_image(vm_entry.uuid)
|
||||
if r_status:
|
||||
etcd_client.client.delete(vm_entry.key)
|
||||
shared.etcd_client.client.delete(vm_entry.key)
|
||||
return {"message": "VM successfully deleted"}
|
||||
else:
|
||||
logger.error("Some Error Occurred while deleting VM")
|
||||
return {"message": "VM deletion unsuccessfull"}
|
||||
else:
|
||||
etcd_client.client.delete(vm_entry.key)
|
||||
shared.etcd_client.client.delete(vm_entry.key)
|
||||
return {"message": "VM successfully deleted"}
|
||||
|
||||
r = RequestEntry.from_scratch(
|
||||
type="{}VM".format(action.title()),
|
||||
uuid=data["uuid"],
|
||||
hostname=vm_entry.hostname,
|
||||
request_prefix=config['etcd']['request_prefix']
|
||||
request_prefix=settings['etcd']['request_prefix']
|
||||
)
|
||||
request_pool.put(r)
|
||||
shared.request_pool.put(r)
|
||||
return {"message": "VM {} Queued".format(action.title())}, 200
|
||||
else:
|
||||
return validator.get_errors(), 400
|
||||
|
|
@ -190,18 +189,18 @@ class VMMigration(Resource):
|
|||
validator = schemas.VmMigrationSchema(data)
|
||||
|
||||
if validator.is_valid():
|
||||
vm = vm_pool.get(data["uuid"])
|
||||
vm = shared.vm_pool.get(data["uuid"])
|
||||
|
||||
r = RequestEntry.from_scratch(
|
||||
type=RequestType.ScheduleVM,
|
||||
uuid=vm.uuid,
|
||||
destination=join_path(
|
||||
config['etcd']['host_prefix'], validator.destination.value
|
||||
settings['etcd']['host_prefix'], validator.destination.value
|
||||
),
|
||||
migration=True,
|
||||
request_prefix=config['etcd']['request_prefix']
|
||||
request_prefix=settings['etcd']['request_prefix']
|
||||
)
|
||||
request_pool.put(r)
|
||||
shared.request_pool.put(r)
|
||||
return {"message": "VM Migration Initialization Queued"}, 200
|
||||
else:
|
||||
return validator.get_errors(), 400
|
||||
|
|
@ -214,8 +213,8 @@ class ListUserVM(Resource):
|
|||
validator = schemas.OTPSchema(data)
|
||||
|
||||
if validator.is_valid():
|
||||
vms = etcd_client.get_prefix(
|
||||
config['etcd']['vm_prefix'], value_in_json=True
|
||||
vms = shared.etcd_client.get_prefix(
|
||||
settings['etcd']['vm_prefix'], value_in_json=True
|
||||
)
|
||||
return_vms = []
|
||||
user_vms = filter(lambda v: v.value["owner"] == data["name"], vms)
|
||||
|
|
@ -227,7 +226,6 @@ class ListUserVM(Resource):
|
|||
"specs": vm.value["specs"],
|
||||
"status": vm.value["status"],
|
||||
"hostname": vm.value["hostname"],
|
||||
# "mac": vm.value["mac"],
|
||||
"vnc_socket": None
|
||||
if vm.value.get("vnc_socket", None) is None
|
||||
else vm.value["vnc_socket"],
|
||||
|
|
@ -248,8 +246,8 @@ class ListUserFiles(Resource):
|
|||
validator = schemas.OTPSchema(data)
|
||||
|
||||
if validator.is_valid():
|
||||
files = etcd_client.get_prefix(
|
||||
config['etcd']['file_prefix'], value_in_json=True
|
||||
files = shared.etcd_client.get_prefix(
|
||||
settings['etcd']['file_prefix'], value_in_json=True
|
||||
)
|
||||
return_files = []
|
||||
user_files = list(
|
||||
|
|
@ -273,14 +271,14 @@ class CreateHost(Resource):
|
|||
data = request.json
|
||||
validator = schemas.CreateHostSchema(data)
|
||||
if validator.is_valid():
|
||||
host_key = join_path(config['etcd']['host_prefix'], uuid4().hex)
|
||||
host_key = join_path(settings['etcd']['host_prefix'], uuid4().hex)
|
||||
host_entry = {
|
||||
"specs": data["specs"],
|
||||
"hostname": data["hostname"],
|
||||
"status": "DEAD",
|
||||
"last_heartbeat": "",
|
||||
}
|
||||
etcd_client.put(host_key, host_entry, value_in_json=True)
|
||||
shared.etcd_client.put(host_key, host_entry, value_in_json=True)
|
||||
|
||||
return {"message": "Host Created"}, 200
|
||||
|
||||
|
|
@ -290,7 +288,7 @@ class CreateHost(Resource):
|
|||
class ListHost(Resource):
|
||||
@staticmethod
|
||||
def get():
|
||||
hosts = host_pool.hosts
|
||||
hosts = shared.host_pool.hosts
|
||||
r = {
|
||||
host.key: {
|
||||
"status": host.status,
|
||||
|
|
@ -312,12 +310,12 @@ class GetSSHKeys(Resource):
|
|||
|
||||
# {user_prefix}/{realm}/{name}/key/
|
||||
etcd_key = join_path(
|
||||
config['etcd']['user_prefix'],
|
||||
settings['etcd']['user_prefix'],
|
||||
data["realm"],
|
||||
data["name"],
|
||||
"key",
|
||||
)
|
||||
etcd_entry = etcd_client.get_prefix(
|
||||
etcd_entry = shared.etcd_client.get_prefix(
|
||||
etcd_key, value_in_json=True
|
||||
)
|
||||
|
||||
|
|
@ -329,13 +327,13 @@ class GetSSHKeys(Resource):
|
|||
|
||||
# {user_prefix}/{realm}/{name}/key/{key_name}
|
||||
etcd_key = join_path(
|
||||
config['etcd']['user_prefix'],
|
||||
settings['etcd']['user_prefix'],
|
||||
data["realm"],
|
||||
data["name"],
|
||||
"key",
|
||||
data["key_name"],
|
||||
)
|
||||
etcd_entry = etcd_client.get(etcd_key, value_in_json=True)
|
||||
etcd_entry = shared.etcd_client.get(etcd_key, value_in_json=True)
|
||||
|
||||
if etcd_entry:
|
||||
return {
|
||||
|
|
@ -358,13 +356,13 @@ class AddSSHKey(Resource):
|
|||
|
||||
# {user_prefix}/{realm}/{name}/key/{key_name}
|
||||
etcd_key = join_path(
|
||||
config['etcd']['user_prefix'],
|
||||
settings['etcd']['user_prefix'],
|
||||
data["realm"],
|
||||
data["name"],
|
||||
"key",
|
||||
data["key_name"],
|
||||
)
|
||||
etcd_entry = etcd_client.get(etcd_key, value_in_json=True)
|
||||
etcd_entry = shared.etcd_client.get(etcd_key, value_in_json=True)
|
||||
if etcd_entry:
|
||||
return {
|
||||
"message": "Key with name '{}' already exists".format(
|
||||
|
|
@ -373,7 +371,7 @@ class AddSSHKey(Resource):
|
|||
}
|
||||
else:
|
||||
# Key Not Found. It implies user' haven't added any key yet.
|
||||
etcd_client.put(etcd_key, data["key"], value_in_json=True)
|
||||
shared.etcd_client.put(etcd_key, data["key"], value_in_json=True)
|
||||
return {"message": "Key added successfully"}
|
||||
else:
|
||||
return validator.get_errors(), 400
|
||||
|
|
@ -388,15 +386,15 @@ class RemoveSSHKey(Resource):
|
|||
|
||||
# {user_prefix}/{realm}/{name}/key/{key_name}
|
||||
etcd_key = join_path(
|
||||
config['etcd']['user_prefix'],
|
||||
settings['etcd']['user_prefix'],
|
||||
data["realm"],
|
||||
data["name"],
|
||||
"key",
|
||||
data["key_name"],
|
||||
)
|
||||
etcd_entry = etcd_client.get(etcd_key, value_in_json=True)
|
||||
etcd_entry = shared.etcd_client.get(etcd_key, value_in_json=True)
|
||||
if etcd_entry:
|
||||
etcd_client.client.delete(etcd_key)
|
||||
shared.etcd_client.client.delete(etcd_key)
|
||||
return {"message": "Key successfully removed."}
|
||||
else:
|
||||
return {
|
||||
|
|
@ -418,22 +416,22 @@ class CreateNetwork(Resource):
|
|||
|
||||
network_entry = {
|
||||
"id": counters.increment_etcd_counter(
|
||||
etcd_client, "/v1/counter/vxlan"
|
||||
shared.etcd_client, "/v1/counter/vxlan"
|
||||
),
|
||||
"type": data["type"],
|
||||
}
|
||||
if validator.user.value:
|
||||
try:
|
||||
nb = pynetbox.api(
|
||||
url=config['netbox']['url'],
|
||||
token=config['netbox']['token'],
|
||||
url=settings['netbox']['url'],
|
||||
token=settings['netbox']['token'],
|
||||
)
|
||||
nb_prefix = nb.ipam.prefixes.get(
|
||||
prefix=config['network']['prefix']
|
||||
prefix=settings['network']['prefix']
|
||||
)
|
||||
prefix = nb_prefix.available_prefixes.create(
|
||||
data={
|
||||
"prefix_length": int(config['network']['prefix_length']),
|
||||
"prefix_length": int(settings['network']['prefix_length']),
|
||||
"description": '{}\'s network "{}"'.format(
|
||||
data["name"], data["network_name"]
|
||||
),
|
||||
|
|
@ -449,11 +447,11 @@ class CreateNetwork(Resource):
|
|||
network_entry["ipv6"] = "fd00::/64"
|
||||
|
||||
network_key = join_path(
|
||||
config['etcd']['network_prefix'],
|
||||
settings['etcd']['network_prefix'],
|
||||
data['name'],
|
||||
data['network_name'],
|
||||
)
|
||||
etcd_client.put(network_key, network_entry, value_in_json=True)
|
||||
shared.etcd_client.put(network_key, network_entry, value_in_json=True)
|
||||
return {"message": "Network successfully added."}
|
||||
else:
|
||||
return validator.get_errors(), 400
|
||||
|
|
@ -467,9 +465,9 @@ class ListUserNetwork(Resource):
|
|||
|
||||
if validator.is_valid():
|
||||
prefix = join_path(
|
||||
config['etcd']['network_prefix'], data["name"]
|
||||
settings['etcd']['network_prefix'], data["name"]
|
||||
)
|
||||
networks = etcd_client.get_prefix(prefix, value_in_json=True)
|
||||
networks = shared.etcd_client.get_prefix(prefix, value_in_json=True)
|
||||
user_networks = []
|
||||
for net in networks:
|
||||
net.value["name"] = net.key.split("/")[-1]
|
||||
|
|
@ -503,7 +501,7 @@ api.add_resource(CreateNetwork, "/network/create")
|
|||
|
||||
|
||||
def main():
|
||||
image_stores = list(etcd_client.get_prefix(config['etcd']['image_store_prefix'], value_in_json=True))
|
||||
image_stores = list(shared.etcd_client.get_prefix(settings['etcd']['image_store_prefix'], value_in_json=True))
|
||||
if len(image_stores) == 0:
|
||||
data = {
|
||||
"is_public": True,
|
||||
|
|
@ -513,7 +511,7 @@ def main():
|
|||
"attributes": {"list": [], "key": [], "pool": "images"},
|
||||
}
|
||||
|
||||
etcd_client.put(join_path(config['etcd']['image_store_prefix'], uuid4().hex), json.dumps(data))
|
||||
shared.etcd_client.put(join_path(settings['etcd']['image_store_prefix'], uuid4().hex), json.dumps(data))
|
||||
|
||||
app.run(host="::", debug=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ import bitmath
|
|||
|
||||
from ucloud.common.host import HostStatus
|
||||
from ucloud.common.vm import VMStatus
|
||||
from ucloud.config import etcd_client, config, vm_pool, host_pool
|
||||
from ucloud.shared import shared
|
||||
from ucloud.settings import settings
|
||||
from . import helper, logger
|
||||
from .common_fields import Field, VmUUIDField
|
||||
from .helper import check_otp, resolve_vm_name
|
||||
|
|
@ -102,14 +103,14 @@ class CreateImageSchema(BaseSchema):
|
|||
super().__init__(data, fields)
|
||||
|
||||
def file_uuid_validation(self):
|
||||
file_entry = etcd_client.get(os.path.join(config['etcd']['file_prefix'], self.uuid.value))
|
||||
file_entry = shared.etcd_client.get(os.path.join(settings['etcd']['file_prefix'], self.uuid.value))
|
||||
if file_entry is None:
|
||||
self.add_error(
|
||||
"Image File with uuid '{}' Not Found".format(self.uuid.value)
|
||||
)
|
||||
|
||||
def image_store_name_validation(self):
|
||||
image_stores = list(etcd_client.get_prefix(config['etcd']['image_store_prefix']))
|
||||
image_stores = list(shared.etcd_client.get_prefix(settings['etcd']['image_store_prefix']))
|
||||
|
||||
image_store = next(
|
||||
filter(
|
||||
|
|
@ -218,7 +219,7 @@ class CreateVMSchema(OTPSchema):
|
|||
|
||||
def image_validation(self):
|
||||
try:
|
||||
image_uuid = helper.resolve_image_name(self.image.value, etcd_client)
|
||||
image_uuid = helper.resolve_image_name(self.image.value, shared.etcd_client)
|
||||
except Exception as e:
|
||||
logger.exception("Cannot resolve image name = %s", self.image.value)
|
||||
self.add_error(str(e))
|
||||
|
|
@ -236,7 +237,7 @@ class CreateVMSchema(OTPSchema):
|
|||
|
||||
if _network:
|
||||
for net in _network:
|
||||
network = etcd_client.get(os.path.join(config['etcd']['network_prefix'],
|
||||
network = shared.etcd_client.get(os.path.join(settings['etcd']['network_prefix'],
|
||||
self.name.value,
|
||||
net), value_in_json=True)
|
||||
if not network:
|
||||
|
|
@ -310,7 +311,7 @@ class VMStatusSchema(OTPSchema):
|
|||
super().__init__(data, fields)
|
||||
|
||||
def validation(self):
|
||||
vm = vm_pool.get(self.uuid.value)
|
||||
vm = shared.vm_pool.get(self.uuid.value)
|
||||
if not (
|
||||
vm.value["owner"] == self.name.value or self.realm.value == "ungleich-admin"
|
||||
):
|
||||
|
|
@ -343,7 +344,7 @@ class VmActionSchema(OTPSchema):
|
|||
)
|
||||
|
||||
def validation(self):
|
||||
vm = vm_pool.get(self.uuid.value)
|
||||
vm = shared.vm_pool.get(self.uuid.value)
|
||||
if not (
|
||||
vm.value["owner"] == self.name.value or self.realm.value == "ungleich-admin"
|
||||
):
|
||||
|
|
@ -383,7 +384,7 @@ class VmMigrationSchema(OTPSchema):
|
|||
|
||||
def destination_validation(self):
|
||||
hostname = self.destination.value
|
||||
host = next(filter(lambda h: h.hostname == hostname, host_pool.hosts), None)
|
||||
host = next(filter(lambda h: h.hostname == hostname, shared.host_pool.hosts), None)
|
||||
if not host:
|
||||
self.add_error("No Such Host ({}) exists".format(self.destination.value))
|
||||
elif host.status != HostStatus.alive:
|
||||
|
|
@ -392,7 +393,7 @@ class VmMigrationSchema(OTPSchema):
|
|||
self.destination.value = host.key
|
||||
|
||||
def validation(self):
|
||||
vm = vm_pool.get(self.uuid.value)
|
||||
vm = shared.vm_pool.get(self.uuid.value)
|
||||
if not (
|
||||
vm.value["owner"] == self.name.value or self.realm.value == "ungleich-admin"
|
||||
):
|
||||
|
|
@ -401,7 +402,7 @@ class VmMigrationSchema(OTPSchema):
|
|||
if vm.status != VMStatus.running:
|
||||
self.add_error("Can't migrate non-running VM")
|
||||
|
||||
if vm.hostname == os.path.join(config['etcd']['host_prefix'], self.destination.value):
|
||||
if vm.hostname == os.path.join(settings['etcd']['host_prefix'], self.destination.value):
|
||||
self.add_error("Destination host couldn't be same as Source Host")
|
||||
|
||||
|
||||
|
|
@ -443,7 +444,7 @@ class CreateNetwork(OTPSchema):
|
|||
super().__init__(data, fields=fields)
|
||||
|
||||
def network_name_validation(self):
|
||||
network = etcd_client.get(os.path.join(config['etcd']['network_prefix'],
|
||||
network = shared.etcd_client.get(os.path.join(settings['etcd']['network_prefix'],
|
||||
self.name.value,
|
||||
self.network_name.value),
|
||||
value_in_json=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue