From 16e6af9ec976557c96ba44e083dc0eb7c5bd2073 Mon Sep 17 00:00:00 2001 From: Li Liu Date: Sun, 3 Mar 2019 00:03:55 -0500 Subject: [PATCH] Modify the deployable's api for new database work Change-Id: I9dee420890237485eba8fe9157a15741cdcb30f5 --- cyborg/api/controllers/v1/deployables.py | 65 ++++-------------------- cyborg/api/controllers/v1/types.py | 12 ++--- 2 files changed, 17 insertions(+), 60 deletions(-) diff --git a/cyborg/api/controllers/v1/deployables.py b/cyborg/api/controllers/v1/deployables.py index 94210ea5..c0698fb7 100644 --- a/cyborg/api/controllers/v1/deployables.py +++ b/cyborg/api/controllers/v1/deployables.py @@ -42,44 +42,20 @@ class Deployable(base.APIBase): uuid = types.uuid """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 """The name of the deployable""" - parent_uuid = types.uuid - """The parent UUID of the deployable""" + num_accelerators = types.integer + """The number of accelerators of the deployable""" - root_uuid = types.uuid - """The root UUID of the deployable""" - - 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""" + device_id = types.integer + """The device on which the deployable is located""" attributes_list = wtypes.text """The json list of attributes of the deployable""" @@ -134,7 +110,7 @@ class DeployablePatchType(types.JsonPatchType): @staticmethod def internal_attrs(): defaults = types.JsonPatchType.internal_attrs() - return defaults + ['/address', '/host', '/type'] + return defaults + ['/name', '/num_accelerators'] class DeployablesController(base.CyborgController): @@ -235,25 +211,6 @@ class DeployablesController(base.CyborgController): reservations = None 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 for field in objects.Deployable.fields: diff --git a/cyborg/api/controllers/v1/types.py b/cyborg/api/controllers/v1/types.py index fad93049..9c240de1 100644 --- a/cyborg/api/controllers/v1/types.py +++ b/cyborg/api/controllers/v1/types.py @@ -30,10 +30,9 @@ class FilterType(wtypes.UserType): name = 'filtertype' basetype = wtypes.text - _supported_fields = wtypes.Enum(wtypes.text, 'parent_uuid', 'root_uuid', - 'vender', 'host', 'board', 'availability', - 'assignable', 'interface_type', - 'instance_uuid', 'limit', 'marker', + _supported_fields = wtypes.Enum(wtypes.text, 'parent_id', 'root_id', + 'name', 'num_accelerators', 'device_id', + 'limit', 'marker', 'sort_key', 'sort_dir') field = wsme.wsattr(_supported_fields, mandatory=True) @@ -46,8 +45,8 @@ class FilterType(wtypes.UserType): @classmethod def sample(cls): - return cls(field='interface_type', - value='pci') + return cls(field='name', + value='FPGA') def as_dict(self): d = dict() @@ -126,6 +125,7 @@ class BooleanType(wtypes.UserType): uuid = UUIDType() jsontype = JsonType() boolean = BooleanType() +integer = wtypes.IntegerType() class JsonPatchType(wtypes.Base):