예제 #1
0
 def update(res_type, obj):
     if not obj.uuid:
         obj.uuid = VncApiMock.name_to_id(res_type, obj.name)
     if obj.uuid is None:
         raise NoIdError("Object does not exist.")
     if obj.uuid not in DBMock.get_dict(res_type.replace('-', '_')):
         raise NoIdError("Object does not exist.")
     DBMock.update(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj))
예제 #2
0
 def update(res_type, obj):
     if not obj.uuid:
         obj.uuid = VncApiMock.name_to_id(res_type, obj.name)
     if obj.uuid is None:
         raise NoIdError("Object does not exist.")
     if obj.uuid not in DBMock.get_dict(res_type.replace('-', '_')):
         raise NoIdError("Object does not exist.")
     DBMock.update(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj))
예제 #3
0
    def create(res_type, obj):
        if obj.name in VncApiMock.name_to_uuid.get(res_type):
            raise RefsExistError()
        obj.uuid = VncApiMock._alloc_uuid()

        DBMock.create(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj))
        VncApiMock.name_to_uuid.get(res_type)[obj.name] = obj.uuid
        return obj.uuid
예제 #4
0
    def create(res_type, obj):
        if obj.name in VncApiMock.name_to_uuid.get(res_type):
            raise RefsExistError()
        obj.uuid = VncApiMock._alloc_uuid()

        DBMock.create(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj))
        VncApiMock.name_to_uuid.get(res_type)[obj.name] = obj.uuid
        return obj.uuid
예제 #5
0
 def delete(res_type, fq_name=None, id=None, ifmap_id=None):
     (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name=fq_name, id=id)
     if not args_ok:
         return result
     id = result
     if id is None:
         raise NoIdError("Object does not exist.")
     obj = DBMock.read(res_type.replace('-', '_'), [id])
     VncApiMock.name_to_uuid.pop(obj.get_name())
     DBMock.delete(res_type.replace('-', '_'), id)
예제 #6
0
 def delete(res_type, fq_name=None, id=None, ifmap_id=None):
     (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name=fq_name, id=id)
     if not args_ok:
         return result
     id = result
     if id is None:
         raise NoIdError("Object does not exist.")
     obj = DBMock.read(res_type.replace('-', '_'), [id])
     VncApiMock.name_to_uuid.pop(obj.get_name())
     DBMock.delete(res_type.replace('-', '_'), id)
예제 #7
0
 def read(res_type, fq_name=None, fq_name_str=None, id=None, fields=None):
     (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name, fq_name_str, id)
     if not args_ok:
         return result
     id = result
     if id is None:
         raise NoIdError("Object does not exist.")
     ok, ret = DBMock.read(res_type.replace('-', '_'), [id])
     if (not ok) or (len(ret) < 1):
         raise NoIdError("Object does not exist.")
     return VncApiMock.object_from_dict(res_type, ret[0])
예제 #8
0
 def read(res_type, fq_name=None, fq_name_str=None, id=None, fields=None):
     (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name, fq_name_str, id)
     if not args_ok:
         return result
     id = result
     if id is None:
         raise NoIdError("Object does not exist.")
     ok, ret = DBMock.read(res_type.replace('-', '_'), [id])
     if (not ok) or (len(ret) < 1):
         raise NoIdError("Object does not exist.")
     return VncApiMock.object_from_dict(res_type, ret[0])
예제 #9
0
 def list(res_type, parent_id=None, parent_fq_name=None,
          obj_uuids=None, back_ref_id=None, fields=None,
          detail=False, count=False, filters=None, shared=False):
     ret = []
     for obj_dict in DBMock.get_dict(res_type.replace('-', '_')).values():
         obj = VncApiMock.object_from_dict(res_type, obj_dict)
         if parent_id is not None and parent_id != VncApiMock.name_to_uuid(obj.parent_name()):
             continue
         if parent_fq_name is not None and parent_fq_name != obj.get_parent_fq_name():
             continue
         if obj_uuids is not None and obj.uuid not in obj_uuids:
             continue
         ret.append(obj)
     return ret
예제 #10
0
 def list(res_type, parent_id=None, parent_fq_name=None,
          obj_uuids=None, back_ref_id=None, fields=None,
          detail=False, count=False, filters=None, shared=False):
     ret = []
     for obj_dict in DBMock.get_dict(res_type.replace('-', '_')).values():
         obj = VncApiMock.object_from_dict(res_type, obj_dict)
         if parent_id is not None and parent_id != VncApiMock.name_to_uuid(obj.parent_name()):
             continue
         if parent_fq_name is not None and parent_fq_name != obj.get_parent_fq_name():
             continue
         if obj_uuids is not None and obj.uuid not in obj_uuids:
             continue
         ret.append(obj)
     return ret
예제 #11
0
 def init():
     DBMock.init()
     VncApiMock.name_to_uuid = {}
     for object_type, resource_type in all_resource_type_tuples:
         VncApiMock.name_to_uuid[resource_type] = {}
     VncApiMock.next_uuid = 0
예제 #12
0
 def init():
     DBMock.init()
     VncApiMock.name_to_uuid = {}
     for object_type, resource_type in all_resource_type_tuples:
         VncApiMock.name_to_uuid[resource_type] = {}
     VncApiMock.next_uuid = 0