Skip to content
This repository was archived by the owner on Feb 10, 2018. It is now read-only.

Commit e764388

Browse files
authored
Merge pull request #96 from napalm-automation/develop
Release 0.5.1
2 parents 16cbdb8 + d951520 commit e764388

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

napalm_junos/junos.py

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from jnpr.junos import Device
2929
from jnpr.junos.utils.config import Config
30+
from jnpr.junos.exception import RpcError
3031
from jnpr.junos.exception import ConfigLoadError
3132
from jnpr.junos.exception import RpcTimeoutError
3233
from jnpr.junos.exception import ConnectTimeoutError
@@ -966,13 +967,8 @@ def get_route_to(self, destination='', protocol=''):
966967
if not isinstance(destination, py23_compat.string_types):
967968
raise TypeError('Please specify a valid destination!')
968969

969-
if protocol and (not isinstance(protocol, py23_compat.string_types) or
970-
protocol.lower() not in ('static', 'bgp', 'isis', 'connected', 'direct')):
971-
raise TypeError("Protocol not supported: {protocol}.".format(
972-
protocol=protocol
973-
))
974-
975-
protocol = protocol.lower()
970+
if protocol and isinstance(destination, py23_compat.string_types):
971+
protocol = protocol.lower()
976972

977973
if protocol == 'connected':
978974
protocol = 'direct' # this is how is called on JunOS
@@ -1022,7 +1018,7 @@ def get_route_to(self, destination='', protocol=''):
10221018
rt_kargs = {
10231019
'destination': destination
10241020
}
1025-
if protocol:
1021+
if protocol and isinstance(destination, py23_compat.string_types):
10261022
rt_kargs['protocol'] = protocol
10271023

10281024
try:
@@ -1033,8 +1029,13 @@ def get_route_to(self, destination='', protocol=''):
10331029
# will take very very long to determine all routes and
10341030
# moreover will return a huge list
10351031
raise CommandTimeoutException(
1036-
'Too many routes returned! Please try with a longer prefix!'
1032+
'Too many routes returned! Please try with a longer prefix or a specific protocol!'
10371033
)
1034+
except RpcError as rpce:
1035+
if len(rpce.errs) > 0 and 'bad_element' in rpce.errs[0]:
1036+
raise CommandErrorException(
1037+
'Unknown protocol: {proto}'.format(proto=rpce.errs[0]['bad_element']))
1038+
raise CommandErrorException(rpce)
10381039
except Exception as err:
10391040
raise CommandErrorException('Cannot retrieve routes! Reason: {err}'.format(err=err))
10401041

@@ -1089,39 +1090,35 @@ def get_snmp_information(self):
10891090
"""Return the SNMP configuration."""
10901091
snmp_information = {}
10911092

1092-
_AUTHORIZATION_MODE_MAP_ = {
1093-
'read-only': u'ro',
1094-
'read-write': u'rw'
1095-
}
1096-
10971093
snmp_config = junos_views.junos_snmp_config_table(self.device)
10981094
snmp_config.get()
10991095
snmp_items = snmp_config.items()
11001096

11011097
if not snmp_items:
11021098
return snmp_information
11031099

1104-
communities = []
1105-
for snmp_config_out in snmp_items:
1106-
community_details = snmp_config_out[1]
1107-
communities.append({
1108-
c[0]: c[1] for c in community_details
1109-
})
1110-
11111100
snmp_information = {
1112-
'contact': napalm_base.helpers.convert(unicode, communities[0].get('contact')),
1113-
'location': napalm_base.helpers.convert(unicode, communities[0].get('location')),
1114-
'chassis_id': napalm_base.helpers.convert(unicode, communities[0].get('chassis')),
1115-
'community': {}
1101+
py23_compat.text_type(ele[0]): ele[1] if ele[1] else ''
1102+
for ele in snmp_items[0][1]
11161103
}
11171104

1118-
for snmp_entry in communities:
1119-
name = napalm_base.helpers.convert(unicode, snmp_entry.get('name'))
1120-
authorization = napalm_base.helpers.convert(unicode, snmp_entry.get('authorization'))
1121-
snmp_information['community'][name] = {
1122-
'mode': _AUTHORIZATION_MODE_MAP_.get(authorization, u''),
1123-
'acl': u''
1105+
snmp_information['community'] = {}
1106+
communities_table = snmp_information.pop('communities_table')
1107+
if not communities_table:
1108+
return snmp_information
1109+
1110+
for community in communities_table.items():
1111+
community_name = py23_compat.text_type(community[0])
1112+
community_details = {
1113+
'acl': ''
11241114
}
1115+
community_details.update({
1116+
py23_compat.text_type(ele[0]): py23_compat.text_type(
1117+
ele[1] if ele[0] != 'mode'
1118+
else C.SNMP_AUTHORIZATION_MODE_MAP.get(ele[1]))
1119+
for ele in community[1]
1120+
})
1121+
snmp_information['community'][community_name] = community_details
11251122

11261123
return snmp_information
11271124

napalm_junos/utils/junos_views.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,25 @@ junos_route_table_view:
518518
###
519519

520520
junos_snmp_config_table:
521-
get: snmp/community
521+
get: snmp
522522
view: junos_snmp_config_view
523+
key: contact
523524

524525
junos_snmp_config_view:
525526
fields:
526-
name: name
527-
authorization: authorization
528-
location: ../location
529-
contact: ../contact
530-
chassis: ../system-name
527+
location: {location: unicode}
528+
contact: {contact: unicode}
529+
chassis_id: {system-name: unicode}
530+
communities_table: junos_snmp_communities_table
531+
532+
junos_snmp_communities_table:
533+
item: community
534+
key: name
535+
view: junos_snmp_communities_view
536+
537+
junos_snmp_communities_view:
538+
fields:
539+
mode: authorization
531540

532541
###
533542
### RPM Probes Config

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="napalm-junos",
15-
version="0.5.0",
15+
version="0.5.1",
1616
packages=find_packages(),
1717
author="David Barroso, Mircea Ulinic",
1818

test/unit/mocked_data/test_get_snmp_information/normal/_configuration__snmp__community____snmp___configuration_.xml renamed to test/unit/mocked_data/test_get_snmp_information/normal/_configuration__snmp____configuration_.xml

File renamed without changes.

0 commit comments

Comments
 (0)