removed rtype and param typing from doc strings to help avoid maintaining duplicate information provided by type hints
This commit is contained in:
parent
9d89877b20
commit
f4ddf310a8
32 changed files with 1091 additions and 1357 deletions
|
@ -90,9 +90,9 @@ class Session:
|
|||
"""
|
||||
Create a Session instance.
|
||||
|
||||
:param int _id: session id
|
||||
:param dict config: session configuration
|
||||
:param bool mkdir: flag to determine if a directory should be made
|
||||
:param _id: session id
|
||||
:param config: session configuration
|
||||
:param mkdir: flag to determine if a directory should be made
|
||||
"""
|
||||
self.id = _id
|
||||
|
||||
|
@ -166,7 +166,7 @@ class Session:
|
|||
"""
|
||||
Retrieve the class for a given node type.
|
||||
|
||||
:param core.emulator.enumerations.NodeTypes _type: node type to get class for
|
||||
:param _type: node type to get class for
|
||||
:return: node class
|
||||
"""
|
||||
node_class = NODES.get(_type)
|
||||
|
@ -181,8 +181,7 @@ class Session:
|
|||
|
||||
:param _class: node class to get a node type for
|
||||
:return: node type
|
||||
:rtype: core.emulator.enumerations.NodeTypes
|
||||
:raises CoreError: when node type does not exist
|
||||
:raises CoreError: when node type does not exist
|
||||
"""
|
||||
node_type = NODES_TYPE.get(_class)
|
||||
if node_type is None:
|
||||
|
@ -197,11 +196,10 @@ class Session:
|
|||
"""
|
||||
Convenience method for retrieving nodes within link data.
|
||||
|
||||
:param int node_one_id: node one id
|
||||
:param int node_two_id: node two id
|
||||
:param node_one_id: node one id
|
||||
:param node_two_id: node two id
|
||||
:return: nodes, network nodes if present, and tunnel if present
|
||||
:rtype: tuple
|
||||
"""
|
||||
"""
|
||||
logging.debug(
|
||||
"link message between node1(%s) and node2(%s)", node_one_id, node_two_id
|
||||
)
|
||||
|
@ -258,8 +256,8 @@ class Session:
|
|||
"""
|
||||
Objects to deal with when connecting/disconnecting wireless links.
|
||||
|
||||
:param list objects: possible objects to deal with
|
||||
:param bool connect: link interfaces if True, unlink otherwise
|
||||
:param objects: possible objects to deal with
|
||||
:param connect: link interfaces if True, unlink otherwise
|
||||
:return: nothing
|
||||
:raises core.CoreError: when objects to link is less than 2, or no common
|
||||
networks are found
|
||||
|
@ -304,13 +302,13 @@ class Session:
|
|||
"""
|
||||
Add a link between nodes.
|
||||
|
||||
:param int node_one_id: node one id
|
||||
:param int node_two_id: node two id
|
||||
:param core.emulator.emudata.InterfaceData interface_one: node one interface
|
||||
:param node_one_id: node one id
|
||||
:param node_two_id: node two id
|
||||
:param interface_one: node one interface
|
||||
data, defaults to none
|
||||
:param core.emulator.emudata.InterfaceData interface_two: node two interface
|
||||
:param interface_two: node two interface
|
||||
data, defaults to none
|
||||
:param core.emulator.emudata.LinkOptions link_options: data for creating link,
|
||||
:param link_options: data for creating link,
|
||||
defaults to no options
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -436,11 +434,11 @@ class Session:
|
|||
"""
|
||||
Delete a link between nodes.
|
||||
|
||||
:param int node_one_id: node one id
|
||||
:param int node_two_id: node two id
|
||||
:param int interface_one_id: interface id for node one
|
||||
:param int interface_two_id: interface id for node two
|
||||
:param core.emulator.enumerations.LinkTypes link_type: link type to delete
|
||||
:param node_one_id: node one id
|
||||
:param node_two_id: node two id
|
||||
:param interface_one_id: interface id for node one
|
||||
:param interface_two_id: interface id for node two
|
||||
:param link_type: link type to delete
|
||||
:return: nothing
|
||||
:raises core.CoreError: when no common network is found for link being deleted
|
||||
"""
|
||||
|
@ -542,11 +540,11 @@ class Session:
|
|||
"""
|
||||
Update link information between nodes.
|
||||
|
||||
:param int node_one_id: node one id
|
||||
:param int node_two_id: node two id
|
||||
:param int interface_one_id: interface id for node one
|
||||
:param int interface_two_id: interface id for node two
|
||||
:param core.emulator.emudata.LinkOptions link_options: data to update link with
|
||||
:param node_one_id: node one id
|
||||
:param node_two_id: node two id
|
||||
:param interface_one_id: interface id for node one
|
||||
:param interface_two_id: interface id for node two
|
||||
:param link_options: data to update link with
|
||||
:return: nothing
|
||||
:raises core.CoreError: when updating a wireless type link, when there is a unknown
|
||||
link between networks
|
||||
|
@ -654,10 +652,10 @@ class Session:
|
|||
"""
|
||||
Add a node to the session, based on the provided node data.
|
||||
|
||||
:param core.emulator.enumerations.NodeTypes _type: type of node to create
|
||||
:param int _id: id for node, defaults to None for generated id
|
||||
:param core.emulator.emudata.NodeOptions options: data to create node with
|
||||
:param class _cls: optional custom class to use for a created node
|
||||
:param _type: type of node to create
|
||||
:param _id: id for node, defaults to None for generated id
|
||||
:param options: data to create node with
|
||||
:param _cls: optional custom class to use for a created node
|
||||
:return: created node
|
||||
:raises core.CoreError: when an invalid node type is given
|
||||
"""
|
||||
|
@ -748,11 +746,10 @@ class Session:
|
|||
"""
|
||||
Edit node information.
|
||||
|
||||
:param int node_id: id of node to update
|
||||
:param core.emulator.emudata.NodeOptions options: data to update node with
|
||||
:param node_id: id of node to update
|
||||
:param options: data to update node with
|
||||
:return: True if node updated, False otherwise
|
||||
:rtype: nothing
|
||||
:raises core.CoreError: when node to update does not exist
|
||||
:raises core.CoreError: when node to update does not exist
|
||||
"""
|
||||
# get node to update
|
||||
node = self.get_node(node_id)
|
||||
|
@ -769,7 +766,7 @@ class Session:
|
|||
Set position for a node, use lat/lon/alt if needed.
|
||||
|
||||
:param node: node to set position for
|
||||
:param core.emulator.emudata.NodeOptions options: data for node
|
||||
:param options: data for node
|
||||
:return: nothing
|
||||
"""
|
||||
# extract location values
|
||||
|
@ -798,7 +795,7 @@ class Session:
|
|||
"""
|
||||
Broadcast node location to all listeners.
|
||||
|
||||
:param core.nodes.base.NodeBase node: node to broadcast location for
|
||||
:param node: node to broadcast location for
|
||||
:return: nothing
|
||||
"""
|
||||
node_data = NodeData(
|
||||
|
@ -813,7 +810,7 @@ class Session:
|
|||
"""
|
||||
Start mobility for the provided node ids.
|
||||
|
||||
:param list[int] node_ids: nodes to start mobility for
|
||||
:param node_ids: nodes to start mobility for
|
||||
:return: nothing
|
||||
"""
|
||||
self.mobility.startup(node_ids)
|
||||
|
@ -835,8 +832,8 @@ class Session:
|
|||
"""
|
||||
Import a session from the EmulationScript XML format.
|
||||
|
||||
:param str file_name: xml file to load session from
|
||||
:param bool start: instantiate session if true, false otherwise
|
||||
:param file_name: xml file to load session from
|
||||
:param start: instantiate session if true, false otherwise
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("opening xml: %s", file_name)
|
||||
|
@ -863,7 +860,7 @@ class Session:
|
|||
"""
|
||||
Export a session to the EmulationScript XML format.
|
||||
|
||||
:param str file_name: file name to write session xml to
|
||||
:param file_name: file name to write session xml to
|
||||
:return: nothing
|
||||
"""
|
||||
CoreXmlWriter(self).write(file_name)
|
||||
|
@ -872,9 +869,9 @@ class Session:
|
|||
"""
|
||||
Store a hook from a received file message.
|
||||
|
||||
:param int state: when to run hook
|
||||
:param str file_name: file name for hook
|
||||
:param str source_name: source name
|
||||
:param state: when to run hook
|
||||
:param file_name: file name for hook
|
||||
:param source_name: source name
|
||||
:param data: hook data
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -888,10 +885,10 @@ class Session:
|
|||
"""
|
||||
Add a file to a node.
|
||||
|
||||
:param int node_id: node to add file to
|
||||
:param str source_name: source file name
|
||||
:param str file_name: file name to add
|
||||
:param str data: file data
|
||||
:param node_id: node to add file to
|
||||
:param source_name: source file name
|
||||
:param file_name: file name to add
|
||||
:param data: file data
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -930,7 +927,7 @@ class Session:
|
|||
"""
|
||||
Handle a mobility event.
|
||||
|
||||
:param core.emulator.data.EventData event_data: event data to handle
|
||||
:param event_data: event data to handle
|
||||
:return: nothing
|
||||
"""
|
||||
self.mobility.handleevent(event_data)
|
||||
|
@ -939,10 +936,10 @@ class Session:
|
|||
"""
|
||||
Set session geospatial location.
|
||||
|
||||
:param float lat: latitude
|
||||
:param float lon: longitude
|
||||
:param float alt: altitude
|
||||
:param float scale: reference scale
|
||||
:param lat: latitude
|
||||
:param lon: longitude
|
||||
:param alt: altitude
|
||||
:param scale: reference scale
|
||||
:return: nothing
|
||||
"""
|
||||
self.location.setrefgeo(lat, lon, alt)
|
||||
|
@ -975,7 +972,7 @@ class Session:
|
|||
"""
|
||||
Handle event data that should be provided to event handler.
|
||||
|
||||
:param core.data.EventData event_data: event data to send out
|
||||
:param event_data: event data to send out
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -986,7 +983,7 @@ class Session:
|
|||
"""
|
||||
Handle exception data that should be provided to exception handlers.
|
||||
|
||||
:param core.emulator.data.ExceptionData exception_data: exception data to send out
|
||||
:param exception_data: exception data to send out
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -997,7 +994,7 @@ class Session:
|
|||
"""
|
||||
Handle node data that should be provided to node handlers.
|
||||
|
||||
:param core.emulator.data.ExceptionData node_data: node data to send out
|
||||
:param node_data: node data to send out
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -1008,7 +1005,7 @@ class Session:
|
|||
"""
|
||||
Handle file data that should be provided to file handlers.
|
||||
|
||||
:param core.data.FileData file_data: file data to send out
|
||||
:param file_data: file data to send out
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -1019,7 +1016,7 @@ class Session:
|
|||
"""
|
||||
Handle config data that should be provided to config handlers.
|
||||
|
||||
:param core.emulator.data.ConfigData config_data: config data to send out
|
||||
:param config_data: config data to send out
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -1030,7 +1027,7 @@ class Session:
|
|||
"""
|
||||
Handle link data that should be provided to link handlers.
|
||||
|
||||
:param core.emulator.data.ExceptionData link_data: link data to send out
|
||||
:param link_data: link data to send out
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -1041,7 +1038,7 @@ class Session:
|
|||
"""
|
||||
Set the session's current state.
|
||||
|
||||
:param core.enumerations.EventTypes state: state to set to
|
||||
:param state: state to set to
|
||||
:param send_event: if true, generate core API event messages
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -1072,7 +1069,7 @@ class Session:
|
|||
"""
|
||||
Write the current state to a state file in the session dir.
|
||||
|
||||
:param int state: state to write to file
|
||||
:param state: state to write to file
|
||||
:return: nothing
|
||||
"""
|
||||
try:
|
||||
|
@ -1087,7 +1084,7 @@ class Session:
|
|||
Run hook scripts upon changing states. If hooks is not specified, run all hooks
|
||||
in the given state.
|
||||
|
||||
:param int state: state to run hooks for
|
||||
:param state: state to run hooks for
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
|
@ -1111,10 +1108,10 @@ class Session:
|
|||
"""
|
||||
Store a hook from a received file message.
|
||||
|
||||
:param str hook_type: hook type
|
||||
:param str file_name: file name for hook
|
||||
:param str source_name: source name
|
||||
:param str data: hook data
|
||||
:param hook_type: hook type
|
||||
:param file_name: file name for hook
|
||||
:param source_name: source name
|
||||
:param data: hook data
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info(
|
||||
|
@ -1149,7 +1146,7 @@ class Session:
|
|||
"""
|
||||
Run a hook.
|
||||
|
||||
:param tuple hook: hook to run
|
||||
:param hook: hook to run
|
||||
:return: nothing
|
||||
"""
|
||||
file_name, data = hook
|
||||
|
@ -1190,7 +1187,7 @@ class Session:
|
|||
"""
|
||||
Run state hooks.
|
||||
|
||||
:param int state: state to run hooks for
|
||||
:param state: state to run hooks for
|
||||
:return: nothing
|
||||
"""
|
||||
for hook in self._state_hooks.get(state, []):
|
||||
|
@ -1210,8 +1207,8 @@ class Session:
|
|||
"""
|
||||
Add a state hook.
|
||||
|
||||
:param int state: state to add hook for
|
||||
:param func hook: hook callback for the state
|
||||
:param state: state to add hook for
|
||||
:param hook: hook callback for the state
|
||||
:return: nothing
|
||||
"""
|
||||
hooks = self._state_hooks.setdefault(state, [])
|
||||
|
@ -1226,8 +1223,8 @@ class Session:
|
|||
"""
|
||||
Delete a state hook.
|
||||
|
||||
:param int state: state to delete hook for
|
||||
:param func hook: hook to delete
|
||||
:param state: state to delete hook for
|
||||
:param hook: hook to delete
|
||||
:return: nothing
|
||||
"""
|
||||
hooks = self._state_hooks.setdefault(state, [])
|
||||
|
@ -1237,7 +1234,7 @@ class Session:
|
|||
"""
|
||||
Runtime state hook check.
|
||||
|
||||
:param int state: state to check
|
||||
:param state: state to check
|
||||
:return: nothing
|
||||
"""
|
||||
if state == EventTypes.RUNTIME_STATE.value:
|
||||
|
@ -1255,10 +1252,9 @@ class Session:
|
|||
This is the current process environment with some session-specific
|
||||
variables.
|
||||
|
||||
:param bool state: flag to determine if session state should be included
|
||||
:param state: flag to determine if session state should be included
|
||||
:return: environment variables
|
||||
:rtype: dict
|
||||
"""
|
||||
"""
|
||||
env = os.environ.copy()
|
||||
env["SESSION"] = str(self.id)
|
||||
env["SESSION_SHORT"] = self.short_session_id()
|
||||
|
@ -1301,7 +1297,7 @@ class Session:
|
|||
"""
|
||||
Set the thumbnail filename. Move files from /tmp to session dir.
|
||||
|
||||
:param str thumb_file: tumbnail file to set for session
|
||||
:param thumb_file: tumbnail file to set for session
|
||||
:return: nothing
|
||||
"""
|
||||
if not os.path.exists(thumb_file):
|
||||
|
@ -1318,7 +1314,7 @@ class Session:
|
|||
Set the username for this session. Update the permissions of the
|
||||
session dir to allow the user write access.
|
||||
|
||||
:param str user: user to give write permissions to for the session directory
|
||||
:param user: user to give write permissions to for the session directory
|
||||
:return: nothing
|
||||
"""
|
||||
if user:
|
||||
|
@ -1346,9 +1342,9 @@ class Session:
|
|||
"""
|
||||
Create an emulation node.
|
||||
|
||||
:param class cls: node class to create
|
||||
:param list args: list of arguments for the class to create
|
||||
:param dict kwargs: dictionary of arguments for the class to create
|
||||
:param cls: node class to create
|
||||
:param args: list of arguments for the class to create
|
||||
:param kwargs: dictionary of arguments for the class to create
|
||||
:return: the created node instance
|
||||
:raises core.CoreError: when id of the node to create already exists
|
||||
"""
|
||||
|
@ -1364,10 +1360,9 @@ class Session:
|
|||
"""
|
||||
Get a session node.
|
||||
|
||||
:param int _id: node id to retrieve
|
||||
:param _id: node id to retrieve
|
||||
:return: node for the given id
|
||||
:rtype: core.nodes.base.NodeBase
|
||||
:raises core.CoreError: when node does not exist
|
||||
:raises core.CoreError: when node does not exist
|
||||
"""
|
||||
if _id not in self.nodes:
|
||||
raise CoreError(f"unknown node id {_id}")
|
||||
|
@ -1377,10 +1372,9 @@ class Session:
|
|||
"""
|
||||
Delete a node from the session and check if session should shutdown, if no nodes are left.
|
||||
|
||||
:param int _id: id of node to delete
|
||||
:param _id: id of node to delete
|
||||
:return: True if node deleted, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
# delete node and check for session shutdown if a node was removed
|
||||
logging.info("deleting node(%s)", _id)
|
||||
node = None
|
||||
|
@ -1440,10 +1434,10 @@ class Session:
|
|||
"""
|
||||
Generate and broadcast an exception event.
|
||||
|
||||
:param core.emulator.enumerations.ExceptionLevel level: exception level
|
||||
:param str source: source name
|
||||
:param int node_id: node related to exception
|
||||
:param str text: exception message
|
||||
:param level: exception level
|
||||
:param source: source name
|
||||
:param node_id: node related to exception
|
||||
:param text: exception message
|
||||
:return: nothing
|
||||
"""
|
||||
exception_data = ExceptionData(
|
||||
|
@ -1602,7 +1596,7 @@ class Session:
|
|||
Boot node by adding a control interface when necessary and starting
|
||||
node services.
|
||||
|
||||
:param core.nodes.base.CoreNode node: node to boot
|
||||
:param node: node to boot
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("booting node(%s): %s", node.name, [x.name for x in node.services])
|
||||
|
@ -1616,8 +1610,7 @@ class Session:
|
|||
request flag.
|
||||
|
||||
:return: service boot exceptions
|
||||
:rtype: list[Exception]
|
||||
"""
|
||||
"""
|
||||
with self._nodes_lock:
|
||||
funcs = []
|
||||
start = time.monotonic()
|
||||
|
@ -1638,8 +1631,7 @@ class Session:
|
|||
Retrieve control net prefixes.
|
||||
|
||||
:return: control net prefix list
|
||||
:rtype: list
|
||||
"""
|
||||
"""
|
||||
p = self.options.get_config("controlnet")
|
||||
p0 = self.options.get_config("controlnet0")
|
||||
p1 = self.options.get_config("controlnet1")
|
||||
|
@ -1654,8 +1646,7 @@ class Session:
|
|||
Retrieve control net server interfaces.
|
||||
|
||||
:return: list of control net server interfaces
|
||||
:rtype: list
|
||||
"""
|
||||
"""
|
||||
d0 = self.options.get_config("controlnetif0")
|
||||
if d0:
|
||||
logging.error("controlnet0 cannot be assigned with a host interface")
|
||||
|
@ -1668,10 +1659,9 @@ class Session:
|
|||
"""
|
||||
Retrieve control net index.
|
||||
|
||||
:param str dev: device to get control net index for
|
||||
:param dev: device to get control net index for
|
||||
:return: control net index, -1 otherwise
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
if dev[0:4] == "ctrl" and int(dev[4]) in [0, 1, 2, 3]:
|
||||
index = int(dev[4])
|
||||
if index == 0:
|
||||
|
@ -1702,12 +1692,11 @@ class Session:
|
|||
interfaces. The conf_reqd flag, when False, causes a control network
|
||||
bridge to be added even if one has not been configured.
|
||||
|
||||
:param int net_index: network index
|
||||
:param bool remove: flag to check if it should be removed
|
||||
:param bool conf_required: flag to check if conf is required
|
||||
:param net_index: network index
|
||||
:param remove: flag to check if it should be removed
|
||||
:param conf_required: flag to check if conf is required
|
||||
:return: control net node
|
||||
:rtype: core.nodes.network.CtrlNet
|
||||
"""
|
||||
"""
|
||||
logging.debug(
|
||||
"add/remove control net: index(%s) remove(%s) conf_required(%s)",
|
||||
net_index,
|
||||
|
@ -1791,10 +1780,10 @@ class Session:
|
|||
If conf_reqd is False, the control network may be built even
|
||||
when the user has not configured one (e.g. for EMANE.)
|
||||
|
||||
:param core.nodes.base.CoreNodeBase node: node to add or remove control interface
|
||||
:param int net_index: network index
|
||||
:param bool remove: flag to check if it should be removed
|
||||
:param bool conf_required: flag to check if conf is required
|
||||
:param node: node to add or remove control interface
|
||||
:param net_index: network index
|
||||
:param remove: flag to check if it should be removed
|
||||
:param conf_required: flag to check if conf is required
|
||||
:return: nothing
|
||||
"""
|
||||
control_net = self.add_remove_control_net(net_index, remove, conf_required)
|
||||
|
@ -1836,8 +1825,8 @@ class Session:
|
|||
"""
|
||||
Add the IP addresses of control interfaces to the /etc/hosts file.
|
||||
|
||||
:param int net_index: network index to update
|
||||
:param bool remove: flag to check if it should be removed
|
||||
:param net_index: network index to update
|
||||
:param remove: flag to check if it should be removed
|
||||
:return: nothing
|
||||
"""
|
||||
if not self.options.get_config_bool("update_etc_hosts", default=False):
|
||||
|
@ -1887,8 +1876,8 @@ class Session:
|
|||
start of the runtime state.
|
||||
|
||||
:param event_time: event time
|
||||
:param core.nodes.base.CoreNode node: node to add event for
|
||||
:param str name: name of event
|
||||
:param node: node to add event for
|
||||
:param name: name of event
|
||||
:param data: data for event
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -1926,9 +1915,9 @@ class Session:
|
|||
"""
|
||||
Run a scheduled event, executing commands in the data string.
|
||||
|
||||
:param int node_id: node id to run event
|
||||
:param str name: event name
|
||||
:param str data: event data
|
||||
:param node_id: node id to run event
|
||||
:param name: event name
|
||||
:param data: event data
|
||||
:return: nothing
|
||||
"""
|
||||
now = self.runtime()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue