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
|
@ -14,7 +14,7 @@ def signal_handler(signal_number: int, _) -> None:
|
|||
"""
|
||||
Handle signals and force an exit with cleanup.
|
||||
|
||||
:param int signal_number: signal number
|
||||
:param signal_number: signal number
|
||||
:param _: ignored
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -38,7 +38,7 @@ class CoreEmu:
|
|||
"""
|
||||
Create a CoreEmu object.
|
||||
|
||||
:param dict config: configuration options
|
||||
:param config: configuration options
|
||||
"""
|
||||
# set umask 0
|
||||
os.umask(0)
|
||||
|
@ -88,11 +88,10 @@ class CoreEmu:
|
|||
"""
|
||||
Create a new CORE session.
|
||||
|
||||
:param int _id: session id for new session
|
||||
:param class _cls: Session class to use
|
||||
:param _id: session id for new session
|
||||
:param _cls: Session class to use
|
||||
:return: created session
|
||||
:rtype: EmuSession
|
||||
"""
|
||||
"""
|
||||
if not _id:
|
||||
_id = 1
|
||||
while _id in self.sessions:
|
||||
|
@ -106,10 +105,9 @@ class CoreEmu:
|
|||
"""
|
||||
Shutdown and delete a CORE session.
|
||||
|
||||
:param int _id: session id to delete
|
||||
:param _id: session id to delete
|
||||
:return: True if deleted, False otherwise
|
||||
:rtype: bool
|
||||
"""
|
||||
"""
|
||||
logging.info("deleting session: %s", _id)
|
||||
session = self.sessions.pop(_id, None)
|
||||
result = False
|
||||
|
|
|
@ -34,8 +34,8 @@ class DistributedServer:
|
|||
"""
|
||||
Create a DistributedServer instance.
|
||||
|
||||
:param str name: convenience name to associate with host
|
||||
:param str host: host to connect to
|
||||
:param name: convenience name to associate with host
|
||||
:param host: host to connect to
|
||||
"""
|
||||
self.name = name
|
||||
self.host = host
|
||||
|
@ -48,14 +48,13 @@ class DistributedServer:
|
|||
"""
|
||||
Run command remotely using server connection.
|
||||
|
||||
:param str cmd: command to run
|
||||
:param dict env: environment for remote command, default is None
|
||||
:param str cwd: directory to run command in, defaults to None, which is the
|
||||
:param cmd: command to run
|
||||
:param env: environment for remote command, default is None
|
||||
:param cwd: directory to run command in, defaults to None, which is the
|
||||
user's home directory
|
||||
:param bool wait: True to wait for status, False to background process
|
||||
:param wait: True to wait for status, False to background process
|
||||
:return: stdout when success
|
||||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
|
||||
replace_env = env is not None
|
||||
|
@ -83,8 +82,8 @@ class DistributedServer:
|
|||
"""
|
||||
Push file to remote server.
|
||||
|
||||
:param str source: source file to push
|
||||
:param str destination: destination file location
|
||||
:param source: source file to push
|
||||
:param destination: destination file location
|
||||
:return: nothing
|
||||
"""
|
||||
with self.lock:
|
||||
|
@ -95,8 +94,8 @@ class DistributedServer:
|
|||
Remote push file contents to a remote server, using a temp file as an
|
||||
intermediate step.
|
||||
|
||||
:param str destination: file destination for data
|
||||
:param str data: data to store in remote file
|
||||
:param destination: file destination for data
|
||||
:param data: data to store in remote file
|
||||
:return: nothing
|
||||
"""
|
||||
with self.lock:
|
||||
|
@ -129,8 +128,8 @@ class DistributedController:
|
|||
"""
|
||||
Add distributed server configuration.
|
||||
|
||||
:param str name: distributed server name
|
||||
:param str host: distributed server host address
|
||||
:param name: distributed server name
|
||||
:param host: distributed server host address
|
||||
:return: nothing
|
||||
"""
|
||||
server = DistributedServer(name, host)
|
||||
|
@ -197,12 +196,11 @@ class DistributedController:
|
|||
Create gre tunnel using a pair of gre taps between the local and remote server.
|
||||
|
||||
|
||||
:param core.nodes.network.CoreNetwork node: node to create gre tunnel for
|
||||
:param core.emulator.distributed.DistributedServer server: server to create
|
||||
:param node: node to create gre tunnel for
|
||||
:param server: server to create
|
||||
tunnel for
|
||||
:return: local and remote gre taps created for tunnel
|
||||
:rtype: tuple
|
||||
"""
|
||||
"""
|
||||
host = server.host
|
||||
key = self.tunnel_key(node.id, netaddr.IPAddress(host).value)
|
||||
tunnel = self.tunnels.get(key)
|
||||
|
@ -236,11 +234,10 @@ class DistributedController:
|
|||
The hash(n1num), hash(n2num) values are used, so node numbers may be
|
||||
None or string values (used for e.g. "ctrlnet").
|
||||
|
||||
:param int n1_id: node one id
|
||||
:param int n2_id: node two id
|
||||
:param n1_id: node one id
|
||||
:param n2_id: node two id
|
||||
:return: tunnel key for the node pair
|
||||
:rtype: int
|
||||
"""
|
||||
"""
|
||||
logging.debug("creating tunnel key for: %s, %s", n1_id, n2_id)
|
||||
key = (
|
||||
(self.session.id << 16) ^ utils.hashkey(n1_id) ^ (utils.hashkey(n2_id) << 8)
|
||||
|
@ -251,8 +248,8 @@ class DistributedController:
|
|||
"""
|
||||
Return the GreTap between two nodes if it exists.
|
||||
|
||||
:param int n1_id: node one id
|
||||
:param int n2_id: node two id
|
||||
:param n1_id: node one id
|
||||
:param n2_id: node two id
|
||||
:return: gre tap between nodes or None
|
||||
"""
|
||||
key = self.tunnel_key(n1_id, n2_id)
|
||||
|
|
|
@ -32,8 +32,8 @@ def link_config(
|
|||
|
||||
:param network: network to configure link for
|
||||
:param interface: interface to configure
|
||||
:param core.emulator.emudata.LinkOptions link_options: data to configure link with
|
||||
:param str devname: device name, default is None
|
||||
:param link_options: data to configure link with
|
||||
:param devname: device name, default is None
|
||||
:param interface_two: other interface associated, default is None
|
||||
:return: nothing
|
||||
"""
|
||||
|
@ -64,10 +64,10 @@ class NodeOptions:
|
|||
"""
|
||||
Create a NodeOptions object.
|
||||
|
||||
:param str name: name of node, defaults to node class name postfix with its id
|
||||
:param str model: defines services for default and physical nodes, defaults to
|
||||
:param name: name of node, defaults to node class name postfix with its id
|
||||
:param model: defines services for default and physical nodes, defaults to
|
||||
"router"
|
||||
:param str image: image to use for docker nodes
|
||||
:param image: image to use for docker nodes
|
||||
"""
|
||||
self.name = name
|
||||
self.model = model
|
||||
|
@ -89,8 +89,8 @@ class NodeOptions:
|
|||
"""
|
||||
Convenience method for setting position.
|
||||
|
||||
:param float x: x position
|
||||
:param float y: y position
|
||||
:param x: x position
|
||||
:param y: y position
|
||||
:return: nothing
|
||||
"""
|
||||
self.x = x
|
||||
|
@ -100,9 +100,9 @@ class NodeOptions:
|
|||
"""
|
||||
Convenience method for setting location.
|
||||
|
||||
:param float lat: latitude
|
||||
:param float lon: longitude
|
||||
:param float alt: altitude
|
||||
:param lat: latitude
|
||||
:param lon: longitude
|
||||
:param alt: altitude
|
||||
:return: nothing
|
||||
"""
|
||||
self.lat = lat
|
||||
|
@ -119,7 +119,7 @@ class LinkOptions:
|
|||
"""
|
||||
Create a LinkOptions object.
|
||||
|
||||
:param core.emulator.enumerations.LinkTypes _type: type of link, defaults to
|
||||
:param _type: type of link, defaults to
|
||||
wired
|
||||
"""
|
||||
self.type = _type
|
||||
|
@ -158,13 +158,13 @@ class InterfaceData:
|
|||
"""
|
||||
Creates an InterfaceData object.
|
||||
|
||||
:param int _id: interface id
|
||||
:param str name: name for interface
|
||||
:param str mac: mac address
|
||||
:param str ip4: ipv4 address
|
||||
:param int ip4_mask: ipv4 bit mask
|
||||
:param str ip6: ipv6 address
|
||||
:param int ip6_mask: ipv6 bit mask
|
||||
:param _id: interface id
|
||||
:param name: name for interface
|
||||
:param mac: mac address
|
||||
:param ip4: ipv4 address
|
||||
:param ip4_mask: ipv4 bit mask
|
||||
:param ip6: ipv6 address
|
||||
:param ip6_mask: ipv6 bit mask
|
||||
"""
|
||||
self.id = _id
|
||||
self.name = name
|
||||
|
@ -217,8 +217,7 @@ class InterfaceData:
|
|||
Returns a list of ip4 and ip6 address when present.
|
||||
|
||||
:return: list of addresses
|
||||
:rtype: list
|
||||
"""
|
||||
"""
|
||||
ip4 = self.ip4_address()
|
||||
ip6 = self.ip6_address()
|
||||
return [i for i in [ip4, ip6] if i]
|
||||
|
@ -233,8 +232,8 @@ class IpPrefixes:
|
|||
"""
|
||||
Creates an IpPrefixes object.
|
||||
|
||||
:param str ip4_prefix: ip4 prefix to use for generation
|
||||
:param str ip6_prefix: ip6 prefix to use for generation
|
||||
:param ip4_prefix: ip4 prefix to use for generation
|
||||
:param ip6_prefix: ip6 prefix to use for generation
|
||||
:raises ValueError: when both ip4 and ip6 prefixes have not been provided
|
||||
"""
|
||||
if not ip4_prefix and not ip6_prefix:
|
||||
|
@ -253,8 +252,7 @@ class IpPrefixes:
|
|||
|
||||
:param node: node to get IP4 address for
|
||||
:return: IP4 address or None
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
if not self.ip4:
|
||||
raise ValueError("ip4 prefixes have not been set")
|
||||
return str(self.ip4[node.id])
|
||||
|
@ -265,8 +263,7 @@ class IpPrefixes:
|
|||
|
||||
:param node: node to get IP6 address for
|
||||
:return: IP4 address or None
|
||||
:rtype: str
|
||||
"""
|
||||
"""
|
||||
if not self.ip6:
|
||||
raise ValueError("ip6 prefixes have not been set")
|
||||
return str(self.ip6[node.id])
|
||||
|
@ -278,13 +275,12 @@ class IpPrefixes:
|
|||
Creates interface data for linking nodes, using the nodes unique id for
|
||||
generation, along with a random mac address, unless provided.
|
||||
|
||||
:param core.nodes.base.CoreNode node: node to create interface for
|
||||
:param str name: name to set for interface, default is eth{id}
|
||||
:param str mac: mac address to use for this interface, default is random
|
||||
:param node: node to create interface for
|
||||
:param name: name to set for interface, default is eth{id}
|
||||
:param mac: mac address to use for this interface, default is random
|
||||
generation
|
||||
:return: new interface data for the provided node
|
||||
:rtype: InterfaceData
|
||||
"""
|
||||
"""
|
||||
# interface id
|
||||
inteface_id = node.newifindex()
|
||||
|
||||
|
@ -324,8 +320,8 @@ def create_interface(
|
|||
Create an interface for a node on a network using provided interface data.
|
||||
|
||||
:param node: node to create interface for
|
||||
:param core.nodes.base.CoreNetworkBase network: network to associate interface with
|
||||
:param core.emulator.emudata.InterfaceData interface_data: interface data
|
||||
:param network: network to associate interface with
|
||||
:param interface_data: interface data
|
||||
:return: created interface
|
||||
"""
|
||||
node.newnetif(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -76,12 +76,11 @@ class SessionConfig(ConfigurableManager, ConfigurableOptions):
|
|||
"""
|
||||
Retrieves a specific configuration for a node and configuration type.
|
||||
|
||||
:param str _id: specific configuration to retrieve
|
||||
:param int node_id: node id to store configuration for
|
||||
:param str config_type: configuration type to store configuration for
|
||||
:param _id: specific configuration to retrieve
|
||||
:param node_id: node id to store configuration for
|
||||
:param config_type: configuration type to store configuration for
|
||||
:param default: default value to return when value is not found
|
||||
:return: configuration value
|
||||
:rtype str
|
||||
"""
|
||||
value = super().get_config(_id, node_id, config_type, default)
|
||||
if value == "":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue