grpc: updates to wrapper classes to help write client code in a more simple way using the consolidated api, updated examples to used the wrapped client
This commit is contained in:
parent
38e162aec5
commit
917c45e70b
8 changed files with 196 additions and 235 deletions
|
@ -1,44 +1,29 @@
|
|||
# required imports
|
||||
from core.api.grpc import client
|
||||
from core.api.grpc.core_pb2 import Node, NodeType, Position, SessionState
|
||||
from core.api.grpc import clientw
|
||||
from core.api.grpc.wrappers import NodeType, Position
|
||||
|
||||
# interface helper
|
||||
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||
iface_helper = clientw.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
||||
|
||||
# create grpc client and connect
|
||||
core = client.CoreGrpcClient()
|
||||
core = clientw.CoreGrpcClient()
|
||||
core.connect()
|
||||
|
||||
# create session and get id
|
||||
response = core.create_session()
|
||||
session_id = response.session_id
|
||||
# add session
|
||||
session = core.add_session()
|
||||
|
||||
# change session state to configuration so that nodes get started when added
|
||||
core.set_session_state(session_id, SessionState.CONFIGURATION)
|
||||
|
||||
# create switch node
|
||||
# create nodes
|
||||
position = Position(x=200, y=200)
|
||||
switch = Node(type=NodeType.SWITCH, position=position)
|
||||
response = core.add_node(session_id, switch)
|
||||
switch_id = response.node_id
|
||||
|
||||
# create node one
|
||||
switch = session.add_node(1, _type=NodeType.SWITCH, position=position)
|
||||
position = Position(x=100, y=100)
|
||||
n1 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||
response = core.add_node(session_id, n1)
|
||||
n1_id = response.node_id
|
||||
|
||||
# create node two
|
||||
node1 = session.add_node(2, position=position)
|
||||
position = Position(x=300, y=100)
|
||||
n2 = Node(type=NodeType.DEFAULT, position=position, model="PC")
|
||||
response = core.add_node(session_id, n2)
|
||||
n2_id = response.node_id
|
||||
node2 = session.add_node(3, position=position)
|
||||
|
||||
# links nodes to switch
|
||||
iface1 = iface_helper.create_iface(n1_id, 0)
|
||||
core.add_link(session_id, n1_id, switch_id, iface1)
|
||||
iface1 = iface_helper.create_iface(n2_id, 0)
|
||||
core.add_link(session_id, n2_id, switch_id, iface1)
|
||||
# create links
|
||||
iface1 = iface_helper.create_iface(node1.id, 0)
|
||||
session.add_link(node1=node1, node2=switch, iface1=iface1)
|
||||
iface1 = iface_helper.create_iface(node2.id, 0)
|
||||
session.add_link(node1=node2, node2=switch, iface1=iface1)
|
||||
|
||||
# change session state
|
||||
core.set_session_state(session_id, SessionState.INSTANTIATION)
|
||||
# start session
|
||||
core.start_session(session)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue