Commit 16e6af9e by Li Liu

Modify the deployable's api for new database work

Change-Id: I9dee420890237485eba8fe9157a15741cdcb30f5
parent cb2b1b03
......@@ -42,44 +42,20 @@ class Deployable(base.APIBase):
uuid = types.uuid
"""The UUID of the deployable"""
name = wtypes.text
"""The name of the deployable"""
parent_uuid = types.uuid
"""The parent UUID 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"""
parent_id = types.integer
"""The parent ID of the deployable"""
board = wtypes.text
"""The board of the deployable"""
root_id = types.integer
"""The root ID 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"""
name = wtypes.text
"""The name of the deployable"""
instance_uuid = types.uuid
"""The UUID of the instance which deployable is assigned to"""
num_accelerators = types.integer
"""The number of accelerators of the deployable"""
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):
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)
# 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}
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:
......@@ -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):
def sample(cls):
return cls(field='interface_type',
return cls(field='name',
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):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment