2019-06-27 23:45:35 +01:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from core.emulator.coreemu import CoreEmu
|
2022-05-25 18:51:42 +01:00
|
|
|
from core.emulator.data import IpPrefixes
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.emulator.enumerations import EventTypes
|
|
|
|
from core.nodes.docker import DockerNode
|
|
|
|
from core.nodes.network import SwitchNode
|
2019-06-27 23:45:35 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
|
|
|
|
|
|
|
try:
|
|
|
|
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
2019-06-28 23:41:55 +01:00
|
|
|
|
|
|
|
# create switch
|
2020-05-21 06:14:03 +01:00
|
|
|
switch = session.add_node(SwitchNode)
|
2019-06-28 23:41:55 +01:00
|
|
|
|
|
|
|
# node one
|
2022-05-25 18:51:42 +01:00
|
|
|
options = DockerNode.create_options()
|
|
|
|
options.image = "core"
|
|
|
|
options.binds.append(("/tmp/testbind", "/tmp/bind"))
|
|
|
|
options.volumes.append(("var.log", "/tmp/var.log", True, True))
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(DockerNode, options=options)
|
2020-06-16 17:30:16 +01:00
|
|
|
interface1_data = prefixes.create_iface(node1)
|
2019-06-28 23:41:55 +01:00
|
|
|
|
|
|
|
# node two
|
2020-06-13 00:52:41 +01:00
|
|
|
node2 = session.add_node(DockerNode, options=options)
|
2020-06-16 17:30:16 +01:00
|
|
|
interface2_data = prefixes.create_iface(node2)
|
2019-06-28 23:41:55 +01:00
|
|
|
|
|
|
|
# node three
|
2022-05-25 18:51:42 +01:00
|
|
|
# node_three = session.add_node(CoreNode)
|
|
|
|
# interface_three = prefixes.create_iface(node_three)
|
2019-06-27 23:45:35 +01:00
|
|
|
|
2019-06-28 23:41:55 +01:00
|
|
|
# add links
|
2020-06-13 00:52:41 +01:00
|
|
|
session.add_link(node1.id, switch.id, interface1_data)
|
|
|
|
session.add_link(node2.id, switch.id, interface2_data)
|
2022-05-25 18:51:42 +01:00
|
|
|
# session.add_link(node_three.id, switch.id, interface_three)
|
2019-06-28 23:41:55 +01:00
|
|
|
|
|
|
|
# instantiate
|
2019-06-28 16:17:11 +01:00
|
|
|
session.instantiate()
|
2022-05-25 18:51:42 +01:00
|
|
|
|
|
|
|
print(f"{node2.name}: {node2.volumes.values()}")
|
2019-06-27 23:45:35 +01:00
|
|
|
finally:
|
|
|
|
input("continue to shutdown")
|
|
|
|
coreemu.shutdown()
|