def get_object_with_id(owner, rid, rtype, *args, **kwargs):
query = {}
if rtype in ['machine', 'network', 'image', 'location']:
if 'cloud_id' not in kwargs:
raise RequiredParameterMissingError('No cloud id provided')
else:
query.update({'cloud': kwargs['cloud_id']})
if rtype == 'machine':
query.update({'machine_id': rid})
else:
query.update({'id': rid, 'deleted': None})
if rtype not in ['machine', 'image']:
query.update({'owner': owner})
try:
resource_obj = get_resource_model(rtype).objects.get(**query)
except DoesNotExist:
raise NotFoundError('Resource with this id could not be located')
return resource_obj
评论列表
文章目录