2019-07-02 15:48:43 +01:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from core.emulator.coreemu import CoreEmu
|
|
|
|
from core.emulator.emudata import IpPrefixes, NodeOptions
|
2019-09-10 22:20:51 +01:00
|
|
|
from core.emulator.enumerations import EventTypes, NodeTypes
|
2019-07-02 15:48:43 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-10-14 22:28:18 +01:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2019-07-02 15:48:43 +01:00
|
|
|
|
|
|
|
coreemu = CoreEmu()
|
|
|
|
session = coreemu.create_session()
|
|
|
|
session.set_state(EventTypes.CONFIGURATION_STATE)
|
|
|
|
|
|
|
|
# create nodes and interfaces
|
|
|
|
try:
|
|
|
|
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
|
2019-10-14 22:28:18 +01:00
|
|
|
options = NodeOptions(image="ubuntu:18.04")
|
2019-07-02 15:48:43 +01:00
|
|
|
|
|
|
|
# create node one
|
2019-10-22 23:31:50 +01:00
|
|
|
node_one = session.add_node(_type=NodeTypes.LXC, options=options)
|
2019-07-02 15:48:43 +01:00
|
|
|
interface_one = prefixes.create_interface(node_one)
|
|
|
|
|
|
|
|
# create node two
|
2019-10-22 23:31:50 +01:00
|
|
|
node_two = session.add_node(_type=NodeTypes.LXC, options=options)
|
2019-07-02 15:48:43 +01:00
|
|
|
interface_two = prefixes.create_interface(node_two)
|
|
|
|
|
|
|
|
# add link
|
|
|
|
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
|
|
|
|
|
|
|
|
# instantiate
|
|
|
|
session.instantiate()
|
|
|
|
finally:
|
|
|
|
input("continue to shutdown")
|
|
|
|
coreemu.shutdown()
|