Modify the deployable's api for new database work

Change-Id: I9dee420890237485eba8fe9157a15741cdcb30f5
This commit is contained in:
Li Liu 2019-03-03 00:03:55 -05:00
parent cb2b1b03d6
commit 16e6af9ec9
2 changed files with 17 additions and 60 deletions

View File

@ -42,44 +42,20 @@ class Deployable(base.APIBase):
uuid = types.uuid uuid = types.uuid
"""The UUID of the deployable""" """The UUID of the deployable"""
parent_id = types.integer
"""The parent ID of the deployable"""
root_id = types.integer
"""The root ID of the deployable"""
name = wtypes.text name = wtypes.text
"""The name of the deployable""" """The name of the deployable"""
parent_uuid = types.uuid num_accelerators = types.integer
"""The parent UUID of the deployable""" """The number of accelerators of the deployable"""
root_uuid = types.uuid device_id = types.integer
"""The root UUID of the deployable""" """The device on which the deployable is located"""
address = wtypes.text
"""The address(pci/mdev) of the deployable"""
host = wtypes.text
"""The host on which the deployable is located"""
board = wtypes.text
"""The board of the deployable"""
vendor = wtypes.text
"""The vendor of the deployable"""
version = wtypes.text
"""The version of the deployable"""
type = wtypes.text
"""The type of the deployable"""
interface_type = wtypes.text
"""The interface type of deployable"""
assignable = types.boolean
"""Whether the deployable is assignable"""
instance_uuid = types.uuid
"""The UUID of the instance which deployable is assigned to"""
availability = wtypes.text
"""The availability of the deployable"""
attributes_list = wtypes.text attributes_list = wtypes.text
"""The json list of attributes of the deployable""" """The json list of attributes of the deployable"""
@ -134,7 +110,7 @@ class DeployablePatchType(types.JsonPatchType):
@staticmethod @staticmethod
def internal_attrs(): def internal_attrs():
defaults = types.JsonPatchType.internal_attrs() defaults = types.JsonPatchType.internal_attrs()
return defaults + ['/address', '/host', '/type'] return defaults + ['/name', '/num_accelerators']
class DeployablesController(base.CyborgController): class DeployablesController(base.CyborgController):
@ -235,25 +211,6 @@ class DeployablesController(base.CyborgController):
reservations = None reservations = None
obj_dep = objects.Deployable.get(context, uuid) obj_dep = objects.Deployable.get(context, uuid)
try:
# TODO(xinran): need more discussion on quota's granularity.
# Now we count by board.
for p in patch:
if p["path"] == "/instance_uuid" and p["op"] == "replace":
if not p["value"]:
obj_dep["assignable"] = True
reserve_opts = {obj_dep["board"]: -1}
else:
obj_dep["assignable"] = False
reserve_opts = {obj_dep["board"]: 1}
reservations = QUOTAS.reserve(context, reserve_opts)
api_dep = Deployable(
**api_utils.apply_jsonpatch(obj_dep.as_dict(), patch))
except api_utils.JSONPATCH_EXCEPTIONS as e:
QUOTAS.rollback(context, reservations, project_id=None)
raise exception.PatchError(patch=patch, reason=e)
QUOTAS.commit(context, reservations)
# Update only the fields that have changed # Update only the fields that have changed
for field in objects.Deployable.fields: for field in objects.Deployable.fields:

View File

@ -30,10 +30,9 @@ class FilterType(wtypes.UserType):
name = 'filtertype' name = 'filtertype'
basetype = wtypes.text basetype = wtypes.text
_supported_fields = wtypes.Enum(wtypes.text, 'parent_uuid', 'root_uuid', _supported_fields = wtypes.Enum(wtypes.text, 'parent_id', 'root_id',
'vender', 'host', 'board', 'availability', 'name', 'num_accelerators', 'device_id',
'assignable', 'interface_type', 'limit', 'marker',
'instance_uuid', 'limit', 'marker',
'sort_key', 'sort_dir') 'sort_key', 'sort_dir')
field = wsme.wsattr(_supported_fields, mandatory=True) field = wsme.wsattr(_supported_fields, mandatory=True)
@ -46,8 +45,8 @@ class FilterType(wtypes.UserType):
@classmethod @classmethod
def sample(cls): def sample(cls):
return cls(field='interface_type', return cls(field='name',
value='pci') value='FPGA')
def as_dict(self): def as_dict(self):
d = dict() d = dict()
@ -126,6 +125,7 @@ class BooleanType(wtypes.UserType):
uuid = UUIDType() uuid = UUIDType()
jsontype = JsonType() jsontype = JsonType()
boolean = BooleanType() boolean = BooleanType()
integer = wtypes.IntegerType()
class JsonPatchType(wtypes.Base): class JsonPatchType(wtypes.Base):