本文整理汇总了Python中ciscoconfparse.CiscoConfParse方法的典型用法代码示例。如果您正苦于以下问题:Python ciscoconfparse.CiscoConfParse方法的具体用法?Python ciscoconfparse.CiscoConfParse怎么用?Python ciscoconfparse.CiscoConfParse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ciscoconfparse
的用法示例。
在下文中一共展示了ciscoconfparse.CiscoConfParse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def main():
"""
Using ciscoconfparse find the crypto maps that are not using AES (based-on
the transform set name). Print these entries and their corresponding
transform set name.
"""
cisco_file = 'cisco_ipsec.txt'
cisco_cfg = CiscoConfParse(cisco_file)
crypto_maps = cisco_cfg.find_objects_wo_child(parentspec=r'crypto map CRYPTO',
childspec=r'AES')
print("\nCrypto maps not using AES:")
for entry in crypto_maps:
for child in entry.children:
if 'transform' in child.text:
match = re.search(r"set transform-set (.*)$", child.text)
encryption = match.group(1)
print(" {} >>> {}".format(entry.text.strip(), encryption))
print()
示例2: main
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def main():
"""
Find all of the crypto map entries in the file (lines that begin with
'crypto map CRYPTO') and print out the children of each crypto map.
"""
cisco_file = 'cisco_ipsec.txt'
cisco_cfg = CiscoConfParse(cisco_file)
crypto_maps = cisco_cfg.find_objects(r"^crypto map CRYPTO")
for c_map in crypto_maps:
print()
print(c_map.text)
for child in c_map.children:
print(child.text)
print()
示例3: main
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def main():
'''
Find all of the crypto map entries in the file (lines that begin with
'crypto map CRYPTO') and print out the children of each crypto map.
'''
cisco_file = 'cisco_ipsec.txt'
cisco_cfg = CiscoConfParse(cisco_file)
crypto_maps = cisco_cfg.find_objects(r"^crypto map CRYPTO")
for c_map in crypto_maps:
print
print c_map.text
for child in c_map.children:
print child.text
print
示例4: main
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def main():
'''
Using ciscoconfparse find the crypto maps that are not using AES (based-on
the transform set name). Print these entries and their corresponding
transform set name.
'''
cisco_file = 'cisco_ipsec.txt'
cisco_cfg = CiscoConfParse(cisco_file)
crypto_maps = cisco_cfg.find_objects_wo_child(parentspec=r'crypto map CRYPTO',
childspec=r'AES')
print "\nCrypto maps not using AES:"
for entry in crypto_maps:
for child in entry.children:
if 'transform' in child.text:
match = re.search(r"set transform-set (.*)$", child.text)
encryption = match.group(1)
print " {0} >>> {1}".format(entry.text.strip(), encryption)
print
示例5: get_device_info
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def get_device_info(device):
"""Get Device Information from Config"""
conf_file = conf_dir + device['Device'] + "-confg"
try:
parse = CiscoConfParse(conf_file)
except:
#print("Warning, could not load config for ", conf_file)
return
else:
dentry = parse_snmp(parse, device['Device'])
dentry['FQDN'] = device['FQDN']
if args.mf:
dentry = parse_model(dentry)
else:
dentry['Model'] = "Unknown"
dentry['Version'] = "Unknown"
device_list.append(dentry)
示例6: update_config_file_parse
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def update_config_file_parse(item_remove, config_file, type):
"""Update config file with unused object-group, ACL, and group-policy statements removed; ciscoconfparse library needed to remove child objects"""
parse = CiscoConfParse(config_file)
for i in item_remove:
if type == 'obg':
for obj in parse.find_objects(r"^object-group network %s" %i):
obj.delete(r"^object-group network %s" %i)
elif type == 'acl':
for obj in parse.find_objects(r"^access-list %s" %i):
obj.delete(r"^access-list %s" %i)
elif type == 'gp':
for obj in parse.find_objects(r"^group-policy %s" %i):
obj.delete(r"^group-policy %s" %i)
config_file_new = []
for line in parse.ioscfg:
config_file_new.append(line)
return config_file_new
示例7: main
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def main():
"""
Use the ciscoconfparse library to find the crypto maps that are using pfs
group2
"""
cisco_file = 'cisco_ipsec.txt'
cisco_cfg = CiscoConfParse(cisco_file)
crypto_maps = cisco_cfg.find_objects_w_child(parentspec=r'crypto map CRYPTO',
childspec=r'pfs group2')
print("\nCrypto Maps using PFS group2:")
for entry in crypto_maps:
print(" {}".format(entry.text))
print()
示例8: confparse_parent
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def confparse_parent(config, parent, child):
"""Returns [match, parent_line, child_line]
Where match is boolean indicating whether a match happened.
parent_line is the parent line that was matched
child_line is the child line that was matched
if match is false, then parent_line will be set, but not child_line.
"""
results = []
try:
# ConfParse requires a list, not a string
config = config.splitlines()
except AttributeError:
pass
try:
# Automatically handle if 'show run' from _command module
config = config['stdout_lines'][0]
except (KeyError, IndexError, TypeError):
pass
cfg_obj = CiscoConfParse(config)
search_results = cfg_obj.find_objects(parent)
for parent_line in search_results:
child_results = parent_line.re_search_children(child)
if child_results:
if len(child_results) > 1:
raise ValueError("Currently only a single child match is supported")
results.append((True, parent_line.text, child_results[0].text))
else:
results.append((False, parent_line.text, None))
return results
示例9: main
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def main():
'''
Use the ciscoconfparse library to find the crypto maps that are using pfs
group2
'''
cisco_file = 'cisco_ipsec.txt'
cisco_cfg = CiscoConfParse(cisco_file)
crypto_maps = cisco_cfg.find_objects_w_child(parentspec=r'crypto map CRYPTO',
childspec=r'pfs group2')
print "\nCrypto Maps using PFS group2:"
for entry in crypto_maps:
print " {0}".format(entry.text)
print
示例10: clean_line
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def clean_line(line, vendor):
cleaned_lines = []
if vendor == 'tmsh':
# Remove text after a # (Because CiscoConfParse crash if there is a
# bracket in a comment
remove_comment = re.search('(?P<before_comment>[^\#]*)\#', line)
if remove_comment:
line = remove_comment.group('before_comment')
# match " begin } end"
tmsh_curly_bracket_left = re.search(
'^(?P<space>\s*)(?P<begin>.*)'
'(?P<bracket>[\}\{])(?'
'P<end>[^\}\{]*)$',
line)
if tmsh_curly_bracket_left:
# replace
# " begin } end"
# by
# " begin }
# end
cleaned_lines = clean_line(tmsh_curly_bracket_left.
group('begin'), vendor)
cleaned_lines.append(tmsh_curly_bracket_left.group('bracket'))
cleaned_lines.append(tmsh_curly_bracket_left.group('end').
rstrip(' \t\r\n\0'))
else:
cleaned_lines.append(line.rstrip(' \t\r\n\0'))
else:
cleaned_lines.append(line.rstrip(' \t\r\n\0'))
return cleaned_lines
示例11: _get_ccp
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def _get_ccp(config=None, config_path=None, saltenv='base'):
'''
'''
if config_path:
config = __salt__['cp.get_file_str'](config_path, saltenv=saltenv)
if config is False:
raise SaltException('{} is not available'.format(config_path))
if isinstance(config, six.string_types):
config = config.splitlines()
ccp = ciscoconfparse.CiscoConfParse(config)
return ccp
# ------------------------------------------------------------------------------
# callable functions
# ------------------------------------------------------------------------------
示例12: get_int
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def get_int(switch, interface):
""" Get a config snippet from a device """
conf_file = conf_dir + switch + extension
interface = expand_port(interface)
try:
parse = CiscoConfParse(conf_file)
except:
print("Error: could not load config for ", conf_file)
sys.exit(1)
search_int = "^interface " + interface + "$"
if args.match:
m = parse.find_objects_w_child(parentspec=search_int,
childspec=args.match)
if m:
print(args.switch + ',' + args.int + ',' + args.match)
else:
iface = parse.find_all_children(search_int)
if iface:
print('!' + switch + ' ' + interface)
for line in iface:
print(line)
if iface:
print('!')
示例13: get_links
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def get_links(device):
"""Get all trunks"""
conf_file = conf_dir + device['Device'] + "-confg"
try:
parse = CiscoConfParse(conf_file)
except:
#print("Warning, could not load config for ", conf_file)
return []
else:
l2_ints = parse_l2_interfaces(parse, device['Device'])
return l2_ints
示例14: get_interfaces
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def get_interfaces(device):
"""Get the Interfaces off a device"""
conf_file = conf_dir + device['Device'] + "-confg"
if device['Type'] == 'Primary' or device['Type'] == 'Standby':
try:
parse = CiscoConfParse(conf_file)
except:
return
else:
default_shut = False
if len(parse.find_objects('no shutdown')):
default_shut = True
vlan_ints = parse_vlan_interfaces(parse, device['Device'], default_shut)
for en in vlan_ints:
en['MgmtGroup'] = device['MgmtGroup']
if device['Type'] == 'Standby':
en['Standby'] = True
else:
en['Standby'] = False
interface_list.append(en)
l3_ints = parse_l3_interfaces(parse, device['Device'], default_shut)
for en in l3_ints:
en['MgmtGroup'] = device['MgmtGroup']
if device['Type'] == 'Standby':
en['Standby'] = True
else:
en['Standby'] = False
interface_list.append(en)
示例15: get_vlans
# 需要导入模块: import ciscoconfparse [as 别名]
# 或者: from ciscoconfparse import CiscoConfParse [as 别名]
def get_vlans(device):
"""Get the VLANs off a device"""
conf_file = conf_dir + device['Device'] + "-confg"
stp = dict()
if device['MgmtGroup'] != 'None':
try:
parse = CiscoConfParse(conf_file)
except:
print("Warning, could not load config for ", conf_file)
return
else:
vdb = parse_vlans(parse, device['Device'])
stp_en = parse.find_objects('^spanning-tree\svlan\s(.*)\spriority\s(\d+)')
for s in stp_en:
catstp = re.search('^spanning-tree\svlan\s(.*)\spriority\s(\d+)', s.text)
stp = getSTP(stp, catstp.group(1), catstp.group(2))
stp_en = parse.find_objects('^\s*vlan\s+(.*)root\spriority\s(\d+)')
for s in stp_en:
peerstp = re.search('^\s*vlan\s+(.*)root\spriority\s(\d+)', s.text)
stp = getSTP(stp, peerstp.group(1), peerstp.group(2))
# for en in stp:
# print(device['Device'], en, stp[en])
for vid in vdb.keys():
stpval = 0
name = vdb[vid]['name']
if vid in stp.keys():
stpval = stp[vid]
#print(device['MgmtGroup'],vid,name,device['Device'],stpval)
saveVLAN(device['MgmtGroup'],vid,name,device['Device'],stpval)