Skip to content
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
165 changes: 119 additions & 46 deletions pycsco/nxos/utils/nxapi_lib.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def get_existing_portchannel_to_vpc_mappings(device):
return pc_vpc_mapping


def get_vpc_running_config(device):
def get_vpc_running_config(device, model):
"""Gets vpc running config

Args:
Expand All @@ -1813,7 +1813,15 @@ def get_vpc_running_config(device):
str: 'show run section vpc'

"""
command = 'show running section vpc'
if model.startswith('3'):
model = 'n3k'
elif model.startswith('9'):
model= 'n9k'
model_commands = {
'n9k': 'show running section vpc',
'n3k': 'show running | section vpc'
}
command = model_commands[model]
try:
get_data = device.show(command, text=True)
data_dict = xmltodict.parse(get_data[1])
Expand All @@ -1823,7 +1831,7 @@ def get_vpc_running_config(device):
return data


def feature_enabled(device, feature):
def feature_enabled(device, feature, model=None):
"""Checks to see if a feature is enabled

Args:
Expand Down Expand Up @@ -1851,43 +1859,64 @@ def feature_enabled(device, feature):
elif feature == 'scp-server':
feature = 'scpServer'

try:
data = device.show(command)
data_dict = xmltodict.parse(data[1])
table = data_dict['ins_api']['outputs']['output']
error = table.get('clierror', None)
if error is None:
features = table['body'].get(
'TABLE_cfcFeatureCtrlTable')['ROW_cfcFeatureCtrlTable']
else:
# For the 3K, the feature table is being returned in the clierror
# key/taag as unstructured text. Ugh.
manual_list = error.split('\n')
if model:
if model.startswith('3'):
data = device.show(command, text=True)
data_dict = xmltodict.parse(data[1])
table = data_dict['ins_api']['outputs']['output']['body']
manual_list = table.split('\n')
features = {}
for each in manual_list:
stripped = each.strip()
words = stripped.split(' ')
for each in manual_list[2:]:
words = filter(lambda x: x != '', each.split(' '))
first = str(words[0])
last = str(words[-1])
last = str(words[2])
features[first] = last
status = features.get(feature, None)
if status:
if status.startswith('enabled'):
return True
else:
return False
except (KeyError, AttributeError):
return check
if features:
for each in features:
feat = str(each['cfcFeatureCtrlName2'])
if feat == feature:
enabled = str(each['cfcFeatureCtrlOpStatus2'])
if enabled.startswith('enabled'):
# returning here to not loop through each supported
# instance/process of ospf, etc.
return True
return False
else:
try:
data = device.show(command)
data_dict = xmltodict.parse(data[1])
table = data_dict['ins_api']['outputs']['output']
error = table.get('clierror', None)
if error is None:
features = table['body'].get(
'TABLE_cfcFeatureCtrlTable')['ROW_cfcFeatureCtrlTable']
else:
# For the 3K, the feature table is being returned in the clierror
# key/taag as unstructured text. Ugh.
manual_list = error.split('\n')
features = {}
for each in manual_list:
stripped = each.strip()
words = stripped.split(' ')
first = str(words[0])
last = str(words[-1])
features[first] = last
status = features.get(feature, None)
if status:
if status.startswith('enabled'):
return True
else:
return False
except (KeyError, AttributeError):
return check
if features:
for each in features:
feat = str(each['cfcFeatureCtrlName2'])
if feat == feature:
enabled = str(each['cfcFeatureCtrlOpStatus2'])
if enabled.startswith('enabled'):
# returning here to not loop through each supported
# instance/process of ospf, etc.
return True
return False
else:
return False


def get_commands_to_remove_vpc(domain):
Expand All @@ -1908,7 +1937,7 @@ def get_commands_to_remove_vpc(domain):
return commands


def peer_link_exists(device):
def peer_link_exists(device, model):
"""Checks to see if vpc peer link exists

Args:
Expand All @@ -1920,7 +1949,7 @@ def peer_link_exists(device):

"""
found = False
run = get_vpc_running_config(device)
run = get_vpc_running_config(device, model)
if run:
vpc_list = run.split('\n')
for each in vpc_list:
Expand Down Expand Up @@ -2261,6 +2290,13 @@ def get_facts(device):
platform = resource_table.get('chassis_id', None)
hostname = resource_table.get('host_name', None)
rr = resource_table.get('rr_reason', None)
platforml = platform.lstrip('Nexus')
platformr = platforml.rstrip('Chassis')
models = platformr.strip()
if len(models) > 4:
model = models[:4]
else: model = models
n3k = model.startswith('3')

command = 'show interface status'
xml = device.show(command)
Expand Down Expand Up @@ -2357,6 +2393,28 @@ def get_facts(device):
temp['status'] = str(each.get('ps_status', None))
fan_list.append(temp)

command = 'show feature'
if n3k:
xml = device.show(command, text=True)
result = xmltodict.parse(xml[1])
resource_table = result['ins_api']['outputs']['output']['body']
manual_list = resource_table.split('\n')
feature_list = []
features = {}
for each in manual_list[2:]:
words = filter(lambda x: x != '', each.split(' '))
feature = str(words[0])
state = str(words[2])
features[feature] = state
feature_list.append(features)
else:
xml = device.show(command)
result = xmltodict.parse(xml[1])
features = result['ins_api']['outputs']['output']['body'].get(
'TABLE_cfcFeatureCtrlTable')['ROW_cfcFeatureCtrlTable']
feature_list.append(features)
# 9k functionality needs to be tested

facts = dict(
os=os,
kickstart_image=kickstart,
Expand All @@ -2367,7 +2425,9 @@ def get_facts(device):
interfaces_detail=detailed_list,
modules=mod_list,
power_supply_info=power_supply_list,
fan_info=fan_list
fan_info=fan_list,
features=feature_list,
model=model
)

return facts
Expand Down Expand Up @@ -2849,7 +2909,7 @@ def get_commands_remove_mtu(delta, interface):
return commands


def get_feature_list(device):
def get_feature_list(device, model):
"""Gets features supported on switch

Args:
Expand All @@ -2864,23 +2924,36 @@ def get_feature_list(device):
features = None
feature_list = None
command = 'show feature'
try:
data = device.show(command)
if model.startswith('3'):
data = device.show(command, text=True)
data_dict = xmltodict.parse(data[1])
features = data_dict['ins_api']['outputs']['output']['body'].get(
'TABLE_cfcFeatureCtrlTable')['ROW_cfcFeatureCtrlTable']
except (KeyError, AttributeError):
raw_list = data_dict['ins_api']['outputs']['output']['clierror'].split('\n')
features = data_dict['ins_api']['outputs']['output']['body']
raw_list = features.split('\n')
features = []
for line in raw_list[2:]:
tmp = {}
split_line = line.split(' ')
feat = split_line[0].strip()
print feat
split_line = filter(lambda x: x != '', line.split(' '))
feat = split_line[0]
tmp['cfcFeatureCtrlName2'] = feat
features.append(tmp)
except:
return []
else:
try:
data = device.show(command)
data_dict = xmltodict.parse(data[1])
features = data_dict['ins_api']['outputs']['output']['body'].get(
'TABLE_cfcFeatureCtrlTable')['ROW_cfcFeatureCtrlTable']
except (KeyError, AttributeError):
raw_list = data_dict['ins_api']['outputs']['output']['clierror'].split('\n')
features = []
for line in raw_list[2:]:
tmp = {}
split_line = line.split(' ')
feat = split_line[0].strip()
print feat
tmp['cfcFeatureCtrlName2'] = feat
features.append(tmp)
except:
return []

if features:
for each in features:
Expand Down