grpc updated create link/node to use the verbage add, to align with the actual python EmuSession class
This commit is contained in:
parent
6f428bd68a
commit
96d38e0b40
4 changed files with 25 additions and 25 deletions
|
@ -102,17 +102,17 @@ class CoreGrpcClient(object):
|
|||
stream = self.stub.FileEvents(request)
|
||||
start_streamer(stream, handler)
|
||||
|
||||
def create_node(self, session, _type=NodeTypes.DEFAULT, _id=None, node_options=None, emane=None):
|
||||
def add_node(self, session, _type=NodeTypes.DEFAULT, _id=None, node_options=None, emane=None):
|
||||
if not node_options:
|
||||
node_options = NodeOptions()
|
||||
position = core_pb2.Position(
|
||||
x=node_options.x, y=node_options.y,
|
||||
lat=node_options.lat, lon=node_options.lon, alt=node_options.alt)
|
||||
request = core_pb2.CreateNodeRequest(
|
||||
request = core_pb2.AddNodeRequest(
|
||||
session=session, type=_type.value, name=node_options.name,
|
||||
model=node_options.model, icon=node_options.icon, services=node_options.services,
|
||||
opaque=node_options.opaque, emane=emane, position=position)
|
||||
return self.stub.CreateNode(request)
|
||||
return self.stub.AddNode(request)
|
||||
|
||||
def get_node(self, session, _id):
|
||||
request = core_pb2.GetNodeRequest(session=session, id=_id)
|
||||
|
@ -133,7 +133,7 @@ class CoreGrpcClient(object):
|
|||
request = core_pb2.GetNodeLinksRequest(session=session, id=_id)
|
||||
return self.stub.GetNodeLinks(request)
|
||||
|
||||
def create_link(self, session, node_one, node_two, interface_one=None, interface_two=None, link_options=None):
|
||||
def add_link(self, session, node_one, node_two, interface_one=None, interface_two=None, link_options=None):
|
||||
interface_one_proto = None
|
||||
if interface_one is not None:
|
||||
interface_one_proto = core_pb2.Interface(
|
||||
|
@ -167,8 +167,8 @@ class CoreGrpcClient(object):
|
|||
link = core_pb2.Link(
|
||||
node_one=node_one, node_two=node_two, type=LinkTypes.WIRED.value,
|
||||
interface_one=interface_one_proto, interface_two=interface_two_proto, options=options)
|
||||
request = core_pb2.CreateLinkRequest(session=session, link=link)
|
||||
return self.stub.CreateLink(request)
|
||||
request = core_pb2.AddLinkRequest(session=session, link=link)
|
||||
return self.stub.AddLink(request)
|
||||
|
||||
def edit_link(self, session, node_one, node_two, link_options, interface_one=None, interface_two=None):
|
||||
options = core_pb2.LinkOptions(
|
||||
|
@ -375,7 +375,7 @@ def main():
|
|||
print("set session state: {}".format(client.set_session_state(session_data.id, EventTypes.CONFIGURATION_STATE)))
|
||||
|
||||
# create switch node
|
||||
response = client.create_node(session_data.id, _type=NodeTypes.SWITCH)
|
||||
response = client.add_node(session_data.id, _type=NodeTypes.SWITCH)
|
||||
print("created switch: {}".format(response))
|
||||
switch_id = response.id
|
||||
|
||||
|
@ -383,7 +383,7 @@ def main():
|
|||
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
||||
|
||||
for _ in xrange(2):
|
||||
response = client.create_node(session_data.id)
|
||||
response = client.add_node(session_data.id)
|
||||
print("created node: {}".format(response))
|
||||
node_id = response.id
|
||||
node_options = NodeOptions()
|
||||
|
@ -402,7 +402,7 @@ def main():
|
|||
ip4=str(prefixes.ip4.addr(node_id)), ip4_mask=prefixes.ip4.prefixlen,
|
||||
ip6=None, ip6_mask=None
|
||||
)
|
||||
print("created link: {}".format(client.create_link(session_data.id, node_id, switch_id, interface_one)))
|
||||
print("created link: {}".format(client.add_link(session_data.id, node_id, switch_id, interface_one)))
|
||||
link_options = LinkOptions()
|
||||
link_options.per = 50
|
||||
print("edit link: {}".format(client.edit_link(
|
||||
|
|
|
@ -527,8 +527,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
|
||||
self._cancel_stream(context)
|
||||
|
||||
def CreateNode(self, request, context):
|
||||
logging.debug("create node: %s", request)
|
||||
def AddNode(self, request, context):
|
||||
logging.debug("add node: %s", request)
|
||||
session = self.get_session(request.session, context)
|
||||
|
||||
node_id = request.id
|
||||
|
@ -552,7 +552,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
if emane_model:
|
||||
session.emane.set_model_config(node_id, emane_model)
|
||||
|
||||
return core_pb2.CreateNodeResponse(id=node.objid)
|
||||
return core_pb2.AddNodeResponse(id=node.objid)
|
||||
|
||||
def GetNode(self, request, context):
|
||||
logging.debug("get node: %s", request)
|
||||
|
@ -610,8 +610,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
links = get_links(session, node)
|
||||
return core_pb2.GetNodeLinksResponse(links=links)
|
||||
|
||||
def CreateLink(self, request, context):
|
||||
logging.debug("create link: %s", request)
|
||||
def AddLink(self, request, context):
|
||||
logging.debug("add link: %s", request)
|
||||
session = self.get_session(request.session, context)
|
||||
node_one = request.link.node_one
|
||||
node_two = request.link.node_two
|
||||
|
@ -675,7 +675,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
link_options.opaque = options_data.opaque
|
||||
|
||||
session.add_link(node_one, node_two, interface_one, interface_two, link_options=link_options)
|
||||
return core_pb2.CreateLinkResponse(result=True)
|
||||
return core_pb2.AddLinkResponse(result=True)
|
||||
|
||||
def EditLink(self, request, context):
|
||||
logging.debug("edit link: %s", request)
|
||||
|
|
|
@ -38,7 +38,7 @@ service CoreApi {
|
|||
}
|
||||
|
||||
// node rpc
|
||||
rpc CreateNode (CreateNodeRequest) returns (CreateNodeResponse) {
|
||||
rpc AddNode (AddNodeRequest) returns (AddNodeResponse) {
|
||||
}
|
||||
rpc GetNode (GetNodeRequest) returns (GetNodeResponse) {
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ service CoreApi {
|
|||
// link rpc
|
||||
rpc GetNodeLinks (GetNodeLinksRequest) returns (GetNodeLinksResponse) {
|
||||
}
|
||||
rpc CreateLink (CreateLinkRequest) returns (CreateLinkResponse) {
|
||||
rpc AddLink (AddLinkRequest) returns (AddLinkResponse) {
|
||||
}
|
||||
rpc EditLink (EditLinkRequest) returns (EditLinkResponse) {
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ message FileEvent {
|
|||
bytes compressed_data = 10;
|
||||
}
|
||||
|
||||
message CreateNodeRequest {
|
||||
message AddNodeRequest {
|
||||
int32 session = 1;
|
||||
int32 id = 2;
|
||||
NodeType type = 3;
|
||||
|
@ -292,7 +292,7 @@ message CreateNodeRequest {
|
|||
string opaque = 10;
|
||||
}
|
||||
|
||||
message CreateNodeResponse {
|
||||
message AddNodeResponse {
|
||||
int32 id = 1;
|
||||
}
|
||||
|
||||
|
@ -334,12 +334,12 @@ message GetNodeLinksResponse {
|
|||
repeated Link links = 1;
|
||||
}
|
||||
|
||||
message CreateLinkRequest {
|
||||
message AddLinkRequest {
|
||||
int32 session = 1;
|
||||
Link link = 2;
|
||||
}
|
||||
|
||||
message CreateLinkResponse {
|
||||
message AddLinkResponse {
|
||||
bool result = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,14 +170,14 @@ class TestGrpc:
|
|||
assert response.result is True
|
||||
assert session.state == EventTypes.DEFINITION_STATE.value
|
||||
|
||||
def test_create_node(self, grpc_server):
|
||||
def test_add_node(self, grpc_server):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
response = client.create_node(session.session_id)
|
||||
response = client.add_node(session.session_id)
|
||||
|
||||
# then
|
||||
assert response.id is not None
|
||||
|
@ -306,7 +306,7 @@ class TestGrpc:
|
|||
# then
|
||||
assert len(response.links) == 1
|
||||
|
||||
def test_create_link(self, grpc_server, ip_prefixes):
|
||||
def test_add_link(self, grpc_server, ip_prefixes):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
|
@ -317,7 +317,7 @@ class TestGrpc:
|
|||
# then
|
||||
interface = ip_prefixes.create_interface(node)
|
||||
with client.context_connect():
|
||||
response = client.create_link(session.session_id, node.objid, switch.objid, interface)
|
||||
response = client.add_link(session.session_id, node.objid, switch.objid, interface)
|
||||
|
||||
# then
|
||||
assert response.result is True
|
||||
|
|
Loading…
Reference in a new issue