def __init__(self, master, app): super().__init__(master, app, "Hook", modal=True) self.name = tk.StringVar() self.codetext = None self.hook = core_pb2.Hook() self.state = tk.StringVar() self.draw()
def __init__(self, master: tk.BaseWidget, app: "Application"): super().__init__(app, "Hook", master=master) self.name = tk.StringVar() self.codetext = None self.hook = core_pb2.Hook() self.state = tk.StringVar() self.draw()
def __init__(self, master: tk.BaseWidget, app: "Application") -> None: super().__init__(app, "Hook", master=master) self.name: tk.StringVar = tk.StringVar() self.codetext: Optional[CodeText] = None self.hook: core_pb2.Hook = core_pb2.Hook() self.state: tk.StringVar = tk.StringVar() self.draw()
def get_hooks(session: Session) -> List[core_pb2.Hook]: hooks = [] for state in session.hooks: state_hooks = session.hooks[state] for file_name, file_data in state_hooks: hook = core_pb2.Hook(state=state.value, file=file_name, data=file_data) hooks.append(hook) return hooks
def GetHooks(self, request, context): logging.debug("get hooks: %s", request) session = self.get_session(request.session_id, context) hooks = [] for state in session._hooks: state_hooks = session._hooks[state] for file_name, file_data in state_hooks: hook = core_pb2.Hook(state=state, file=file_name, data=file_data) hooks.append(hook) return core_pb2.GetHooksResponse(hooks=hooks)
def add_hook(self, session_id, state, file_name, file_data): """ Add hook scripts. :param int session_id: session id :param core_pb2.SessionState state: state to trigger hook :param str file_name: name of file for hook script :param bytes file_data: hook script contents :return: response with result of success or failure :rtype: core_pb2.AddHookResponse :raises grpc.RpcError: when session doesn't exist """ hook = core_pb2.Hook(state=state, file=file_name, data=file_data) request = core_pb2.AddHookRequest(session_id=session_id, hook=hook) return self.stub.AddHook(request)
def to_proto(self) -> core_pb2.Hook: return core_pb2.Hook(state=self.state.value, file=self.file, data=self.data)
def test_start_session(self, grpc_server): # given client = CoreGrpcClient() session = grpc_server.coreemu.create_session() position = core_pb2.Position(x=50, y=100) node_one = core_pb2.Node(id=1, position=position, model="PC") position = core_pb2.Position(x=100, y=100) node_two = core_pb2.Node(id=2, position=position, model="PC") position = core_pb2.Position(x=200, y=200) wlan_node = core_pb2.Node(id=3, type=NodeTypes.WIRELESS_LAN.value, position=position) nodes = [node_one, node_two, wlan_node] interface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16") interface_one = interface_helper.create_interface(node_one.id, 0) interface_two = interface_helper.create_interface(node_two.id, 0) link = core_pb2.Link( type=core_pb2.LinkType.WIRED, node_one_id=node_one.id, node_two_id=node_two.id, interface_one=interface_one, interface_two=interface_two, ) links = [link] hook = core_pb2.Hook(state=core_pb2.SessionState.RUNTIME, file="echo.sh", data="echo hello") hooks = [hook] location_x = 5 location_y = 10 location_z = 15 location_lat = 20 location_lon = 30 location_alt = 40 location_scale = 5 location = core_pb2.SessionLocation( x=location_x, y=location_y, z=location_z, lat=location_lat, lon=location_lon, alt=location_alt, scale=location_scale, ) emane_config_key = "platform_id_start" emane_config_value = "2" emane_config = {emane_config_key: emane_config_value} model_node_id = 20 model_config_key = "bandwidth" model_config_value = "500000" model_config = core_pb2.EmaneModelConfig( node_id=model_node_id, interface_id=-1, model=EmaneIeee80211abgModel.name, config={model_config_key: model_config_value}, ) model_configs = [model_config] wlan_config_key = "range" wlan_config_value = "333" wlan_config = core_pb2.WlanConfig( node_id=wlan_node.id, config={wlan_config_key: wlan_config_value}) wlan_configs = [wlan_config] mobility_config_key = "refresh_ms" mobility_config_value = "60" mobility_config = core_pb2.MobilityConfig( node_id=wlan_node.id, config={mobility_config_key: mobility_config_value}) mobility_configs = [mobility_config] service_config = core_pb2.ServiceConfig(node_id=node_one.id, service="DefaultRoute", validate=["echo hello"]) service_configs = [service_config] service_file_config = core_pb2.ServiceFileConfig( node_id=node_one.id, service="DefaultRoute", file="defaultroute.sh", data="echo hello", ) service_file_configs = [service_file_config] # when with patch.object(CoreXmlWriter, "write"): with client.context_connect(): client.start_session( session.id, nodes, links, location, hooks, emane_config, model_configs, wlan_configs, mobility_configs, service_configs, service_file_configs, ) # then assert node_one.id in session.nodes assert node_two.id in session.nodes assert wlan_node.id in session.nodes assert session.nodes[node_one.id].netif(0) is not None assert session.nodes[node_two.id].netif(0) is not None hook_file, hook_data = session._hooks[core_pb2.SessionState.RUNTIME][0] assert hook_file == hook.file assert hook_data == hook.data assert session.location.refxyz == (location_x, location_y, location_z) assert session.location.refgeo == (location_lat, location_lon, location_alt) assert session.location.refscale == location_scale assert session.emane.get_config(emane_config_key) == emane_config_value set_wlan_config = session.mobility.get_model_config( wlan_node.id, BasicRangeModel.name) assert set_wlan_config[wlan_config_key] == wlan_config_value set_mobility_config = session.mobility.get_model_config( wlan_node.id, Ns2ScriptedMobility.name) assert set_mobility_config[ mobility_config_key] == mobility_config_value set_model_config = session.emane.get_model_config( model_node_id, EmaneIeee80211abgModel.name) assert set_model_config[model_config_key] == model_config_value service = session.services.get_service(node_one.id, service_config.service, default_service=True) assert service.validate == tuple(service_config.validate) service_file = session.services.get_service_file( node_one, service_file_config.service, service_file_config.file) assert service_file.data == service_file_config.data