Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def transform_lldp_capab(capabilities):
if capabilities and isinstance(capabilities, str):
capabilities = capabilities.strip().lower().split(",")
return sorted(
[constants.LLDP_CAPAB_TRANFORM_TABLE[c.strip()] for c in capabilities]
)
else:
return []
def ping(self,
destination,
source=C.PING_SOURCE,
ttl=C.PING_TTL,
timeout=C.PING_TIMEOUT,
size=C.PING_SIZE,
count=C.PING_COUNT,
vrf=C.PING_VRF):
deadline = timeout * count
command = "ping %s " % destination
command += "-t %d " % int(ttl)
command += "-w %d " % int(deadline)
command += "-s %d " % int(size)
command += "-c %d " % int(count)
if source != "":
command += "interface %s " % source
def ping(
self,
destination,
source=c.PING_SOURCE,
ttl=c.PING_TTL,
timeout=c.PING_TIMEOUT,
size=c.PING_SIZE,
count=c.PING_COUNT,
vrf=c.PING_VRF,
):
"""
Executes ping on the device and returns a dictionary with the result
:param destination: Host or IP Address of the destination
:param source (optional): Source address of echo request
:param ttl (optional): Maximum number of hops
:param timeout (optional): Maximum seconds to wait after sending final packet
:param size (optional): Size of request (bytes)
:param count (optional): Number of ping request to send
def ping(
self,
destination,
source=C.PING_SOURCE,
ttl=C.PING_TTL,
timeout=C.PING_TIMEOUT,
size=C.PING_SIZE,
count=C.PING_COUNT,
vrf=C.PING_VRF,
):
"""
Execute ping on the device and returns a dictionary with the result.
Output dictionary has one of following keys:
* success
* error
In case of success, inner dictionary will have the followin keys:
* probes_sent (int)
* packet_loss (int)
* rtt_min (float)
def ping(
self,
destination,
source=C.PING_SOURCE,
ttl=C.PING_TTL,
timeout=C.PING_TIMEOUT,
size=C.PING_SIZE,
count=C.PING_COUNT,
vrf=C.PING_VRF,
):
"""
Execute ping on the device and returns a dictionary with the result.
Output dictionary has one of following keys:
* success
* error
In case of success, inner dictionary will have the followin keys:
* probes_sent (int)
* packet_loss (int)
* rtt_min (float)
def ping(self,
destination,
source=C.PING_SOURCE,
ttl=C.PING_TTL,
timeout=C.PING_TIMEOUT,
size=C.PING_SIZE,
count=C.PING_COUNT,
vrf=C.PING_VRF):
"""Execute ping on the device and returns a dictionary with the result."""
ping_dict = {}
ping_caps = self._ping_caps()
command = 'ping {}'.format(destination)
command += ' repetitions {}'.format(count)
command += ' timeout {}'.format(timeout)
if 'data-size' in ping_caps:
command += ' data-size {}'.format(size)
if source != '' and 'source' in ping_caps:
def ping(
self,
destination,
source=c.PING_SOURCE,
ttl=c.PING_TTL,
timeout=c.PING_TIMEOUT,
size=c.PING_SIZE,
count=c.PING_COUNT,
vrf=c.PING_VRF,
):
"""
Execute ping on the device and returns a dictionary with the result.
Output dictionary has one of following keys:
* success
* error
In case of success, inner dictionary will have the followin keys:
* probes_sent (int)
* packet_loss (int)
* rtt_min (float)
* rtt_max (float)
* rtt_avg (float)
* rtt_stddev (float)
* results (list)
'results' is a list of dictionaries with the following keys:
def ping(
self,
destination,
source=c.PING_SOURCE,
ttl=c.PING_TTL,
timeout=c.PING_TIMEOUT,
size=c.PING_SIZE,
count=c.PING_COUNT,
vrf=c.PING_VRF,
):
"""
Execute ping on the device and returns a dictionary with the result.
Output dictionary has one of following keys:
* success
* error
In case of success, inner dictionary will have the followin keys:
* probes_sent (int)
* packet_loss (int)
* rtt_min (float)
* rtt_max (float)
* rtt_avg (float)
* rtt_stddev (float)
* results (list)
def traceroute(
self,
destination,
source=c.TRACEROUTE_SOURCE,
ttl=c.TRACEROUTE_TTL,
timeout=c.TRACEROUTE_TIMEOUT,
vrf=c.TRACEROUTE_VRF,
):
_HOP_ENTRY_PROBE = [
r"\s+",
r"(", # beginning of host_name (ip_address) RTT group
r"(", # beginning of host_name (ip_address) group only
r"([a-zA-Z0-9\.:-]*)", # hostname
r"\s+",
r"\(?([a-fA-F0-9\.:][^\)]*)\)?", # IP Address between brackets
r"(?:\s+\(AS\s+[0-9]+\))?", # AS number -- may or may not be present
r")?", # end of host_name (ip_address) group only
# also hostname/ip are optional -- they can or cannot be specified
# if not specified, means the current probe followed the same path as the previous
r"\s+",
r"(\d+\.\d+)\s+ms", # RTT
def traceroute(
self,
destination,
source=c.TRACEROUTE_SOURCE,
ttl=c.TRACEROUTE_TTL,
timeout=c.TRACEROUTE_TIMEOUT,
vrf=c.TRACEROUTE_VRF,
):
_HOP_ENTRY_PROBE = [
r"\s+",
r"(", # beginning of host_name (ip_address) RTT group
r"(", # beginning of host_name (ip_address) group only
r"([a-zA-Z0-9\.:-]*)", # hostname
r"\s+",
r"\(?([a-fA-F0-9\.:][^\)]*)\)?", # IP Address between brackets
r"(?:\s+\(AS\s+[0-9]+\))?", # AS number -- may or may not be present
r")?", # end of host_name (ip_address) group only
# also hostname/ip are optional -- they can or cannot be specified
# if not specified, means the current probe followed the same path as the previous
r"\s+",