def read_device(self, device_element: etree.Element) -> None: node_id = get_int(device_element, "id") name = device_element.get("name") model = device_element.get("type") icon = device_element.get("icon") clazz = device_element.get("class") image = device_element.get("image") server = device_element.get("server") options = NodeOptions(name=name, model=model, image=image, icon=icon, server=server) node_type = NodeTypes.DEFAULT if clazz == "docker": node_type = NodeTypes.DOCKER elif clazz == "lxc": node_type = NodeTypes.LXC _class = self.session.get_node_class(node_type) service_elements = device_element.find("services") if service_elements is not None: options.services = [ x.get("name") for x in service_elements.iterchildren() ] config_service_elements = device_element.find("configservices") if config_service_elements is not None: options.config_services = [ x.get("name") for x in config_service_elements.iterchildren() ] position_element = device_element.find("position") if position_element is not None: x = get_float(position_element, "x") y = get_float(position_element, "y") if all([x, y]): options.set_position(x, y) lat = get_float(position_element, "lat") lon = get_float(position_element, "lon") alt = get_float(position_element, "alt") if all([lat, lon, alt]): options.set_location(lat, lon, alt) logging.info("reading node id(%s) model(%s) name(%s)", node_id, model, name) self.session.add_node(_class, node_id, options)
from core.nodes.base import CoreNode from core.nodes.network import SwitchNode if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) # setup basic network prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16") options = NodeOptions(model=None) coreemu = CoreEmu() session = coreemu.create_session() session.set_state(EventTypes.CONFIGURATION_STATE) switch = session.add_node(SwitchNode) # node one options.config_services = ["DefaultRoute", "IPForward"] node1 = session.add_node(CoreNode, options=options) interface = prefixes.create_iface(node1) session.add_link(node1.id, switch.id, iface1_data=interface) # node two node2 = session.add_node(CoreNode, options=options) interface = prefixes.create_iface(node2) session.add_link(node2.id, switch.id, iface1_data=interface) # start session and run services session.instantiate() input("press enter to exit") session.shutdown()