def __init__( self, master: Any, app: "Application", canvas_node: "CanvasNode", services: Set[str] = None, ): title = f"{canvas_node.core_node.name} Services" super().__init__(master, app, title, modal=True) self.app = app self.canvas_node = canvas_node self.node_id = canvas_node.core_node.id self.groups = None self.services = None self.current = None if services is None: services = canvas_node.core_node.services model = canvas_node.core_node.model if len(services) == 0: # not custom node type and node's services haven't been modified before if not NodeUtils.is_custom( canvas_node.core_node.model ) and not self.app.core.service_been_modified(self.node_id): services = set(self.app.core.default_services[model]) # services of default type nodes were modified to be empty elif canvas_node.core_node.id in self.app.core.modified_service_nodes: services = set() else: services = set( NodeUtils.get_custom_node_services( self.app.guiconfig, model)) else: services = set(services) self.current_services = services self.draw()
def create_node(self, x: float, y: float, node_type: NodeType, model: str) -> Optional[Node]: """ Add node, with information filled in, to grpc manager """ node_id = self.next_node_id() position = Position(x=x, y=y) image = None if NodeUtils.is_image_node(node_type): image = "ubuntu:latest" emane = None if node_type == NodeType.EMANE: if not self.session.emane_models: dialog = EmaneInstallDialog(self.app) dialog.show() return emane = self.session.emane_models[0] name = f"emane{node_id}" elif node_type == NodeType.WIRELESS_LAN: name = f"wlan{node_id}" elif node_type in [NodeType.RJ45, NodeType.TUNNEL]: name = "unassigned" else: name = f"n{node_id}" node = Node( id=node_id, type=node_type, name=name, model=model, position=position, image=image, emane=emane, ) if NodeUtils.is_custom(node_type, model): services = NodeUtils.get_custom_node_services( self.app.guiconfig, model) node.services[:] = services # assign default services to CORE node else: services = self.session.default_services.get(model) if services: node.services = services.copy() logging.info( "add node(%s) to session(%s), coordinates(%s, %s)", node.name, self.session.id, x, y, ) self.session.nodes[node.id] = node return node
def create_node( self, x: float, y: float, node_type: core_pb2.NodeType, model: str ) -> core_pb2.Node: """ Add node, with information filled in, to grpc manager """ node_id = self.next_node_id() position = core_pb2.Position(x=x, y=y) image = None if NodeUtils.is_image_node(node_type): image = "ubuntu:latest" emane = None if node_type == core_pb2.NodeType.EMANE: emane = self.emane_models[0] name = f"EMANE{node_id}" elif node_type == core_pb2.NodeType.WIRELESS_LAN: name = f"WLAN{node_id}" elif node_type in [core_pb2.NodeType.RJ45, core_pb2.NodeType.TUNNEL]: name = "UNASSIGNED" else: name = f"n{node_id}" node = core_pb2.Node( id=node_id, type=node_type, name=name, model=model, position=position, image=image, emane=emane, ) if NodeUtils.is_custom(node_type, model): services = NodeUtils.get_custom_node_services(self.app.guiconfig, model) node.services[:] = services logging.info( "add node(%s) to session(%s), coordinates(%s, %s)", node.name, self.session_id, x, y, ) return node