示例#1
0
    def test_proto_dict_with_exts(self, data):
        msg, expected_dict = data.values

        msg.Extensions[test_pb2.number] = 11
        msg.Extensions[test_pb2.name] = 'abiko'

        expected_dict['extensions'] = {'number': 11, 'name': 'abiko'}
        self.assertEqual(expected_dict, utils.proto_to_dict(msg))
示例#2
0
    def test_proto_dict_with_exts(self, data):
        msg, expected_dict = data.values

        msg.Extensions[test_pb2.number] = 11
        msg.Extensions[test_pb2.name] = 'abiko'

        expected_dict['extensions'] = {'number': 11, 'name': 'abiko'}
        self.assertEqual(expected_dict, utils.proto_to_dict(msg))
示例#3
0
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
示例#4
0
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
示例#5
0
def handshake(sock, cnxn_id, req_id):
    """Performs the initial handshake operation with the topology server"""
    sock.send(utils.encode_delimited(_handshake_msg(cnxn_id, req_id).SerializeToString()))
    response = topology_api_pb2.Response()
    try:
        response.ParseFromString(utils.get_answer(sock))
    except socket.timeout:
        issue = "Timed out receiving Handshake protobuf response"
        LOG.exception(issue)
        raise TopologyError(issue)
    except PBDecodeError:
        issue = "Failed to parse Handshake protobuf response"
        LOG.exception(issue)
        raise TopologyError(issue)
    if response.type != topology_api_pb2.ResponseType.Value("ACK"):
        raise HandshakeError(
            "Failed to handshake with the topology API. Got response %s" % utils.proto_to_dict(response)
        )
示例#6
0
def handshake(sock, cnxn_id, req_id):
    """Performs the initial handshake operation with the topology server"""
    sock.send(
        utils.encode_delimited(
            _handshake_msg(cnxn_id, req_id).SerializeToString()))
    response = topology_api_pb2.Response()
    try:
        response.ParseFromString(utils.get_answer(sock))
    except socket.timeout:
        issue = 'Timed out receiving Handshake protobuf response'
        LOG.exception(issue)
        raise TopologyError(issue)
    except PBDecodeError:
        issue = 'Failed to parse Handshake protobuf response'
        LOG.exception(issue)
        raise TopologyError(issue)
    if response.type != topology_api_pb2.ResponseType.Value('ACK'):
        raise HandshakeError(
            'Failed to handshake with the topology API. Got response %s' %
            utils.proto_to_dict(response))
示例#7
0
def get_all_dict(sock):
    for response in get_all(sock):
        yield utils.proto_to_dict(response.update.host,
                                  message_type_map=msg_type_map)
示例#8
0
def get_dict(sock, obj_uuid):
    """Returns the Host dict that corresponds to the specified uuid string"""
    return utils.proto_to_dict(
        get(sock, obj_uuid=uuid.UUID(hex=obj_uuid)).update.host,
        message_type_map=msg_type_map)
示例#9
0
 def test_proto_dict(self, data):
     msg, expected_dict = data.values
     self.assertEqual(expected_dict, utils.proto_to_dict(msg))
示例#10
0
 def test_proto_dict(self, data):
     msg, expected_dict = data.values
     self.assertEqual(expected_dict, utils.proto_to_dict(msg))