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 Position
|
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=100, y=100)
|
2021-05-03 23:25:18 +01:00
|
|
|
node1 = session.add_node(1, 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(2, position=position)
|
2020-09-12 07:49:26 +01:00
|
|
|
|
2021-05-03 23:25:18 +01:00
|
|
|
# create link
|
|
|
|
iface1 = iface_helper.create_iface(node1.id, 0)
|
|
|
|
iface2 = iface_helper.create_iface(node2.id, 0)
|
|
|
|
session.add_link(node1=node1, node2=node2, iface1=iface1, iface2=iface2)
|
2020-09-12 07:49:26 +01:00
|
|
|
|
2021-05-03 23:25:18 +01:00
|
|
|
# start session
|
|
|
|
core.start_session(session)
|