a
This commit is contained in:
parent
3f406799db
commit
ec032ed0db
9 changed files with 544 additions and 103 deletions
|
|
@ -1,10 +1,14 @@
|
|||
import os
|
||||
|
||||
from specs_parser import SpecsParser
|
||||
from config import etcd_client as client
|
||||
from config import VM_PREFIX
|
||||
|
||||
|
||||
specs_parser = SpecsParser(exceptional_devices=["cpu"])
|
||||
|
||||
|
||||
class Field(object):
|
||||
class Field:
|
||||
def __init__(self, _name, _type, _value=None):
|
||||
self.name = _name
|
||||
self.value = _value
|
||||
|
|
@ -16,10 +20,10 @@ class Field(object):
|
|||
|
||||
def is_valid(self):
|
||||
if self.value == KeyError:
|
||||
self.add_error(f"'{self.name}' field is a required field")
|
||||
self.add_error("'{}' field is a required field".format(self.name))
|
||||
else:
|
||||
if not isinstance(self.value, self.type):
|
||||
self.add_error(f"Incorrect Type for '{self.name}' field")
|
||||
self.add_error("Incorrect Type for '{}' field".format(self.name))
|
||||
else:
|
||||
self.validation()
|
||||
|
||||
|
|
@ -43,9 +47,9 @@ class VmUUIDField(Field):
|
|||
self.validation = self.vm_uuid_validation
|
||||
|
||||
def vm_uuid_validation(self):
|
||||
r = client.get(f"/v1/vm/{self.uuid}")
|
||||
r = client.get(os.path.join(VM_PREFIX, self.uuid))
|
||||
if not r:
|
||||
self.add_error(f"VM with uuid {self.uuid} does not exists")
|
||||
self.add_error("VM with uuid {} does not exists".format(self.uuid))
|
||||
|
||||
|
||||
class SpecsField(Field):
|
||||
|
|
@ -59,4 +63,4 @@ class SpecsField(Field):
|
|||
def specs_validation(self):
|
||||
if not specs_parser.transform_specs(self.specs):
|
||||
self.add_error("Invalid unit - "
|
||||
f"Please use following units {specs_parser.get_allowed_units()}")
|
||||
"Please use following units {}".format(specs_parser.get_allowed_units()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue