Commit 742495bf authored by Simon Redman's avatar Simon Redman

Add ospf sniffer stopping

parent d0320404
......@@ -48,7 +48,7 @@ def generate_start_command(path:str=DEFAULT_CLONE_PATH,
pidfile: str=DEFAULT_PIDFILE,
) -> str:
"""
Generate a command which launches the OSPF sniffer on all requested nodes in the network
Generate a command which launches the OSPF sniffer
Does not do any initialization, such as downloading the sniffer
......@@ -67,6 +67,9 @@ def generate_start_command(path:str=DEFAULT_CLONE_PATH,
pidfile=pidfile,
)
def generate_stop_command(pidfile: str=DEFAULT_PIDFILE) -> str:
return "kill $(cat {pidfile})".format(pidfile=pidfile)
def clone_repo_on_network(graph: networkx.Graph,
repo: str=DEFAULT_REPO_URL,
......@@ -77,13 +80,16 @@ def clone_repo_on_network(graph: networkx.Graph,
"""
Clone the specified repository and branch on each non-ignored node in the network
If the passed path is already in use, attempts to update the repository in that directory
:param graph: networkx.Graph representation of the network
:param repo: Repository to clone
:param branch: Branch in the repository to clone
:param path: Path into which to clone the repository
:param path: Directory into which to clone the repository
:param ignore_nodes: Nodes in the network which should not have the repository cloned
:return:
"""
if ignore_nodes is None: ignore_nodes = []
command = generate_repo_clone_command(repo=repo, branch=branch, path=path)
hosts = [host for host in graph.nodes if host not in ignore_nodes]
......@@ -129,6 +135,7 @@ def start_sniffer_on_network(graph: networkx.Graph,
:param ignore_nodes: nodes which should not have the daemon run on them
:return:
"""
if ignore_nodes is None: ignore_nodes = []
command = generate_start_command(path=path, executable=executable, controller=controller, pidfile=pidfile)
hosts = [host for host in graph.nodes if host not in ignore_nodes]
......@@ -153,7 +160,19 @@ def start_sniffer_on_network(graph: networkx.Graph,
if errors is not None: raise errors
def stop_sniffer_on_network(graph: networkx.Graph, pidfile: str=DEFAULT_PIDFILE) -> Optional[str]:
def stop_sniffer_on_network(graph: networkx.Graph,
pidfile: str=DEFAULT_PIDFILE,
ignore_nodes: List[str] = None):
"""
Stop the sniffer on all non-ignored nodes in the network
"""
if ignore_nodes is None: ignore_nodes = []
hosts = [host for host in graph.nodes if host not in ignore_nodes]
sessions = [graph._node[host]['session'] for host in hosts]
commands = [generate_stop_command(pidfile=pidfile)] * len(hosts)
output = ssh_helper.run_commands_on_many_hosts(sessions, commands)
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment