本文整理汇总了Python中ciscoconfparse.CiscoConfParse.append_line方法的典型用法代码示例。如果您正苦于以下问题:Python CiscoConfParse.append_line方法的具体用法?Python CiscoConfParse.append_line怎么用?Python CiscoConfParse.append_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ciscoconfparse.CiscoConfParse
的用法示例。
在下文中一共展示了CiscoConfParse.append_line方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: and
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import append_line [as 别名]
is_switchport_trunk = intf.has_child_with(r'switchport mode trunk')
## Add missing commands
if is_switchport_access and (not has_stormcontrol):
intf.append_to_family(' storm-control action trap')
intf.append_to_family(' storm-control broadcast level 0.4 0.3')
## remove dot1q trunk misconfiguration
elif is_switchport_trunk:
intf.delete_children_matching('port-security')
## Parse the config
parse = CiscoConfParse('switch.conf')
## Add a new switchport at the bottom of the config...
parse.append_line('interface GigabitEthernet1/0')
parse.append_line(' switchport')
parse.append_line(' switchport mode access')
parse.append_line('!')
parse.commit ()
## Search and standardize the interfaces
standardize_interfaces(parse)
parse.commit()
## Add a line to the top of the config if not already there.
if not parse.has_line_with(r'^service\stimestamp'):
parse.prepend_line('service timestamps debug datetime msec localtime show-timezone')
parse.prepend_line('service timestamps log datetime msec localtime show-timezone')
## Wrtite the config file now...
示例2: IPv4Address
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import append_line [as 别名]
# now we create an IP address object from the ARP entry
arp_ipv4_addr = IPv4Address(ipv4)
# assign static arp entry to the VLAN SVI interface
for vlan_svi in vlan_svis:
svi_ipv4_network = IPv4Network(vlan_svi['ipv4_addr'] + "/" + vlan_svi['ipv4_netmask'], strict=False)
if arp_ipv4_addr in svi_ipv4_network.hosts():
# extend the model if the correct IP network is found
if "static_arps" not in vlan_svi.keys():
vlan_svi['static_arps'] = list()
record = {
'ipv4_host': ipv4,
'mac': mac
}
vlan_svi['static_arps'].append(record)
# a static ARP is only defined on a single interface
break
print("Write results to file...")
cisco_nxos_template = CiscoConfParse(['!'])
for vlan_svi in vlan_svis:
cisco_nxos_template.append_line("interface Vlan%s" % vlan_svi['vlan_id'])
for static_arp in vlan_svi['static_arps']:
cisco_nxos_template.append_line(" ip arp %s %s" % (static_arp['ipv4_host'], static_arp['mac']))
cisco_nxos_template.append_line('!')
cisco_nxos_template.save_as(os.path.join(output_dir, "cisco_nxos_config.txt"))
示例3: IPv4Network
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import append_line [as 别名]
# the current SVI address is used as a HSRP virtual IP
virtual_ip = ipv4_addr.ip_object
# at this point we need to determine the next addresses which are used for the primary and secondary switch
# we will try, if the next two addresses are part of the network, otherwise we will use the previous two
# addresses
ipv4_network = IPv4Network(ipv4_addr.network)
if (ipv4_addr.ip_object + 1) in ipv4_network.hosts():
primary_ip = ipv4_addr.ip_object + 1
secondary_ip = ipv4_addr.ip_object + 2
else:
primary_ip = ipv4_addr.ip_object - 1
secondary_ip = ipv4_addr.ip_object - 2
# now add the configuration to the change scripts
primary_config.append_line("interface %s" % vlan_interface_string)
primary_config.append_line(" description *** VLAN SVI %s" % vlan_id)
primary_config.append_line(" ip address %s %s" % (primary_ip, ipv4_addr.netmask))
primary_config.append_line(" standby version 2")
primary_config.append_line(" standby 1 ip %s" % virtual_ip)
primary_config.append_line(" standby 1 priority 255")
primary_config.append_line(" standby 1 authentication md5 key-string vl%s" % vlan_id)
primary_config.append_line("!")
secondary_config.append_line("interface %s" % vlan_interface_string)
secondary_config.append_line(" description *** VLAN SVI %s" % vlan_id)
secondary_config.append_line(" ip address %s %s" % (secondary_ip, ipv4_addr.netmask))
secondary_config.append_line(" standby version 2")
secondary_config.append_line(" standby 1 ip %s" % virtual_ip)
secondary_config.append_line(" standby 1 priority 254")
secondary_config.append_line(" standby 1 authentication md5 key-string vl%s" % vlan_id)
示例4: CiscoConfParse
# 需要导入模块: from ciscoconfparse import CiscoConfParse [as 别名]
# 或者: from ciscoconfparse.CiscoConfParse import append_line [as 别名]
cfgdiff = CiscoConfParse([])
text = config_file
re1='(ag)'
rg = re.compile(re1,re.IGNORECASE|re.DOTALL)
l2agg = rg.search(text)
if l2agg:
for intf in parse.find_objects(r'^interface.+?thernet'):
has_qos_trust = intf.has_child_with(r' mls qos trust dscp')
is_switchport_trunk = intf.has_child_with(r'switchport mode trunk')
is_switchport_infra = intf.has_child_with(r'INFRA:TRUNK*.*')
if (is_switchport_trunk and is_switchport_infra) and (not has_qos_trust):
cfgdiff.append_line("!")
cfgdiff.append_line(intf.text)
cfgdiff.append_line("mls qos trust dscp")
cfgdiff.save_as(config_file+'_new')
print ("Config Created with _new extension for L2AGG")
else:
for intf in parse.find_objects(r'^interface.+?thernet'):
has_qos_trust = intf.has_child_with(r' mls qos trust dscp')
is_switchport_trunk = intf.has_child_with(r'switchport mode trunk')
is_switchport_infra = intf.has_child_with(r'INFRA:TRUNK*.*')
is_switchport_access = intf.has_child_with(r'switchport mode access')
is_switchport_shutdown = intf.has_child_with(r'shutdown')
if (is_switchport_trunk and is_switchport_infra) and (not has_qos_trust):
cfgdiff.append_line("!")
cfgdiff.append_line(intf.text)