本文整理汇总了Python中ciscoconfparse.CiscoConfParse.find_parents_w_child方法的典型用法代码示例。如果您正苦于以下问题:Python CiscoConfParse.find_parents_w_child方法的具体用法?Python CiscoConfParse.find_parents_w_child怎么用?Python CiscoConfParse.find_parents_w_child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ciscoconfparse.CiscoConfParse
的用法示例。
在下文中一共展示了CiscoConfParse.find_parents_w_child方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
class DhcpConfig:
def __init__(self, config_file):
self.config_file = config_file
self.parse = CiscoConfParse(self.config_file)
def get_dhcppool_config(self, pool_name):
find_result = self.parse.find_children(pool_name)
return find_result
def get_dhcppoolname_list(self):
dhcppoolname_list = []
find_result = self.parse.find_parents_w_child('^ip dhcp pool', 'host')
for parent in find_result:
dhcppoolname_list.append(parent.split()[3])
return dhcppoolname_list
def get_ipaddr(self, pool_name):
find_result = self.parse.find_children(pool_name)
return find_result[1].split()[1]
def get_ipaddrmask(self, pool_name):
find_result = self.parse.find_children(pool_name)
return find_result[1].split()[2]
def get_macaddr(self, pool_name):
find_result = self.parse.find_children(pool_name)
return find_result[2].split()[1]
def get_defaultrouter(self, pool_name):
find_result = self.parse.find_children(pool_name)
return find_result[3].split()[1]
def get_dns(self, pool_name):
find_result = self.parse.find_children(pool_name)
return [find_result[4].split()[1], find_result[4].split()[2]]
示例2: main
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
def main() :
parse = CiscoConfParse("cisco_ipsec.txt")
# Find all crypto map entries and print parent and child
print ("The crypto maps in the parsed config are : \n" )
crypto_objs = parse.find_objects(r"^crypto map CRYPTO")
for obj in crypto_objs :
print (obj.text)
child_obj = (obj.re_search_children(r".*"))
for obj2 in child_obj :
print (obj2.text)
print ("\n")
# Find crypto maps with pfs group2
pfsg2 = parse.find_parents_w_child("crypto map CRYPTO", "set pfs group2" )
print ("The following crypto maps have pfs set to group 2: \n")
for obj in pfsg2 :
print (obj)
# Find crypto maps without AES encryptions
print ("\n")
trans_set = parse.find_parents_wo_child("^crypto map CRYPTO", "set transform-set AES-SHA")
print ("The crypto maps that do not have AES-SHA transform set are : \n")
for obj in trans_set :
print (obj)
示例3: cisco_conf_task_2
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
def cisco_conf_task_2():
print "\n\nCisco parse exersise 2.\n"
cfg_file = CiscoConfParse("cisco_ipsec.txt")
c_maps = cfg_file.find_parents_w_child("^crypto map CRYPTO","^ set pfs group2")
x = 1
for element in c_maps:
print "entry # %s that are using PFS group2: %s" % (x, element)
x += 1
示例4: CiscoConfParse
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
#!/usr/bin/python
#Import modules
from ciscoconfparse import CiscoConfParse
#Search through the config file
parse = CiscoConfParse('conf.txt')
basic_search = parse.find_parents_w_child('^interface', 'trunk')
print basic_search
#Save output to text file
f = open('output.txt', 'w')
print >> f, basic_search
f.close()
#Sanitize the output to replace , with a new line
f = open('output.txt','r')
filedata = f.read()
f.close()
newdata = filedata.replace(", ","\n")
f = open('output.txt','w')
f.write(newdata)
f.close()
#Sanitize he output for '
f = open('output.txt','r')
filedata = f.read()
f.close()
newdata = filedata.replace("'","")
f = open('output.txt','w')
f.write(newdata)
示例5: NetDevices
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
nd = NetDevices()
for deviceName in deviceList:
# commands to run in order to bring the device back to standard
commandList = []
# the current device configuration file is stored here, parse it
p = CiscoConfParse("/home/ioswrite/network-configurations/" + deviceName)
# ---------------------------------------------------------------------------------
# STORM CONTROL: legacy switch configuration
# ---------------------------------------------------------------------------------
# give me a list of interfaces that contain " port storm-control unicast"
interfaceList = p.find_parents_w_child('^interf', '^ port storm-control unicast')
# create the commands so that I can remove this unwanted command
for line in interfaceList:
commandList.append(line)
commandList.append(' no port storm-control unicast action filter')
commandList.append(' no port storm-control unicast trap')
# ---------------------------------------------------------------------------------
# STORM CONTROL: modern switch configuration
# ---------------------------------------------------------------------------------
# give me a list of interfaces that contain "storm-control unicast level"
interfaceList = p.find_parents_w_child('^interf', 'storm-control unicast level')
# create the commands so that I can remove this unwanted command
示例6: testValues_find_parents_w_child
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
def testValues_find_parents_w_child(self):
## test find_parents_w_child
for config, args, result_correct in self.find_parents_w_child_Values:
cfg = CiscoConfParse(config)
test_result = cfg.find_parents_w_child(**args)
self.assertEqual(result_correct, test_result)
示例7: CiscoConfParse
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import find_parents_w_child [as 别名]
#!/usr/bin/env python
from ciscoconfparse import CiscoConfParse
parse = CiscoConfParse("../configs/sample_01.ios")
# Return a list of all ATM interfaces and subinterfaces
atm_intfs = parse.find_lines("^interface\sATM")
# Return a list of all interfaces with a certain QOS policy
qos_intfs = parse.find_parents_w_child( "^interf", "service-policy" )
# Return a list of all active interfaces (i.e. not shutdown)
active_intfs = parse.find_parents_wo_child( "^interf", "shutdown" )