Merge "Modify the deployable's api for new database work"

This commit is contained in:
Zuul 2019-03-07 02:53:46 +00:00 committed by Gerrit Code Review
commit 0b7324bbc9
2 changed files with 17 additions and 60 deletions

View File

@ -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:

View File

@ -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):