Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip trailing whitespace #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions napalm_ruckus_fastiron/FastIron.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from netmiko import ConnectHandler
import socket
import sys
# import re
import re

# local modules
# import napalm.base.exceptions
Expand Down Expand Up @@ -488,16 +488,23 @@ def __creates_config_block(list_1):

return config_block

@staticmethod
def __strip_trailing_whitespace(cmd):
strip = re.compile(r"(\s*([^\s]*[\s]*[^\s+]+)+)\s*$")
return strip.match(cmd).group(1)

@staticmethod
def __compare_blocks(cb_1, config_blocks_2, cmd, symbol):
temp_list = list()
stat = False
for cb_2 in config_blocks_2: # grabs a single config block
if cmd == cb_2[0]: # checks cmd not found
if FastIronDriver.__strip_trailing_whitespace(cmd) == FastIronDriver.__strip_trailing_whitespace(cb_2[0]): # checks cmd not found
stat = True
for single_cmd in cb_1: # iterates through cmd of config block
if single_cmd == cmd: # if this is first command add as base
if FastIronDriver.__strip_trailing_whitespace(single_cmd) == FastIronDriver.__strip_trailing_whitespace(cmd): # if this is first command add as base
temp_list.append(single_cmd) # add to list with no changes
elif single_cmd not in cb_2:
elif FastIronDriver.__strip_trailing_whitespace(single_cmd) not in list(map(FastIronDriver.__strip_trailing_whitespace, cb_2)):
print(list(map(FastIronDriver.__strip_trailing_whitespace, cb_2)))
temp_list.append(symbol + " " + single_cmd)
return temp_list, stat

Expand All @@ -510,6 +517,7 @@ def __comparing_list(list_1, list_2, symbol):
for cb_1 in config_blocks_1: # Grabs a single config block
is_found = False

temp_list = list()
if cb_1 not in config_blocks_2: # checks if config block already exisit
cmd = cb_1[0] # grabs first cmd of config block

Expand Down Expand Up @@ -657,8 +665,8 @@ def compare_config(self): # optimize implementatio
else:
return -1 # No configuration was found

diff_1 = FastIronDriver.__comparing_list(rc, stored_conf, "+")
diff_2 = FastIronDriver.__comparing_list(stored_conf, rc, "-")
diff_1 = FastIronDriver.__comparing_list(rc, stored_conf, "-")
diff_2 = FastIronDriver.__comparing_list(stored_conf, rc, "+")

str_diff1 = FastIronDriver.__compare_away(diff_1, diff_2)
str_diff2 = FastIronDriver.__compare_vice(diff_2, diff_1)
Expand All @@ -681,9 +689,9 @@ def commit_config(self):

for sentence in my_temp:

if sentence[0] == '-':
if sentence[0] == '+':
sentence = sentence[1:len(sentence)]
elif sentence[0] == '+':
elif sentence[0] == '-':
sentence = 'no' + sentence[1:len(sentence)]
replace_list.append(sentence)

Expand Down