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))
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
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) )
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))
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)
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)
def test_proto_dict(self, data): msg, expected_dict = data.values self.assertEqual(expected_dict, utils.proto_to_dict(msg))