[api] done -> configparser
This commit is contained in:
parent
adddba518c
commit
76f63633ca
3 changed files with 52 additions and 37 deletions
|
|
@ -21,7 +21,7 @@ import bitmath
|
|||
|
||||
from ucloud.common.host import HostStatus
|
||||
from ucloud.common.vm import VMStatus
|
||||
from ucloud.config import etcd_client, env_vars, vm_pool, host_pool
|
||||
from ucloud.config import etcd_client, config, vm_pool, host_pool
|
||||
from . import helper
|
||||
from .common_fields import Field, VmUUIDField
|
||||
from .helper import check_otp, resolve_vm_name
|
||||
|
|
@ -102,14 +102,14 @@ class CreateImageSchema(BaseSchema):
|
|||
super().__init__(data, fields)
|
||||
|
||||
def file_uuid_validation(self):
|
||||
file_entry = etcd_client.get(os.path.join(env_vars.get('FILE_PREFIX'), self.uuid.value))
|
||||
file_entry = etcd_client.get(os.path.join(config['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(env_vars.get('IMAGE_STORE_PREFIX')))
|
||||
image_stores = list(etcd_client.get_prefix(config['etcd']['IMAGE_STORE_PREFIX']))
|
||||
|
||||
image_store = next(
|
||||
filter(
|
||||
|
|
@ -235,7 +235,7 @@ class CreateVMSchema(OTPSchema):
|
|||
|
||||
if _network:
|
||||
for net in _network:
|
||||
network = etcd_client.get(os.path.join(env_vars.get('NETWORK_PREFIX'),
|
||||
network = etcd_client.get(os.path.join(config['etcd']['NETWORK_PREFIX'],
|
||||
self.name.value,
|
||||
net), value_in_json=True)
|
||||
if not network:
|
||||
|
|
@ -400,7 +400,7 @@ class VmMigrationSchema(OTPSchema):
|
|||
if vm.status != VMStatus.running:
|
||||
self.add_error("Can't migrate non-running VM")
|
||||
|
||||
if vm.hostname == os.path.join(env_vars.get('HOST_PREFIX'), self.destination.value):
|
||||
if vm.hostname == os.path.join(config['etcd']['HOST_PREFIX'], self.destination.value):
|
||||
self.add_error("Destination host couldn't be same as Source Host")
|
||||
|
||||
|
||||
|
|
@ -442,7 +442,7 @@ class CreateNetwork(OTPSchema):
|
|||
super().__init__(data, fields=fields)
|
||||
|
||||
def network_name_validation(self):
|
||||
network = etcd_client.get(os.path.join(env_vars.get('NETWORK_PREFIX'),
|
||||
network = etcd_client.get(os.path.join(config['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