def get_all(sock, kind, req_id=None): """Generates Protobuf Response object for a Request.Get snapshot command""" if req_id is None: req_id = uuid.uuid4() response = get(sock, kind, obj_uuid=None, req_id=req_id) if response.type != topology_api_pb2.ResponseType.Value('SNAPSHOT'): raise SnapshotError( 'Failed to get snapshot from the topology API. Got response: %s' % utils.proto_to_dict(response)) for obj_id in response.snapshot.obj_ids: py_uuid = utils.uuid_to_UUID(obj_id) obj_response = get(sock, kind, obj_uuid=py_uuid, req_id=req_id) if obj_response.type != topology_api_pb2.ResponseType.Value('UPDATE'): raise UpdateError( 'Failed to get object %s from the topology API. Got response: ' '%s' % (py_uuid, utils.proto_to_dict(obj_response))) yield obj_response
def get_all(sock, kind, req_id=None): """Generates Protobuf Response object for a Request.Get snapshot command""" if req_id is None: req_id = uuid.uuid4() response = get(sock, kind, obj_uuid=None, req_id=req_id) if response.type != topology_api_pb2.ResponseType.Value("SNAPSHOT"): raise SnapshotError( "Failed to get snapshot from the topology API. Got response: %s" % utils.proto_to_dict(response) ) for obj_id in response.snapshot.obj_ids: py_uuid = utils.uuid_to_UUID(obj_id) obj_response = get(sock, kind, obj_uuid=py_uuid, req_id=req_id) if obj_response.type != topology_api_pb2.ResponseType.Value("UPDATE"): raise UpdateError( "Failed to get object %s from the topology API. Got response: " "%s" % (py_uuid, utils.proto_to_dict(obj_response)) ) yield obj_response
return request def _get_msg(req_id, kind, obj_uuid): """Msg for fetching resources from the topology api with the specified type Returns: - A topology_pb2.update object if obj_uuid is specified, or - a topology_api_pb2.Response.snapshot of all the uuids of the specified kind. """ request = topology_api_pb2.Request() request.get.req_id.msb, request.get.req_id.lsb = utils.split_uuid(req_id) request.get.type = kind if obj_uuid is not None: request.get.id.msb, request.get.id.lsb = utils.split_uuid(obj_uuid) return request _get_all_msg = functools.partial(_get_msg, obj_uuid=None) # Common convenient conversions that may be used by topology response # conversion to common python types. msg_type_map = { "org.midonet.cluster.models.IPAddress.version": lambda x: {"V4": 4, "V6": 6}.get(x), "org.midonet.cluster.models.UUID": lambda x: str(utils.uuid_to_UUID(x)), } TYPE = dict(topology_pb2.Type.items())
def _get_msg(req_id, kind, obj_uuid): """Msg for fetching resources from the topology api with the specified type Returns: - A topology_pb2.update object if obj_uuid is specified, or - a topology_api_pb2.Response.snapshot of all the uuids of the specified kind. """ request = topology_api_pb2.Request() request.get.req_id.msb, request.get.req_id.lsb = (utils.split_uuid(req_id)) request.get.type = kind if obj_uuid is not None: request.get.id.msb, request.get.id.lsb = utils.split_uuid(obj_uuid) return request _get_all_msg = functools.partial(_get_msg, obj_uuid=None) # Common convenient conversions that may be used by topology response # conversion to common python types. msg_type_map = { 'org.midonet.cluster.models.IPAddress.version': lambda x: { 'V4': 4, 'V6': 6 }.get(x), 'org.midonet.cluster.models.UUID': lambda x: str(utils.uuid_to_UUID(x)) } TYPE = dict(topology_pb2.Type.items())