pygui: updates to leveraged wrapped grpc client for proper type hinting without manual conversion
This commit is contained in:
parent
be0e0175a2
commit
f7f54d9aa6
11 changed files with 160 additions and 294 deletions
|
@ -66,6 +66,7 @@ from core.api.grpc.wlan_pb2 import (
|
|||
WlanConfig,
|
||||
WlanLinkRequest,
|
||||
)
|
||||
from core.api.grpc.wrappers import Hook
|
||||
from core.emulator.data import IpPrefixes
|
||||
|
||||
|
||||
|
@ -859,25 +860,16 @@ class CoreGrpcClient:
|
|||
hooks.append(hook)
|
||||
return hooks
|
||||
|
||||
def add_hook(
|
||||
self,
|
||||
session_id: int,
|
||||
state: wrappers.SessionState,
|
||||
file_name: str,
|
||||
file_data: str,
|
||||
) -> bool:
|
||||
def add_hook(self, session_id: int, hook: Hook) -> bool:
|
||||
"""
|
||||
Add hook scripts.
|
||||
|
||||
:param session_id: session id
|
||||
:param state: state to trigger hook
|
||||
:param file_name: name of file for hook script
|
||||
:param file_data: hook script contents
|
||||
:param hook: hook to add
|
||||
:return: True for success, False otherwise
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
hook = core_pb2.Hook(state=state.value, file=file_name, data=file_data)
|
||||
request = core_pb2.AddHookRequest(session_id=session_id, hook=hook)
|
||||
request = core_pb2.AddHookRequest(session_id=session_id, hook=hook.to_proto())
|
||||
response = self.stub.AddHook(request)
|
||||
return response.result
|
||||
|
||||
|
@ -1277,7 +1269,7 @@ class CoreGrpcClient:
|
|||
|
||||
:param file_path: path of scenario XML file
|
||||
:param start: tuple of result and session id when successful
|
||||
:return: response with opened session id
|
||||
:return: tuple of result and session id
|
||||
"""
|
||||
with open(file_path, "r") as xml_file:
|
||||
data = xml_file.read()
|
||||
|
|
|
@ -171,15 +171,16 @@ class ConfigServiceData:
|
|||
class ConfigServiceDefaults:
|
||||
templates: Dict[str, str]
|
||||
config: Dict[str, "ConfigOption"]
|
||||
modes: List[str]
|
||||
modes: Dict[str, Dict[str, str]]
|
||||
|
||||
@classmethod
|
||||
def from_proto(
|
||||
cls, proto: configservices_pb2.GetConfigServicesResponse
|
||||
) -> "ConfigServiceDefaults":
|
||||
config = ConfigOption.from_dict(proto.config)
|
||||
modes = {x.name: dict(x.config) for x in proto.modes}
|
||||
return ConfigServiceDefaults(
|
||||
templates=dict(proto.templates), config=config, modes=list(proto.modes)
|
||||
templates=dict(proto.templates), config=config, modes=modes
|
||||
)
|
||||
|
||||
|
||||
|
@ -598,11 +599,12 @@ class EmaneModelConfig:
|
|||
)
|
||||
|
||||
def to_proto(self) -> emane_pb2.EmaneModelConfig:
|
||||
config = ConfigOption.to_dict(self.config)
|
||||
return emane_pb2.EmaneModelConfig(
|
||||
node_id=self.node_id,
|
||||
model=self.model,
|
||||
iface_id=self.iface_id,
|
||||
config=self.config,
|
||||
config=config,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue