-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from juztas/sitermapi
Autofetch overwrite config. Use SiteRM Api to send pings between hosts
- Loading branch information
Showing
9 changed files
with
186 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REPLACEME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REPLACEME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
"urn:ogf:network:icair.org:2013": | ||
name: "NSI_STARLIGHT" | ||
joint_net: False | ||
"urn:ogf:network:es.net:2013": | ||
name: "ESNET" | ||
joint_net: True | ||
"urn:ogf:network:stack-fabric:2024": | ||
name: "NSI_FABRIC" | ||
joint_net: True | ||
"urn:ogf:network:lsanca.pacificwave.net:2016": | ||
name: "NSI_PACWAVE" | ||
joint_net: False | ||
"urn:ogf:network:uhnet.net:2021": | ||
name: "NSI_HAWAII" | ||
joint_net: False | ||
"urn:ogf:network:calit2.optiputer.net:2020": | ||
name: "NSI_UCSD" | ||
joint_net: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Class for interacting with SENSE SiteRMs | ||
""" | ||
from RTMonLibs.GeneralLibs import loadJson | ||
from sense.client.siterm.debug_api import DebugApi | ||
|
||
|
||
|
||
class SiteRMApi: | ||
"""Class for interacting with SENSE-0 API""" | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self.config = kwargs.get('config') | ||
self.logger = kwargs.get('logger') | ||
self.siterm_debug = DebugApi() | ||
|
||
@staticmethod | ||
def _sr_all_keys_match(action, newaction): | ||
return all(newaction.get(key) == action.get(key) for key in newaction) | ||
|
||
def _sr_get_all_hosts(self, **kwargs): | ||
"""Get all hosts from manifest""" | ||
allHosts, allIPs = [], {} | ||
for _idx, item in enumerate(kwargs.get("manifest", {}).get("Ports", [])): | ||
for hostdata in item.get('Host', []): | ||
if item.get('Vlan'): | ||
hostdata['vlan'] = f"vlan.{item['Vlan']}" | ||
allHosts.append(hostdata) | ||
# Check if IPv6 or IPv4 is defined | ||
for key, defval in [("IPv4", "?ipv4?"), ("IPv6", "?ipv6?")]: | ||
# TODO: Remove split of ip once this is solved: https://github.com/sdn-sense/siterm/issues/576 | ||
if hostdata.get(key) and hostdata[key] != defval: | ||
allIPs.setdefault(key, []) | ||
allIPs[key].append(hostdata[key].split('/')[0]) | ||
return allHosts, allIPs | ||
|
||
def sr_get_debug_actions(self, **kwargs): | ||
"""Get all debug actions for a site and hostname""" | ||
allDebugActions = [] | ||
for key in ["new", "active"]: | ||
jsonOut = {} | ||
out = self.siterm_debug.get_all_debug_hostname(sitename=kwargs.get("sitename"), | ||
hostname=kwargs.get("hostname"), | ||
state=key) | ||
if out and out[0]: | ||
jsonOut = loadJson(out[0], self.logger) | ||
for item in jsonOut: | ||
item["requestdict"] = loadJson(item["requestdict"], self.logger) | ||
allDebugActions.append(item) | ||
return allDebugActions | ||
|
||
def sr_submit_ping(self, **kwargs): | ||
"""Submit a ping test to the SENSE-SiteRM API""" | ||
self.logger.info("Start check for ping test if needed") | ||
hosts, allIPs = self._sr_get_all_hosts(**kwargs) | ||
# based on our variables; | ||
for host in hosts: | ||
# Check if IPv6 or IPv4 is defined | ||
for key, defval in [("IPv4", "?ipv4?"), ("IPv6", "?ipv6?")]: | ||
if host.get(key) and host[key] != defval: | ||
hostspl = host.get("Name").split(':') | ||
allDebugActions = self.sr_get_debug_actions(**{'sitename': hostspl[0], | ||
'hostname': hostspl[1]}) | ||
for ip in allIPs.get(key, []): | ||
hostip = host[key].split('/')[0] | ||
if hostip == ip: | ||
# We ignore ourself. No need to ping ourself | ||
continue | ||
# Loop all debug actions and check if the action is already in the list of actions | ||
# # TODO: Change time to 1hr once this is solved: https://github.com/sdn-sense/siterm/issues/574 | ||
newaction = {"hostname": hostspl[1], "type": "rapid-ping", | ||
"sitename": hostspl[0], "ip": ip, | ||
"packetsize": kwargs.get("packetsize", 56), | ||
"interval": kwargs.get("interval", 5), | ||
"interface": host['Interface'] if not host.get('vlan') else host['vlan'], | ||
"time": kwargs.get("time", 300)} | ||
actionPresent = False | ||
for action in allDebugActions: | ||
if self._sr_all_keys_match(action.get('requestdict'), newaction): | ||
actionPresent = True | ||
break | ||
if not actionPresent: | ||
self.logger.info(f"Submitting ping test for {newaction}") | ||
self.siterm_debug.submit_ping(**newaction) |