Merge pull request #54 from fooelisa/0.2

iosxr bgp and lldp
This commit is contained in:
David Barroso committed 2015-05-28 14:38:46 -04:00
commit 54a72b08c2
3 files changed
+40 -34

No files matched your search

+2 -33
View File
@@ -18,7 +18,7 @@ from pyFG.exceptions import FailedCommit, CommandExecutionException
from base import NetworkDriver
from exceptions import ReplaceConfigException, MergeConfigException
from utils.string_parsers import colon_separated_string_to_dict
from utils.string_parsers import colon_separated_string_to_dict, convert_uptime_string_seconds
import re
@@ -37,37 +37,6 @@ def execute_get(device, cmd, separator=':', auto=False):
return colon_separated_string_to_dict('\n'.join(output), separator)
def convert_uptime_string_seconds(uptime):
regex_1 = re.compile(r"((?P<days>\d+) days,\s+)?((?P<hours>\d+) hours,\s+)?((?P<minutes>\d+) minutes)")
regex_2 = re.compile(r"((?P<hours>\d+)):((?P<minutes>\d+)):((?P<seconds>\d+))")
regex_list = [regex_1, regex_2]
uptime_dict = dict()
for regex in regex_list:
uptime_dict = regex.match(uptime)
if uptime_dict is not None:
uptime_dict = uptime_dict.groupdict()
break
uptime_dict = dict()
uptime_seconds = 0
for unit, value in uptime_dict.iteritems():
if unit == 'days':
uptime_seconds += int(value) * 86400
elif unit == 'hours':
uptime_seconds += int(value) * 3600
elif unit == 'minutes':
uptime_seconds += int(value) * 60
elif unit == 'seconds':
uptime_seconds += int(value)
else:
raise Exception('Unrecognized unit "{}" in uptime:{}'.format(unit, uptime))
return uptime_seconds
class FortiOSDriver(NetworkDriver):
def __init__(self, hostname, username, password):
@@ -239,4 +208,4 @@ class FortiOSDriver(NetworkDriver):
'router_id': bgp_sum[0].split()[3],
'peers': peers
}
}
}
+1
View File
@@ -51,6 +51,7 @@ junos_bgp_view:
uptime: { elapsed-time/@seconds: int }
received_prefixes: { bgp-rib/received-prefix-count: int }
accepted_prefixes: { bgp-rib/accepted-prefix-count: int }
sent_prefixes: { bgp-rib/aadvertised-prefix-count: int }
####
#### LLDP table
+37 -1
View File
@@ -39,7 +39,6 @@ def colon_separated_string_to_dict(string, separator=':'):
return dictionary
def hyphen_range(string):
'''
Expands a string of numbers separated by commas and hyphens into a list of integers.
@@ -60,3 +59,40 @@ def hyphen_range(string):
raise Exception('Something went wrong expanding the range'.format(string))
return list_numbers
def convert_uptime_string_seconds(uptime):
'''
Convert uptime strings to seconds. The string can be formatted various ways, eg.
1 hour, 56 minutes
'''
regex_1 = re.compile(r"((?P<days>\d+) day(s)?,\s+)?((?P<hours>\d+) hour(s)?,\s+)?((?P<minutes>\d+) minute(s)?)")
regex_2 = re.compile(r"((?P<hours>\d+)):((?P<minutes>\d+)):((?P<seconds>\d+))")
regex_list = [regex_1, regex_2]
# say whaaaat!?
uptime_dict = dict()
for regex in regex_list:
uptime_dict = regex.match(uptime)
if uptime_dict is not None:
uptime_dict = uptime_dict.groupdict()
break
uptime_dict = dict()
uptime_seconds = 0
for unit, value in uptime_dict.iteritems():
if value != None:
if unit == 'days':
uptime_seconds += int(value) * 86400
elif unit == 'hours':
uptime_seconds += int(value) * 3600
elif unit == 'minutes':
uptime_seconds += int(value) * 60
elif unit == 'seconds':
uptime_seconds += int(value)
else:
raise Exception('Unrecognized unit "{}" in uptime:{}'.format(unit, uptime))
return uptime_seconds