Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #132 from napalm-automation/bad-eval
Browse files Browse the repository at this point in the history
Get rid of dangerous eval
  • Loading branch information
mirceaulinic authored Jul 12, 2017
2 parents 3b2cb45 + 18a5a12 commit bf5c791
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions napalm_iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,8 @@ def build_prefix_limit(af_table, limit, prefix_percent, prefix_timeout):
bgp_group, 'NeighborGroupAFTable/NeighborGroupAF/RoutePolicyIn')
export_policy = napalm_base.helpers.find_txt(
bgp_group, 'NeighborGroupAFTable/NeighborGroupAF/RoutePolicyOut')
multipath = eval((napalm_base.helpers.find_txt(
bgp_group, 'NeighborGroupAFTable/NeighborGroupAF/Multipath') or 'false').title())
multipath = napalm_base.helpers.find_txt(
bgp_group, 'NeighborGroupAFTable/NeighborGroupAF/Multipath') == 'true'
peer_as = napalm_base.helpers.convert(
int, napalm_base.helpers.find_txt(bgp_group, 'RemoteAS/AS_YY'), 0)
local_as = napalm_base.helpers.convert(
Expand Down Expand Up @@ -949,8 +949,8 @@ def get_bgp_neighbors_detail(self, neighbor_address=''):
napalm_base.helpers.find_txt(neighbor, 'Naming/NeighborAddress/IPV4Address') or
napalm_base.helpers.find_txt(neighbor, 'Naming/NeighborAddress/IPV6Address')
)
local_address_configured = eval(napalm_base.helpers.find_txt(
neighbor, 'IsLocalAddressConfigured', 'false').title())
local_address_configured = napalm_base.helpers.find_txt(
neighbor, 'IsLocalAddressConfigured') == 'true'
local_address = napalm_base.helpers.ip(
napalm_base.helpers.find_txt(neighbor, 'ConnectionLocalAddress/IPV4Address') or
napalm_base.helpers.find_txt(neighbor, 'ConnectionLocalAddress/IPV6Address')
Expand All @@ -963,12 +963,12 @@ def get_bgp_neighbors_detail(self, neighbor_address=''):
)
remote_port = napalm_base.helpers.convert(
int, napalm_base.helpers.find_txt(neighbor, 'ConnectionRemotePort'))
multihop = eval(napalm_base.helpers.find_txt(
neighbor, 'IsExternalNeighborNotDirectlyConnected', 'false').title())
remove_private_as = eval(napalm_base.helpers.find_txt(
neighbor, 'AFData/Entry/RemovePrivateASFromUpdates', 'false').title())
multipath = eval(napalm_base.helpers.find_txt(
neighbor, 'AFData/Entry/SelectiveMultipathEligible', 'false').title())
multihop = napalm_base.helpers.find_txt(
neighbor, 'IsExternalNeighborNotDirectlyConnected') == 'true'
remove_private_as = napalm_base.helpers.find_txt(
neighbor, 'AFData/Entry/RemovePrivateASFromUpdates') == 'true'
multipath = napalm_base.helpers.find_txt(
neighbor, 'AFData/Entry/SelectiveMultipathEligible') == 'true'
import_policy = napalm_base.helpers.find_txt(
neighbor, 'AFData/Entry/RoutePolicyIn')
export_policy = napalm_base.helpers.find_txt(
Expand Down Expand Up @@ -1000,10 +1000,10 @@ def get_bgp_neighbors_detail(self, neighbor_address=''):
advertised_prefix_count = napalm_base.helpers.convert(
int, napalm_base.helpers.find_txt(
neighbor, 'AFData/Entry/PrefixesAdvertised'), 0)
suppress_4byte_as = eval(napalm_base.helpers.find_txt(
neighbor, 'Suppress4ByteAs', 'false').title())
local_as_prepend = not eval(napalm_base.helpers.find_txt(
neighbor, 'LocalASNoPrepend', 'false').title())
suppress_4byte_as = napalm_base.helpers.find_txt(
neighbor, 'Suppress4ByteAs') == 'true'
local_as_prepend = napalm_base.helpers.find_txt(
neighbor, 'LocalASNoPrepend') != 'true'
holdtime = napalm_base.helpers.convert(
int, napalm_base.helpers.find_txt(neighbor, 'HoldTime'), 0) or vrf_holdtime
configured_holdtime = napalm_base.helpers.convert(
Expand Down Expand Up @@ -1142,7 +1142,7 @@ def get_ntp_stats(self):

xpath = './/NodeTable/Node/Associations/PeerSummaryInfo/Entry/PeerInfoCommon'
for node in result_tree.xpath(xpath):
synchronized = eval(napalm_base.helpers.find_txt(node, 'IsSysPeer', 'false').title())
synchronized = napalm_base.helpers.find_txt(node, 'IsSysPeer') == 'true'
address = napalm_base.helpers.find_txt(node, 'Address')
if address == 'DLRSC node':
continue
Expand Down Expand Up @@ -1365,8 +1365,8 @@ def get_route_to(self, destination='', protocol=''):
for bgp_path in bgp_route_tree.xpath('.//Path'):
single_route_details = route_details.copy()
if 'NotFound' not in bgp_path.keys():
best_path = eval(napalm_base.helpers.find_txt(
bgp_path, 'PathInformation/IsBestPath', 'false').title())
best_path = napalm_base.helpers.find_txt(
bgp_path, 'PathInformation/IsBestPath') == 'true'
local_preference = napalm_base.helpers.convert(
int,
napalm_base.helpers.find_txt(
Expand Down

0 comments on commit bf5c791

Please sign in to comment.