2021-05-04 21:29:22 +01:00
|
|
|
from core.api.grpc import client
|
2021-05-03 23:25:18 +01:00
|
|
|
from core.api.grpc.wrappers import NodeType, Position
|
2019-03-31 03:01:11 +01:00
|
|
|
|
2020-09-12 07:49:26 +01:00
|
|
|
# interface helper
|
2021-05-04 21:29:22 +01:00
|
|
|
iface_helper = client.InterfaceHelper(ip4_prefix="10.0.0.0/24", ip6_prefix="2001::/64")
|
2020-09-12 07:49:26 +01:00
|
|
|
|
|
|
|
# create grpc client and connect
|
2021-05-04 21:29:22 +01:00
|
|
|
core = client.CoreGrpcClient()
|
2020-09-12 07:49:26 +01:00
|
|
|
core.connect()
|
|
|
|
|
2021-05-03 23:25:18 +01:00
|
|
|
# add session
|
2021-05-06 23:06:16 +01:00
|
|
|
session = core.create_session()
|
2020-09-12 07:49:26 +01:00
|
|
|
|
2021-05-03 23:25:18 +01:00
|
|
|
# create nodes
|
2020-09-12 07:49:26 +01:00
|
|
|
position = Position(x=200, y=200)
|
2021-05-03 23:25:18 +01:00
|
|
|
switch = session.add_node(1, _type=NodeType.SWITCH, position=position)
|
2020-09-12 07:49:26 +01:00
|
|
|
position = Position(x=100, y=100)
|
2021-05-03 23:25:18 +01:00
|
|
|
node1 = session.add_node(2, position=position)
|
2020-09-12 07:49:26 +01:00
|
|
|
position = Position(x=300, y=100)
|
2021-05-03 23:25:18 +01:00
|
|
|
node2 = session.add_node(3, position=position)
|
2020-09-12 07:49:26 +01:00
|
|
|
|
2021-05-03 23:25:18 +01:00
|
|
|
# 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)
|
2020-09-12 07:49:26 +01:00
|
|
|
|
2021-05-03 23:25:18 +01:00
|
|
|
# start session
|
|
|
|
core.start_session(session)
|