def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # enabled N/A # state_change_disable N/A # interface <interface_name> with configurations.submode_context( attributes.format('interface {interface_name}', force=True)): # interface <interface_name> # standby version <version> configurations.append_line( attributes.format('standby version {version}')) # interface <interface_name> # standby <bfd> (old) if attributes.value('bfd'): configurations.append_line('standby bfd') # interface <interface_name> # standby bfd if attributes.value('bfd_enabled'): configurations.append_line('standby bfd') # bfd_interval N/A # bfd_detection_multiplier N/A # bfd_address N/A # bfd_interface_name # interface <interface_name> # standby delay minimum <minimum_delay> \ # reload <reload_delay> if attributes.value('minimum_delay') and \ attributes.value('reload_delay'): configurations.append_line( attributes.format( 'standby delay minimum {minimum_delay} ' 'reload {reload_delay}')) elif attributes.value('minimum_delay'): configurations.append_line( attributes.format( 'standby delay minimum {minimum_delay}')) # interface <interface_name> # standby mac-refresh <mac_refresh> if attributes.value('mac_refresh'): configurations.append_line( attributes.format( 'standby mac-refresh {mac_refresh}')) # interface <interface_name> # standby use-bia scope interface if attributes.value('use_bia'): configurations.append_line( attributes.format('standby use-bia')) # interface <interface_name> # standby redirect (old) if attributes.value('redirect'): configurations.append_line('standby redirect') # interface <interface_name> # standby redirect if attributes.value('redirects_disable') == False: configurations.append_line('standby redirect') if attributes.value('authentication_word'): # interface <interface_name> # standby <group_number> authentication \ # <authentication_word> (old) configurations.append_line( attributes.format( 'standby {group_number} ' 'authentication {authentication_word}')) elif attributes.value('authentication_text'): # interface <interface_name> # standby <group_number> authentication text \ # <authentication_text> (old) configurations.append_line( attributes.format( 'standby {group_number} ' 'authentication text {authentication_text}')) elif attributes.value('authentication_md5_keychain'): # interface <interface_name> # standby <group_number> authentication \ # md5 key-chain <authentication_md5_keychain> (old) configurations.append_line( attributes.format( 'standby {group_number} authentication ' 'md5 key-chain {authentication_md5_keychain}')) elif attributes.value('authentication_md5_keystring'): # interface <interface_name> # standby <group_number> authentication \ # md5 key-string <authentication_md5_keystring> (old) configurations.append_line( attributes.format( 'standby {group_number} authentication ' 'md5 key-string {authentication_md5_keystring}' )) # interface <interface_name> # standby <group_number> authentication \ # <authentication> configurations.append_line( attributes.format('standby {group_number} ' 'authentication {authentication}')) # interface <interface_name> # standby <group_number> follow <follow> configurations.append_line( attributes.format( 'standby {group_number} follow {follow}')) # interface <interface_name> # standby <group_number> ip <ip_address> (old) if attributes.value('address_family').name == 'ipv4': configurations.append_line( attributes.format( 'standby {group_number} ip {ip_address}')) # interface <interface_name> # standby <group_number> ip <primary_ipv4_address> # standby <group_number> ip <secondary_ipv4_address> secondary if attributes.value('address_family').name == 'ipv4': configurations.append_line( attributes.format( 'standby {group_number} ip {primary_ipv4_address}' )) configurations.append_line( attributes.format( 'standby {group_number} ip {secondary_ipv4_address}' ' secondary')) if attributes.value('virtual_ip_learn'): configurations.append_line( attributes.format('standby {group_number} ip')) # interface <interface_name> # standby <group_number> ipv6 <global_ipv6_address> # standby <group_number> ipv6 <link_local_ipv6_address> if attributes.value('address_family').name == 'ipv6': configurations.append_line( attributes.format('standby {group_number} ipv6 ' '{global_ipv6_address}')) configurations.append_line( attributes.format('standby {group_number} ipv6 ' '{link_local_ipv6_address}')) if attributes.value('hsrp_linklocal'): if attributes.value('hsrp_linklocal').name \ == 'auto': configurations.append_line( attributes.format( 'standby {group_number} ipv6 autoconfig' )) # interface <interface_name> # standby <group_number> mac-address <mac_address> (old) configurations.append_line( attributes.format( 'standby {group_number} mac-address {mac_address}') ) # interface <interface_name> # standby <group_number> mac-address <virtual_mac_address> configurations.append_line( attributes.format('standby {group_number} mac-address ' '{virtual_mac_address}')) # interface <interface_name> # standby <group_number> name <group_name> (old) configurations.append_line( attributes.format( 'standby {group_number} name {group_name}')) # interface <interface_name> # standby <group_number> name <session_name> configurations.append_line( attributes.format( 'standby {group_number} name {session_name}')) if attributes.value('preempt') and \ attributes.value('preempt_minimum_delay') and \ attributes.value('preempt_reload_delay') and \ attributes.value('preempt_sync_delay'): # interface <interface_name> # standby <group_number> preempt delay \ # minimum <preempt_minimum_delay> reload \ # <preempt_reload_delay> sync <preempt_sync_delay> configurations.append_line( attributes.format( 'standby {group_number} ' 'preempt delay minimum {preempt_minimum_delay} ' 'reload {preempt_reload_delay} ' 'sync {preempt_sync_delay}')) elif attributes.value('preempt') and \ attributes.value('preempt_minimum_delay') and \ attributes.value('preempt_reload_delay'): # interface <interface_name> # standby <group_number> preempt delay \ # minimum <preempt_minimum_delay> reload \ # <preempt_reload_delay> configurations.append_line( attributes.format( 'standby {group_number} ' 'preempt delay minimum {preempt_minimum_delay} ' 'reload {preempt_reload_delay}')) elif attributes.value('preempt') and \ attributes.value('preempt_minimum_delay'): # interface <interface_name> # standby <group_number> preempt delay \ # minimum <preempt_minimum_delay> configurations.append_line( attributes.format( 'standby {group_number} ' 'preempt delay minimum {preempt_minimum_delay}' )) elif attributes.value('preempt') and \ attributes.value('preempt_reload_delay'): # interface <interface_name> # standby <group_number> preempt delay \ # reload <preempt_reload_delay> configurations.append_line( attributes.format( 'standby {group_number} ' 'preempt delay reload {preempt_reload_delay}')) elif attributes.value('preempt') and \ attributes.value('preempt_sync_delay'): # interface <interface_name> # standby <group_number> preempt delay \ # sync <preempt_sync_delay> configurations.append_line( attributes.format( 'standby {group_number} ' 'preempt delay sync {preempt_sync_delay}')) elif attributes.value('preempt'): # interface <interface_name> # standby <group_number> preempt configurations.append_line( attributes.format( 'standby {group_number} preempt')) # interface <interface_name> # standby <group_number> priority <priority> configurations.append_line( attributes.format( 'standby {group_number} priority {priority}')) # interface <interface_name> # standby <group_number> timers \ # <hello_interval_seconds> <holdtime_seconds> (old) configurations.append_line( attributes.format( 'standby {group_number} timers ' '{hello_interval_seconds} {holdtime_seconds}')) # interface <interface_name> # standby <group_number> timers msec \ # <hello_interval_msec> msec <holdtime_msec> (old) configurations.append_line( attributes.format( 'standby {group_number} timers msec ' '{hello_interval_msec} msec {holdtime_msec}')) timers_config =\ [attributes.format('standby {group_number} timers ')] if attributes.value('hello_msec_flag') is False and\ attributes.value('hold_msec_flag') is False: timers_config.append(\ attributes.format('{hello_sec} {hold_sec}')) elif attributes.value('hello_msec_flag') is True and\ attributes.value('hold_msec_flag') is False: timers_config.append(\ attributes.format('msec {hello_msec} {hold_sec}')) elif attributes.value('hello_msec_flag') is False and\ attributes.value('hold_msec_flag') is True: timers_config.append(\ attributes.format('{hello_sec} msec {hold_msec}')) elif attributes.value('hello_msec_flag') is True and\ attributes.value('hold_msec_flag') is True: timers_config.append(\ attributes.format('msec {hello_msec} msec ' '{hold_msec}')) if timers_config[1] != '' and None not in timers_config: configurations.append_line(''.join(timers_config)) # interface <interface_name> # standby <group_number> track object <track_object> \ # decrement <priority_decrement> configurations.append_line( attributes.format( 'standby {group_number} track {track_object} ' 'decrement {priority_decrement}')) # interface <interface_name> # standby <group_number> track object <tracked_object> \ # [decrement <tracked_object_priority_decrement>] if attributes.value('tracked_object') and \ attributes.value('tracked_object_priority_decrement'): configurations.append_line( attributes.format( 'standby {group_number} track {tracked_object} ' 'decrement {tracked_object_priority_decrement}' )) elif attributes.value('tracked_object'): configurations.append_line( attributes.format( 'standby {group_number} track {tracked_object}' )) # interface <interface_name> # standby <group_number> track object <track_object> \ # shutdown if attributes.value('track_shutdown'): configurations.append_line( attributes.format( 'standby {group_number} track {track_object} ' 'shutdown')) # tracked_interface N/A # tracked_intf_priority_decrement N/A return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # robustness_variable if attributes.value('robustness_variable'): configurations.append_line( attributes.format('robustness-count ' '{robustness_variable}')) with configurations.submode_context( attributes.format('interface {intf}', force=True)): # enable if attributes.value('enable'): configurations.append_line('router enable') # last_member_query_interval -- not supported on XR # group_policy if attributes.value('group_policy'): configurations.append_line( attributes.format( 'access-group {group_policy}')) # immediate_leave -- not supported on XR # max_groups if attributes.value('max_groups'): configurations.append_line( attributes.format( 'maximum groups-per-interface {max_groups}' )) # query_interval if attributes.value('query_interval'): configurations.append_line( attributes.format( 'query-interval {query_interval}')) # query_max_response_time if attributes.value('query_max_response_time'): configurations.append_line( attributes.format('query-max-response-time ' '{query_max_response_time}')) # version if attributes.value('version'): configurations.append_line( attributes.format('version {version}')) # Mroute Attributes under top level config for groups, attributes2 in attributes.sequence_values( 'groups', sort=True): if unconfig: configurations.append_block( groups.build_unconfig( apply=False, attributes=attributes2, **kwargs)) else: configurations.append_block( groups.build_config(apply=False, attributes=attributes2, **kwargs)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # nxos: vrf context vrf1 (config-vrf) with configurations.submode_context( attributes.format('vrf context {name}', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() # nxos: vrf context vrf1 / rd 1.2:1 v = attributes.value('rd') if v is not None: # if v != 'auto': # v = format(v, 'd.d:d') configurations.append_line('rd {}'.format(v)) # nxos: vrf context vrf1 / vni 1-16777214 if attributes.value('vni'): configurations.append_line(attributes.format('vni {vni}')) # nxos: vrf context vrf1 / address-family ipv4 unicast (config-vrf-af-ipv4) # nxos: vrf context vrf1 / address-family ipv6 unicast (config-vrf-af-ipv6) for key, sub, attributes2 in attributes.mapping_items( 'address_family_attr', keys=self.address_family_attr, sort=True): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) # nxos: vrf context vrf1 / amt flush-routes if attributes.value('amt_flush_routes'): configurations.append_line('amt flush-routes') # nxos: vrf context vrf1 / amt pseudo-interface Ethernet1/1 configurations.append_line( attributes.format( 'amt pseudo-interface {amt_pseudo_interface.name}')) # nxos: vrf context vrf1 / description some line data configurations.append_line( attributes.format('description {description}')) # nxos: vrf context vrf1 / ip ... -> StaticRouting/TODO # nxos: vrf context vrf1 / ipv6 ... -> StaticRouting/TODO # nxos: vrf context vrf1 / shutdown if attributes.value('shutdown'): configurations.append_line('shutdown') # nxos: vrf context vrf1 / vni 4096 topology 1 # comment out due to impot issue (this is from old configuration) # --- ImportError: cannot import name 'ESI' # for vni, attributes2 in attributes.sequence_values('vnis'): # configurations.append_line('vni {}'.format(vni.vni_id)) if apply: if configurations: self.device.configure(configurations, fail_invalid=True) else: return CliConfig(device=self.device, unconfig=unconfig, cli_config=configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # iosxe: router isis 100 (config-isis) context_cli = attributes.format('router isis {pid}', force=True) with configurations.submode_context(context_cli,cancel_empty=True): if unconfig and attributes.iswildcard: configurations.submode_unconfig() # iosxe: router isis 100 / protocol shutdown if attributes.value('shutdown'): configurations.append_line(attributes.format('protocol shutdown')) # iosxe: router isis 100 / is-type level-1 # iosxe: router isis 100 / is-type level-2-only # iosxe: router isis 100 / is-type level-1-2 configurations.append_line(attributes.format('is-type {is_type}', transform={ _Isis.IsType.level_1: 'level-1', _Isis.IsType.level_2: 'level-2-only', _Isis.IsType.level_1_2: 'level-1-2', })) # iosxe: router isis 100 / nsf cisco # iosxe: router isis 100 / nsf ietf configurations.append_line(attributes.format('nsf {nsf}', transform={ _Isis.Nsf.cisco: 'cisco', _Isis.Nsf.ietf: 'ietf', })) # iosxe: router isis 100 / nsr if attributes.value('nsr'): configurations.append_line(attributes.format('nsr')) # iosxe: router isis 100 / distribute link-state if attributes.value('distribute_link_state'): configurations.append_line(attributes.format('distribute link-state')) # iosxe: router isis 100 / segment-routing mpls if attributes.value('segment_routing_mpls'): configurations.append_line(attributes.format('segment-routing mpls')) # iosxe: router isis 100 / segment-routing prefix-sid-map advertise-local if attributes.value('segment_routing_prefix_sid_map_advertise_local'): configurations.append_line(attributes.format('segment-routing prefix-sid-map advertise-local')) # iosxe: router isis 100 / segment-routing prefix-sid-map receive disable if attributes.value('segment_routing_prefix_sid_map_receive') is True: configurations.append_line(attributes.format('segment-routing prefix-sid-map receive')) elif attributes.value('segment_routing_prefix_sid_map_receive') is False: configurations.append_line(attributes.format('segment-routing prefix-sid-map receive disable')) # iosxe: router isis 100 / net 11.0000.0000.0000.0000.00 for net_id, attributes2 in attributes.sequence_values('net_ids', sort=True): configurations.append_line(attributes2.format('net {area_address}.{system_id}.{nsel}')) # iosxe: router isis 100 / passive-interface Loopback0 for sub, attributes2 in attributes.mapping_values('interface_attr', keys=self.interfaces, sort=True): if attributes2.value('passive'): configurations.append_line(attributes2.format('passive-interface {interface.name}',force=True)) for sub, attributes2 in attributes.mapping_values('address_family_attr', keys=self.address_families, sort=True): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) for sub, attributes2 in attributes.mapping_values('interface_attr', keys=self.interfaces, sort=True): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) if apply: if configurations: self.device.configure(configurations) else: return CliConfig(device=self.device, unconfig=unconfig, cli_config=configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # iosxe: mpls ldp router-id {interface.name} # iosxe: mpls ldp router-id vrf xxx {interface.name} if self.vrf_name == 'default': configurations.append_line( attributes.format( 'mpls ldp router-id {router_id.name}')) else: configurations.append_line( attributes.format( 'mpls ldp router-id vrf {vrf_name} {router_id.name}', force=True)) # iosxe : mpls ldp session protection ... if self.vrf_name == 'default': if attributes.value('session_protection'): if attributes.value('session_protection_for_acl' ) and attributes.value( 'session_protection_dur'): configurations.append_line(attributes.format('mpls ldp session protection for '\ '{session_protection_for_acl.name} {session_protection_dur}')) elif attributes.value('session_protection_for_acl'): configurations.append_line(attributes.format('mpls ldp session protection for '\ '{session_protection_for_acl.name}')) elif attributes.value('session_protection_dur'): configurations.append_line( attributes.format( 'mpls ldp session protection for {session_protection_dur}' )) else: configurations.append_line( 'mpls ldp session protection') else: if attributes.value('session_protection'): if attributes.value('session_protection_for_acl' ) and attributes.value( 'session_protection_dur'): configurations.append_line(attributes.format('mpls ldp session protection vrf {vrf_name} for '\ '{session_protection_for_acl.name} {session_protection_dur}',force=True)) elif attributes.value('session_protection_for_acl'): configurations.append_line(attributes.format('mpls ldp session protection vrf {vrf_name} for '\ '{session_protection_for_acl.name}',force=True)) elif attributes.value('session_protection_dur'): configurations.append_line(attributes.format('mpls ldp session protection vrf {vrf_name} for '\ '{session_protection_dur}',force=True)) else: configurations.append_line( attributes.format( 'mpls ldp session protection vrf {vrf_name}', force=True)) # TODO : support more password options, currently only supporting 1 # TODO : supporting encrypted password # iosxe : mpls ldp password option 1 for xx yy ... if self.vrf_name == 'default': if attributes.value('password_for_acl'): configurations.append_line(attributes.format('mpls ldp password option 1 for {password_for_acl} '\ 'password {password}')) else: if attributes.value('password_for_acl'): configurations.append_line(attributes.format('mpls ldp vrf {vrf_name} password option 1 for {password_for_acl} '\ 'password {password}',force=True)) # TODO : supporting encrypted password for neighbor, neighbor_attributes in attributes.mapping_values( 'neighbor_attr', keys=self.neighbors, sort=True): # iosxe: mpls ldp neighbor a.b.c.d password xxx # iosxe: mpls ldp neighbor vrf xxx a.b.c.d password xxx def _transform(neighbor): return str(neighbor).split(':')[0] if neighbor_attributes.value('password'): if self.vrf_name == 'default': configurations.append_line(neighbor_attributes.format('mpls ldp neighbor {neighbor} password {password}', \ transform_neighbor=_transform,force=True)) else: configurations.append_line(neighbor_attributes.format('mpls ldp neighbor vrf {vrf_name} '\ '{neighbor} password {password}', transform_neighbor=_transform, force=True)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # =================================== # ipv4 # prefix_length # ipv4_secondary # route_tag # secondary_vrf # =================================== if attributes.value('ipv4') and attributes.value('prefix_length'): if attributes.value('ipv4_secondary'): configurations.append_line('ip address' ' {ipv4}/{prefix_length} secondary' .format(ipv4=attributes.value('ipv4'), prefix_length=attributes.value('prefix_length'))) if attributes.value('tag'): configurations.append_line('ip address' ' {ipv4}/{prefix_length} secondary' ' tag {route_tag}' .format(ipv4=attributes.value('ipv4'), prefix_length=attributes.value('prefix_length'), route_tag=attributes.value('route_tag'))) elif attributes.value('tag'): configurations.append_line('ip address' ' {ipv4}/{prefix_length}' ' tag {route_tag}' .format(ipv4=attributes.value('ipv4'), prefix_length=attributes.value('prefix_length'), route_tag=attributes.value('route_tag'))) else: configurations.append_line('ip address' ' {ipv4}/{prefix_length}' .format(ipv4=attributes.value('ipv4'), prefix_length=attributes.value('prefix_length'))) if not attributes.value('redirect'): configurations.append_line('no ip redirects') return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, need_elseif=False, exit_cmd=None, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) self.conditional_keys = {} def config_assembly(self, need_elseif=False, unconfig=False, indent_count=0, **kwargs): new_configurations = \ CliConfigBuilder(unconfig=unconfig) # iosxr: if/elif med eq <match_med_eq> if attributes.value('match_med_eq'): self.conditional_keys['match_med_eq'] = \ attributes.format('med eq {match_med_eq}') # iosxr: if/elif origin is <match_origin_eq> if attributes.value('match_origin_eq'): self.conditional_keys['match_origin_eq'] = \ attributes.format('origin is ' '{match_origin_eq.value}') # iosxr: if/elif nexthop in <match_nexthop_in> if attributes.value('match_nexthop_in'): self.conditional_keys['match_nexthop_in'] = \ attributes.format( 'next-hop in {match_nexthop_in}') # iosxr: if/elif nexthop in <match_nexthop_in_v6> if attributes.value('match_nexthop_in_v6'): self.conditional_keys['match_nexthop_in_v6'] = \ attributes.format('next-hop in ' '{match_nexthop_in_v6}') # iosxr: if/elif local-preference eq # <match_local_pref_eq> if attributes.value('match_local_pref_eq'): self.conditional_keys['match_local_pref_eq'] = \ attributes.format('local-preference eq ' '{match_local_pref_eq}') # iosxr: if/elif community matches-any # <match_community_list> if attributes.value('match_community_list'): self.conditional_keys['match_community_list'] = \ attributes.format('community matches-any ' '{match_community_list}') # iosxr: if/elif extcommunity # <match_ext_community_list_type> # matches-any <match_ext_community_list> if attributes.value('match_ext_community_list') and \ attributes.value('match_ext_community_list_type'): self.conditional_keys['match_ext_community_list'] = \ attributes.format('extcommunity ' '{match_ext_community_list_type.value} ' 'matches-any {match_ext_community_list}') # iosxr: if/elif as-path in <match_as_path_list> if attributes.value('match_as_path_list'): self.conditional_keys['match_as_path_list'] = \ attributes.format('as-path in ' '{match_as_path_list}') # iosxr: if/elif as-path length # <match_as_path_length_oper> <match_as_path_length> if attributes.value('match_as_path_length_oper') and \ attributes.value('match_as_path_length'): self.conditional_keys['match_as_path_length'] = \ attributes.format('as-path length ' '{match_as_path_length_oper.value} ' '{match_as_path_length}') # iosxr: if/elif route-type is <match_level_eq> if attributes.value('match_level_eq'): if 'level_1_2' in attributes.value('match_level_eq'): self.conditional_keys['match_level_eq'] = \ attributes.format( 'route-type is interarea') else: self.conditional_keys['match_level_eq'] = \ attributes.format('route-type is ' '{match_level_eq.value}') # iosxr: if/elif ospf-area is <area_eq> if attributes.value('area_eq'): self.conditional_keys['area_eq'] = \ attributes.format('ospf-area is ' '{area_eq}') # iosxr: if/elif destination in <match_prefix_list> if attributes.value('match_prefix_list'): self.conditional_keys['match_prefix_list'] = \ attributes.format('destination in ' '{match_prefix_list}') # iosxr: if/elif destination in <match_prefix_list_v6> if attributes.value('match_prefix_list_v6'): self.conditional_keys['match_prefix_list_v6'] = \ attributes.format('destination in ' '{match_prefix_list_v6}') # iosxr: if/elif tag in <match_tag_list> if attributes.value('match_tag_list'): self.conditional_keys['match_tag_list'] = \ attributes.format('tag in ' '{match_tag_list}') ## Here we construct the config line if self.conditional_keys: if need_elseif: conditional_cfg = attributes.format(' elseif', force=True) else: conditional_cfg = attributes.format('if', force=True) for index, key in enumerate( sorted(self.conditional_keys.keys())): conditional_cfg += ' {}'.format( self.conditional_keys[key]) if index < (len(self.conditional_keys) - 1): conditional_cfg += ' and' else: conditional_cfg += ' then' new_configurations.append_line(conditional_cfg) else: # No spaces should preceed the configuration # if there is no if/else statements indent_count = 0 # Counting the spaces to preceed the configuration # as per the if/else state. spaces = ' ' * indent_count # iosxr: # <statement_name> if attributes.value('statement_name'): new_configurations.append_line( attributes.format(spaces + '# {statement_name}')) # iosxr: # <description> if attributes.value('description'): new_configurations.append_line( attributes.format(spaces + '# {description}')) # iosxr: set origin <set_route_origin> if attributes.value('set_route_origin'): new_configurations.append_line( attributes.format(spaces + 'set origin ' '{set_route_origin}')) # iosxr: set local-preference <set_local_pref> if attributes.value('set_local_pref'): new_configurations.append_line( attributes.format(spaces + 'set local-preference ' '{set_local_pref}')) # iosxr: set next-hop <set_next_hop> if attributes.value('set_next_hop') or \ attributes.value('set_nexthop'): new_configurations.append_line( attributes.format(spaces + 'set next-hop ' '{set_next_hop}')) # iosxr: set next-hop <set_next_hop_v6> if attributes.value('set_next_hop_v6'): new_configurations.append_line( attributes.format(spaces + 'set next-hop ' '{set_next_hop_v6}')) # iosxr: set next-hop self if attributes.value('set_next_hop_self'): new_configurations.append_line( attributes.format(spaces + 'set next-hop self')) # iosxr: set med <set_med> if attributes.value('set_med'): new_configurations.append_line( attributes.format(spaces + 'set med {set_med}')) # iosxr: prepend as-path <set_as_path_prepend> # <set_as_path_prepend_repeat_n> if attributes.value('set_as_path_prepend') and \ attributes.value('set_as_path_prepend_repeat_n'): new_configurations.append_line( attributes.format( spaces + 'prepend as-path ' '{set_as_path_prepend} ' '{set_as_path_prepend_repeat_n}')) # iosxr: set community (<set_community>, no-export, # no-advertise) additive if attributes.value('set_community'): cfg = attributes.format(spaces + 'set community ' '({set_community}', force=True) v1 = attributes.value('set_community_no_export') if v1 is not None: cfg += ' ,no-export' v2 = attributes.value('set_community_no_advertise') if v2 is not None: cfg += ' ,no-advertise' cfg += ')' v3 = attributes.value('set_community_additive') if v3 is not None: cfg += ' additive' new_configurations.append_line(cfg) # iosxr: delete community in <set_community_delete> if attributes.value('set_community_delete'): new_configurations.append_line( attributes.format(spaces + 'delete community in ' '{set_community_delete}')) # iosxr: set extcommunity rt (<set_ext_community_rt>) # [additive] if attributes.value('set_ext_community_rt'): if attributes.value('set_ext_community_rt_additive'): new_configurations.append_line( attributes.format( spaces + 'set extcommunity rt ' '({set_ext_community_rt}) additive')) else: new_configurations.append_line( attributes.format(spaces + 'set extcommunity rt ' '({set_ext_community_rt})')) # iosxr: set extcommunity soo (<set_ext_community_soo>) # [additive] if attributes.value('set_ext_community_soo'): if attributes.value('set_ext_community_soo_additive'): new_configurations.append_line( attributes.format( spaces + 'set extcommunity soo ' '({set_ext_community_soo}) additive')) else: new_configurations.append_line( attributes.format(spaces + 'set extcommunity soo ' '({set_ext_community_soo})')) # iosxr: set extcommunity vpn (<set_ext_community_vpn>) # [additive] if attributes.value('set_ext_community_vpn'): if attributes.value('set_ext_community_vpn_additive'): new_configurations.append_line( attributes.format( spaces + 'set extcommunity vpn ' '({set_ext_community_vpn}) additive')) else: new_configurations.append_line( attributes.format(spaces + 'set extcommunity vpn ' '({set_ext_community_vpn})')) # iosxr: delete extcommunity # <set_ext_community_delete_type> # <set_ext_community_delete> if attributes.value('set_community_delete') and \ attributes.value('set_ext_community_delete_type'): new_configurations.append_line( attributes.format( spaces + 'delete extcommunity ' '{set_ext_community_delete_type.value} ' '{set_community_delete}')) # iosxr: set level <set_level> if attributes.value('set_level'): new_configurations.append_line( attributes.format(spaces + 'set level ' '{set_level}')) # iosxr: set metric-type <set_metric_type> if attributes.value('set_metric_type'): new_configurations.append_line( attributes.format(spaces + 'set metric-type ' '{set_metric_type}')) # iosxr: set isis-metric <set_metric> if attributes.value('set_metric'): new_configurations.append_line( attributes.format(spaces + 'set isis-metric ' '{set_metric}')) # iosxr: set metric-type <set_ospf_metric_type> if attributes.value('set_ospf_metric_type'): new_configurations.append_line( attributes.format(spaces + 'set metric-type ' '{set_ospf_metric_type}')) # iosxr: set ospf-metric <set_ospf_metric> if attributes.value('set_ospf_metric'): new_configurations.append_line( attributes.format(spaces + 'set ospf-metric ' '{set_ospf_metric}')) # iosxr: set tag <set_tag> if attributes.value('set_tag'): new_configurations.append_line( attributes.format(spaces + 'set tag ' '{set_tag}')) # iosxr: set weight <set_weight> if attributes.value('set_weight'): new_configurations.append_line( attributes.format(spaces + 'set weight ' '{set_weight}')) # iosxr: pass|done|drop if attributes.value('actions'): new_configurations.append_line( attributes.format(spaces + '{actions.value}')) return str(new_configurations) if need_elseif: configurations.append_block( config_assembly(self, need_elseif=need_elseif, unconfig=unconfig, indent_count=2)) else: with configurations.submode_context(attributes.format( 'route-policy {policy_definition}', force=True), exit_cmd=None): if unconfig and attributes.iswildcard: # Never reached! configurations.submode_unconfig() configurations.append_block( config_assembly(self, need_elseif=need_elseif, unconfig=unconfig, indent_count=1)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) with configurations.submode_context( attributes.format('vlan access-map {access_map_id}', force=True)): if unconfig and attributes.iswildcard: # Never reached! configurations.submode_unconfig() # No point of configuring access_map_sequence # nxos: vlan access-map <access_map_id> \ # <access_map_sequence> # A workaround that needs to be better handled if attributes.value('access_map_sequence'): configurations.append_line( attributes.format( 'no vlan access-map {access_map_id}')) configurations.append_line( attributes.format( 'vlan access-map {access_map_id} ' '{access_map_sequence}')) # nxos: vlan access-map <access_map_id> / action drop # nxos: vlan access-map <access_map_id> /action forward # nxos: vlan access-map <access_map_id> / action \ # redirect <redirect_interface> if attributes.value('access_map_action') and \ attributes.value('redirect_interface'): configurations.append_line( attributes.format('action {access_map_action} ' '{redirect_interface}')) else: configurations.append_line( attributes.format('action {access_map_action}')) # nxos: vlan access-map <access_map_id> / statistics # nxos: vlan access-map <access_map_id> / exit # nxos: vlan access-map <access_map_id> / match if attributes.value('access_map_match'): if attributes.value('access_list_name'): configurations.append_line( attributes.format('match {access_map_match}' ' address {access_list}')) # nxos: vlan access-map <access_map_id> / no # nxos: vlan access-map <access_map_id> / this # nxos: vlan access-map <access_map_id> / pop # nxos: vlan access-map <access_map_id> / push # nxos: vlan access-map <access_map_id> / where return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # enabled if attributes.value('enabled'): configurations.append_line( attributes.format('feature interface-vlan')) configurations.append_line( attributes.format('feature vn-segment-vlan-based')) # enabled_interface_vlan elif attributes.value('enabled_interface_vlan'): configurations.append_line('feature interface-vlan') # enabled_vn_segment_vlan_based elif attributes.value('enabled_vn_segment_vlan_based'): configurations.append_line('feature vn-segment-vlan-based') # nxos: vlan 1000 (config-vlan) with configurations.submode_context( attributes.format('vlan {vlan_id}', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() # nxos: vlan 1000 / media enet configurations.append_line( attributes.format('media {media.value}')) # nxos: vlan 1000 / name vlan1000 configurations.append_line(attributes.format('name {name}')) # nxos: vlan 1000 / shutdown # nxos: vlan 1000 / no shutdown v = attributes.value('shutdown') if v is not None: if v: configurations.append_line('shutdown', unconfig_cmd='no shutdown') else: configurations.append_line('no shutdown', unconfig_cmd='shutdown') # nxos: vlan 1000 / remote-span if attributes.value('remote_span'): configurations.append_line( attributes.format('remote-span')) # nxos: vlan 1000 / state active # nxos: vlan 1000 / state suspend configurations.append_line( attributes.format('state {status.value}')) # nxos: vlan 1000 / vn-segment 4096 configurations.append_line( attributes.format('vn-segment {vn_segment.vni_id}')) # nxos: vlan dot1q tag native # nxos: vlan dot1q tag native exclude control # nxos: vlan dot1q tag native fabricpath # nxos: vlan dot1q tag native fabricpath exclude control if attributes.value('dot1q_tag_native'): configurations.append_line( attributes.format('vlan dot1q tag native')) # nxos: vlan configuration <Vlan id list> configurations.append_line( attributes.format('vlan configuration' ' {configuration_id_list}')) # nxos: vlan filter <list name> <list of vlans> for sub, attributes2 in attributes.mapping_values( 'access_map_attr', keys=self.access_map_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, **kwargs)) for sub, attributes2 in attributes.mapping_values( 'vlan_configuration_attr', keys=self.vlan_configuration_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, **kwargs)) for sub, attributes2 in attributes.mapping_values( 'interface_attr', keys=self.interface_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, **kwargs)) # new vlan structure for all vlans for sub, attributes2 in attributes.mapping_values( 'vlan_attr', keys=self.vlan_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, **kwargs)) # new vlan structure for vlan_configs for sub, attributes2 in attributes.mapping_values( 'config_vlan_attr', keys=self.config_vlan_attr.keys()): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, **kwargs)) if apply: if configurations: self.device.configure(str(configurations), fail_invalid=True) else: return CliConfig(device=self.device, unconfig=unconfig, cli_config=configurations, fail_invalid=True)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) if isinstance(self.neighbor, PseudowireIPv4Neighbor): # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 (config-l2vpn-bg-bd-vfi-pw) assert self.ip is not None assert self.pw_id is not None nbr_ctx = attributes.format('neighbor {ip} pw-id {pw_id}', force=True) else: raise ValueError(self.neighbor) assert nbr_ctx with configurations.submode_context(nbr_ctx): # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / dhcp ipv4 none # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / dhcp ipv4 snoop profile someword4 v = attributes.value('dhcp_ipv4_snooping_profile') if v is not None: if v is False: configurations.append_line('dhcp ipv4 none') else: configurations.append_line('dhcp ipv4 snoop profile {}'.format(v)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / igmp snooping profile someword4 v = attributes.value('igmp_snooping_profile') if v is not None: if v is False: pass else: configurations.append_line('igmp snooping profile {}'.format(v)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / mld snooping profile someword4 v = attributes.value('mld_snooping_profile') if v is not None: if v is False: pass else: configurations.append_line('mld snooping profile {}'.format(v)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / mpls static label local 16 remote 16 remote_label = attributes.value('mpls_static_label') if remote_label is not None: local_label = self.neighbor_attr[self.local_neighbor].mpls_static_label if local_label is None: warnings.warn( 'neighbor {!r} mpls_static_label missing'.format(self.local_neighbor), UnsupportedAttributeWarning) else: configurations.append_line('mpls static label local {} remote {}'.\ format(local_label, remote_label)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / pw-class someword4 v = attributes.value('pw_class') if v is not None: configurations.append_line('pw-class {}'.\ format(v.device_attr[self.device].name)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / neighbor 1.2.3.4 pw-id 1 / static-mac-address aaaa.bbbb.cccc configurations.append_line(attributes.format('static-mac-address {static_mac_address}')) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp (config-l2vpn-bg-bd-vfi-ad) with configurations.submode_context('autodiscovery bgp'): if not attributes.value('enabled', force=True): configurations.submode_cancel() # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / control-word if attributes.value('control_word'): configurations.append_line('control-word') # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd 1.2.3.4:1 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd 100000:200 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd 100:200000 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / rd auto configurations.append_line(attributes.format('rd {rd}')) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-policy export <rtepol> configurations.append_line(attributes.format('route-policy {export_route_policy}')) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target 1.2.3.4:1 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target 100000:200 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target 100:200000 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export 1.2.3.4:1 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export 100000:200 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export 100:200000 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export import 1.2.3.4:1 (bug) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export import 100000:200 (bug) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target export import 100:200000 (bug) both_route_targets = set(self.export_route_targets) & set(self.import_route_targets) for v, attributes2 in attributes.sequence_values('export_route_targets', sort=True): if v in both_route_targets: cfg = 'route-target {}'.format(v.route_target) else: cfg = 'route-target export {}'.format(v.route_target) if v.stitching: warning.warn(UnsupportedAttributeWarning, 'route-target export/import stitching') configurations.append_line(cfg) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target import 1.2.3.4:1 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target import 100000:200 # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / route-target import 100:200000 for v, attributes2 in attributes.sequence_values('import_route_targets', sort=True): if v not in both_route_targets: cfg = 'route-target import {}'.format(v.route_target) if v.stitching: warning.warn(UnsupportedAttributeWarning, 'route-target export/import stitching') configurations.append_line(cfg) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / signaling-protocol bgp (config-l2vpn-bg-bd-vfi-ad-sig) sub, attributes2 = attributes.namespace('signaling_protocol_bgp') if sub is not None: configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / signaling-protocol ldp (config-l2vpn-bg-bd-vfi-ad-sig) sub, attributes2 = attributes.namespace('signaling_protocol_ldp') if sub is not None: configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) # iosxr: l2vpn / bridge group someword / bridge-domain someword2 / vfi someword3 / autodiscovery bgp / table-policy <rtepol> configurations.append_line(attributes.format('table-policy {table_policy}')) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) if attributes.value('enabled', force=True): # nxos: evpn / vni 4096 l2 / bgp if attributes.value('enabled'): configurations.append_line('bgp') # nxos: evpn / vni 4096 l2 / rd auto # nxos: evpn / vni 4096 l2 / rd 100:200000 # nxos: evpn / vni 4096 l2 / rd 100000:200 # nxos: evpn / vni 4096 l2 / rd 1.2.3.4:1 configurations.append_line( attributes.format('rd {rd}')) # nxos: evpn / vni 4096 l2 / route-target both auto # nxos: evpn / vni 4096 l2 / route-target both 100:200000 # nxos: evpn / vni 4096 l2 / route-target both 100000:200 # nxos: evpn / vni 4096 l2 / route-target both 1.2.3.4:1 both_route_targets = set( self.export_route_targets) & set( self.import_route_targets) # nxos: evpn / vni 4096 l2 / route-target export auto # XXXJST how does this match none in IOS-XR? # nxos: evpn / vni 4096 l2 / route-target export 100:200000 # nxos: evpn / vni 4096 l2 / route-target export 100000:200 # nxos: evpn / vni 4096 l2 / route-target export 1.2.3.4:1 for v, attributes2 in attributes.sequence_values( 'export_route_targets'): if v == 'auto': cfg = 'route-target {} {}'.format( 'both' if v in both_route_targets else 'export', v) else: cfg = 'route-target {} {}'.format( 'both' if v in both_route_targets else 'export', v.route_target) if v.stitching: warnings.warn( 'export bgp route-target stitching', UnsupportedAttributeWarning) configurations.append_line(cfg) # nxos: evpn / vni 4096 l2 / route-target import auto # nxos: evpn / vni 4096 l2 / route-target import 100:200000 # nxos: evpn / vni 4096 l2 / route-target import 100000:200 # nxos: evpn / vni 4096 l2 / route-target import 1.2.3.4:1 for v, attributes2 in attributes.sequence_values( 'import_route_targets'): if v == 'auto': cfg = 'route-target import {}'.format(v) else: cfg = 'route-target import {}'.format( v.route_target) if v.stitching: warnings.warn( 'import bgp route-target stitching', UnsupportedAttributeWarning) configurations.append_line(cfg) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # =================================== # mroute_address/mroute_prefix_mask # mroute_neighbor_address # mroute_interface_name # mroute_admin_distance # mroute_vrf # =================================== # Get vrf and address_family info vrf = kwargs['vrf'] af_name = kwargs['af_name'] if af_name == 'ipv4': af_key = 'ip' else: af_key = 'ipv6' if attributes.value('mroute_address') and \ attributes.value('mroute_prefix_mask') and \ attributes.value('mroute_neighbor_address') and \ attributes.value('mroute_admin_distance') and \ attributes.value('mroute_vrf'): configurations.append_line('{af_key} mroute' ' {mroute_address}/{mroute_prefix_mask}' ' {mroute_neighbor_address} {mroute_admin_distance}' ' vrf {mroute_vrf}'.format(af_key=af_key, mroute_address=attributes.value('mroute_address'), mroute_prefix_mask=attributes.value('mroute_prefix_mask'), mroute_neighbor_address=\ attributes.value('mroute_neighbor_address'), mroute_admin_distance=\ attributes.value('mroute_admin_distance'), mroute_vrf=attributes.value('mroute_vrf'))) elif attributes.value('mroute_address') and \ attributes.value('mroute_prefix_mask') and \ attributes.value('mroute_neighbor_address') and \ attributes.value('mroute_admin_distance'): configurations.append_line('{af_key} mroute' ' {mroute_address}/{mroute_prefix_mask}' ' {mroute_neighbor_address}' ' {mroute_admin_distance}'.format(af_key=af_key, mroute_address=attributes.value('mroute_address'), mroute_prefix_mask=attributes.value('mroute_prefix_mask'), mroute_neighbor_address=\ attributes.value('mroute_neighbor_address'), mroute_admin_distance=\ attributes.value('mroute_admin_distance'))) elif attributes.value('mroute_address') and \ attributes.value('mroute_prefix_mask') and \ attributes.value('mroute_neighbor_address'): configurations.append_line('{af_key} mroute' ' {mroute_address}/{mroute_prefix_mask}' ' {mroute_neighbor_address}'.format(af_key=af_key, mroute_address=attributes.value('mroute_address'), mroute_prefix_mask=\ attributes.value('mroute_prefix_mask'), mroute_neighbor_address=\ attributes.value('mroute_neighbor_address'))) elif attributes.value('mroute_address') and \ attributes.value('mroute_prefix_mask') and \ attributes.value('mroute_interface_name') and \ attributes.value('mroute_admin_distance') and \ attributes.value('mroute_vrf'): configurations.append_line('{af_key} mroute' ' {mroute_address}/{mroute_prefix_mask}' ' {mroute_interface_name} {mroute_admin_distance}' ' vrf {mroute_vrf}'.format(af_key=af_key, mroute_address=attributes.value('mroute_address'), mroute_prefix_mask=attributes.value('mroute_prefix_mask'), mroute_interface_name=\ attributes.value('mroute_interface_name'), mroute_admin_distance=\ attributes.value('mroute_admin_distance'), mroute_vrf=attributes.value('mroute_vrf'))) elif attributes.value('mroute_address') and \ attributes.value('mroute_prefix_mask') and \ attributes.value('mroute_interface_name') and \ attributes.value('mroute_admin_distance'): configurations.append_line('{af_key} mroute' ' {mroute_address}/{mroute_prefix_mask}' ' {mroute_interface_name} {mroute_admin_distance}'.\ format(af_key=af_key, mroute_address=attributes.value('mroute_address'), mroute_prefix_mask=attributes.value('mroute_prefix_mask'), mroute_interface_name=\ attributes.value('mroute_interface_name'), mroute_admin_distance=\ attributes.value('mroute_admin_distance'))) elif attributes.value('mroute_address') and \ attributes.value('mroute_prefix_mask') and \ attributes.value('mroute_interface_name'): configurations.append_line('{af_key} mroute' ' {mroute_address}/{mroute_prefix_mask}' ' {mroute_interface_name}'.format(af_key=af_key, mroute_address=attributes.value('mroute_address'), mroute_prefix_mask=\ attributes.value('mroute_prefix_mask'), mroute_interface_name=\ attributes.value('mroute_interface_name'))) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # =================================== # ipv4 # prefix_length # ipv4_secondary # secondary_vrf # =================================== if attributes.value('ipv4') and attributes.value('prefix_length'): # convert prefix_length to netmask ret = IPv4Network('1.1.1.1/{}'.format( attributes.value('prefix_length')), strict=False) mask = ret.with_netmask.split('/')[1] if attributes.value('ipv4_secondary'): configurations.append_line('ip address' ' {ipv4} {prefix_length} secondary' .format(ipv4=attributes.value('ipv4'), prefix_length=mask)) if attributes.value('secondary_vrf'): configurations.append_line('ip address' ' {ipv4} {prefix_length} secondary' ' vrf {secondary_vrf}' .format(ipv4=attributes.value('ipv4'), prefix_length=mask, secondary_vrf=attributes.value('secondary_vrf'))) else: configurations.append_line('ip address' ' {ipv4} {prefix_length}' .format(ipv4=attributes.value('ipv4'), prefix_length=mask)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # nxos: it enables 3 features once # feature nv overlay # feature vn-segment-vlan-based # feature nv overlay evpn if attributes.value('enabled'): configurations.append_line( attributes.format('feature nv overlay')) configurations.append_line( attributes.format('feature vn-segment-vlan-based')) configurations.append_line( attributes.format('nv overlay evpn')) # nxos: feature nv overlay if attributes.value('enabled_nv_overlay'): if not unconfig or not attributes.value( 'enabled_vn_segment_vlan_based'): configurations.append_line( attributes.format('feature nv overlay')) # nxos: feature vn-segment-vlan-based if attributes.value('enabled_vn_segment_vlan_based'): if unconfig: configurations.append_line( attributes.format('feature nv overlay')) configurations.append_line( attributes.format('feature vn-segment-vlan-based')) # nxos: nv overlay evpn if attributes.value('enabled_nv_overlay_evpn'): configurations.append_line('nv overlay evpn') # nxos: feature ngmvpn if attributes.value('enabled_ngmvpn'): configurations.append_line('feature ngmvpn') # nxos: advertise evpn multicast if attributes.value('advertise_evpn_multicast'): configurations.append_line('advertise evpn multicast') # nxos: abric forwarding anycast-gateway-mac <str> if attributes.value('fabric_fwd_anycast_gw_mac'): if not unconfig: configurations.append_line(\ attributes.format('fabric forwarding anycast-gateway-mac {fabric_fwd_anycast_gw_mac}')) if unconfig and not attributes.value( 'enabled_nv_overlay_evpn'): configurations.append_line( \ attributes.format('fabric forwarding anycast-gateway-mac {fabric_fwd_anycast_gw_mac}')) # EvpnAttributes for sub, attributes2 in attributes.mapping_values( 'evpn_attr', sort=True, keys=self.evpn_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) # EvpnMsiteBgwAttributes for sub, attributes2 in attributes.mapping_values( 'evpn_msite_attr', sort=True, keys=self.evpn_msite_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) if apply: if configurations: self.device.configure(configurations) else: return CliConfig(device=self.device, unconfig=unconfig, cli_config=configurations)
def build_config(self, devices=None, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) with configurations.submode_context( attributes.format('vlan {vlan}', force=True)): if unconfig and attributes.iswildcard: # Never reached! configurations.submode_unconfig() # shutdown if attributes.value('shutdown') == False: configurations.append_line( attributes.format('no shutdown')) elif attributes.value('shutdown') == True: configurations.append_line( attributes.format('shutdown')) # name if attributes.value('name'): configurations.append_line( attributes.format('name {name}')) # state if attributes.value('state'): state_value = attributes.value('state').value configurations.append_line( attributes.format( 'state {state}'.format(state=state_value))) # mode if attributes.value('mode'): state_value = attributes.value('mode').value configurations.append_line( attributes.format('mode {mode.value}')) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # =================================== # ipv6 # ipv6_prefix_length # ipv6_anycast # ipv6_eui_64 # ipv6_route_tag # =================================== cmd = [] # ipv6 address <ipv6>/<ipv6_prefix_length> [ anycast | eui64 ] [ tag <ipv6_route_tag> ] if attributes.value('ipv6') and attributes.value('ipv6_prefix_length'): cmd.append('ipv6 address {ipv6}/{ipv6_prefix_length}'.\ format(ipv6=attributes.value('ipv6'), ipv6_prefix_length=attributes.value('ipv6_prefix_length'))) if attributes.value('ipv6_eui_64') and \ attributes.value('ipv6_anycast') and \ attributes.value('ipv6_route_tag'): cmd.append(' eui64 tag {ipv6_route_tag} anycast'.\ format(ipv6_route_tag=attributes.value('ipv6_route_tag'))) elif attributes.value('ipv6_eui_64') and \ attributes.value('ipv6_route_tag'): cmd.append(' eui64 tag {ipv6_route_tag}'.\ format(ipv6_route_tag=attributes.value('ipv6_route_tag'))) elif attributes.value('ipv6_anycast') and \ attributes.value('ipv6_route_tag'): cmd.append(' tag {ipv6_route_tag} anycast'.\ format(ipv6_route_tag=attributes.value('ipv6_route_tag'))) elif attributes.value('ipv6_eui64'): cmd.append(' eui64') elif attributes.value('ipv6_anycast'): cmd.append(' anycast') elif attributes.value('ipv6_route_tag'): cmd.append(' tag {ipv6_route_tag}'.\ format(ipv6_route_tag=attributes.value('ipv6_route_tag'))) if not attributes.value('redirect'): cmd.append('\nno ipv6 redirects') elif attributes.value('redirect'): cmd.append('\nipv6 redirects') configurations.append_line(''.join(cmd)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) ydk_obj = ned.Native.Vlan() vlan_config = [] for sub, attributes2 in attributes.mapping_values( 'access_map_attr', keys=self.access_map_attr.keys()): vlan_config.extend( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, ydk_obj=ydk_obj, **kwargs)) for sub, attributes2 in attributes.mapping_values( 'vlan_configuration_attr', keys=self.vlan_configuration_attr.keys()): vlan_config.extend( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, ydk_obj=ydk_obj, **kwargs)) for sub, attributes2 in attributes.mapping_values( 'interface_attr', keys=self.interface_attr.keys()): vlan_config.extend( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, ydk_obj=ydk_obj, **kwargs)) # iosxe: vlan 1000 (config-vlan) id = attributes.value('vlan_id', force=True) if id: vlan = ydk_obj.VlanList() vlan.id = int(id) ydk_obj.vlan_list.append(vlan) # instantiate crud service crud_service = CRUDService() if apply: # create netconf connection ncp = NetconfServiceProvider(self.device) if unconfig: crud_service.delete(ncp, ydk_obj) else: crud_service.create(ncp, ydk_obj) else: ydks = [] if unconfig: ydks.append( YangConfig(device=self.device, ydk_obj=ydk_obj, ncp=NetconfServiceProvider, crud_service=crud_service.delete)) else: ydks.append( YangConfig(device=self.device, ydk_obj=ydk_obj, ncp=NetconfServiceProvider, crud_service=crud_service.create)) return ydks
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): '''IOS-XR RoutePolicy configuration. Note: Selective configuration is not supported on IOS-XR; The whole route-policy is always removed and re-configured. ''' assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) if not attributes.iswildcard: warnings.warn( UnsupportedSelectiveRoutePolicyConfig, 'IOS-XR does not support selective route-policy' ' configuration.') attributes = AttributesHelper(self) configurations = CliConfigBuilder() # First remove any existing to avoid CLI warnings if False: # Actually, a commit is needed to avoid the warning, so don't even bother! configurations.append_line( attributes.format('no route-policy {name}', force=True)) # iosxr: route-policy <rtepol> (config-rpl) with configurations.submode_context(attributes.format( 'route-policy {name}', force=True), exit_cmd='end-policy'): configurations.append_block( _build_attributes_cli(self, self, attributes)) # Initializing variables need_end_if = False need_elseif = False for sub, attributes2 in attributes.mapping_values( 'statement_attr', keys=self.statement_attr, sort=True): if not unconfig: configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, need_elseif=need_elseif, exit_cmd=None, **kwargs)) # Checking if 'if' or 'elseif' will be added to the # config if len(self.statement_attr) > 1: need_elseif = True # Means configuartion contains if/else statmenets if sub.conditional_keys: need_end_if = True # Case of unconfig is handled seperately as in XR we can't # unconfig attributes. The whole route-policy need to be # unconfigured. else: configurations.append_block( sub.build_unconfig(apply=False, attributes=attributes2, unconfig=unconfig, need_elseif=need_elseif, exit_cmd=None, **kwargs)) if self.policy_definition and not unconfig: # Case of if/else statements if need_end_if: configurations.append_line(attributes.format(' endif')) configurations.append_line(attributes.format(' end-policy')) configurations.append_line(attributes.format(' exit')) if apply: if configurations: self.device.configure(configurations, fail_invalid=True) else: return CliConfig(device=self.device, unconfig=False, cli_config=configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) hltapi = self.device.hltapi bNeedStcApply = False try: if unconfig: if self.tgen_port_configured: if False: hltkwargs = self._build_interface_config_hltkwargs( attributes=attributes, unconfig=True) if hltkwargs: hltkl = hltapi.interface_config(**hltkwargs) bNeedStcApply = False else: # Spirent HLTAPI drops the whole port instead of the "port_address" host on the port. Do this ourselves... {{{ for host_handle in hltapi.stc_get( self.tgen_port_handle, '-AffiliationPort-Sources', cast_=functools.partial(hltapi.tcl.cast_list, item_cast=tclstr)): if hltapi.stc_get(host_handle, '-Name', cast_=tclstr) == 'port_address': hltapi.stc_delete(host_handle) bNeedStcApply = True self.tgen_port_configured = False else: if self.tgen_port_configured and attributes.iswildcard: # interface_config -mode modify is very flaky (mostly on # Spirent). So destroy the old configuration first. Note # that, for Spirent, hltapi::interface_config is required # to properly handle -mode destroy. self.build_unconfig() hltkwargs = self._build_interface_config_hltkwargs( attributes=attributes) if hltkwargs: # Spirent: arp_target is Spirent-specific if hltkwargs.get('arp_send_req', None) == 1: hltkwargs.setdefault('arp_target', 'all') # Spirent: bugfix SR-1-334940921 if hltkwargs.get('speed', None) == "ether10000": hltkwargs.pop('intf_mode', None) # Spirent: does not support -op_mode hltkwargs.pop('op_mode', None) # Spirent: tx_scrambling/rx_scrambling -> scramble (give precedence to tx_scrambling) if 'tx_scrambling' in hltkwargs: hltkwargs.setdefault('scramble', hltkwargs.pop('tx_scrambling')) if 'rx_scrambling' in hltkwargs: hltkwargs.setdefault('scramble', hltkwargs.pop('rx_scrambling')) hltkl = hltapi.interface_config(**hltkwargs) bNeedStcApply = False self.tgen_port_configured = True if 'interface_handle' in hltkl: self.tgen_handle = hltkl.interface_handle # Spirent: Enable ping response if 'intf_ip_addr' in hltkwargs: for host_handle in hltapi.stc_get( self.tgen_port_handle, '-AffiliationPort-Sources', cast_=functools.partial(hltapi.tcl.cast_list, item_cast=tclstr)): if hltapi.stc_get(host_handle, '-Name', cast_=tclstr) == 'port_address': if not hltapi.stc_get(host_handle, '-EnablePingResponse', cast_=tclstr) != 'TRUE': hltapi.stc_config(host_handle, '-EnablePingResponse', 'TRUE') bNeedStcApply = True finally: if bNeedStcApply: hltapi.stc_apply() bNeedStcApply = False return '' # No CLI lines
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply assert not kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) if self.address_family.name == 'ipv4_unicast': # iosxe: router isis 100 / metric-style wide configurations.append_line(attributes.format('metric-style {metric_style.value}')) # iosxe : router isis 100 / ispf level-1 # iosxe : router isis 100 / ispf level-2 # iosxe : router isis 100 / ispf level-1-2 configurations.append_line(attributes.format('ispf {ispf_type}', transform={ _Isis.IsType.level_1: 'level-1', _Isis.IsType.level_2: 'level-2', _Isis.IsType.level_1_2: 'level-1-2', })) # iosxe: router isis 100 / mpls traffic-eng level-1 # iosxe: router isis 100 / mpls traffic-eng level-2 # iosxe: router isis 100 / mpls traffic-eng level-1 ; mpls traffic-eng level-2 configurations.append_line(attributes.format('mpls traffic-eng {mpls_te_level}', transform={ _Isis.IsType.level_1: 'level-1', _Isis.IsType.level_2: 'level-2', _Isis.IsType.level_1_2: 'level-1\nmpls traffic-eng level-2', })) # iosxe: router isis 100 / mpls traffic-eng router-id <intf> configurations.append_line(attributes.format('mpls traffic-eng router-id {mpls_te_rtrid.name}')) # iosxe : router isis 100 / maximum-paths 32 configurations.append_line(attributes.format('maximum-paths {maximum-paths}')) # iosxe : router isis 100 / mpls ldp autoconfig if attributes.value('ldp_auto_config'): configurations.append_line(attributes.format('mpls ldp autoconfig')) # iosxe : router isis 100 / mpls ldp sync if attributes.value('ldp_sync'): configurations.append_line(attributes.format('mpls ldp sync')) # iosxe : router isis 100 / mpls ldp sync-igp-shortcut if attributes.value('ldp_sync_shortcut'): configurations.append_line(attributes.format('mpls ldp sync-igp-shortcut')) # iosxe : router isis 100 / mpls ldp ac-igp-shortcut if attributes.value('ldp_auto_config_shortcut'): configurations.append_line(attributes.format('mpls ldp ac-igp-shortcut')) # iosxe: router isis 100 / address-family ipv4|ipv6 unicast|multicast (config-isis-af) with configurations.submode_context(attributes.format('address-family {address_family.value}', force=True),\ cancel_empty=True): if unconfig and attributes.iswildcard: configurations.submode_unconfig() if self.address_family.name != 'ipv4_unicast': configurations.append_line(attributes.format('metric-style {metric_style.value}')) return str(configurations)
def build_unconfig(self, clean=False, apply=True, attributes=None, **kwargs): attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=True) if clean: postclean = None # TODO support postclean # Is postclean using commit replace? if not re.search(r'^\s*commit\s+replace\s*$', postclean or '', re.MULTILINE): remove_static_routes = postclean or True # Do it the hard way... cmds_first = CliConfigBuilder() cmds = CliConfigBuilder() cmds_last = CliConfigBuilder() # TODO ignore_errors = {'invalid-input'} l_lab_nets = set() l_netboot_intfs = set() l_netboot_switchport_access_vlans = set() if False: pass # TODO # if { # [info exists ::tb_gateway_addr($::env(TESTBED))] && # [regexp {^(\d+)\.} $::tb_gateway_addr($::env(TESTBED)) - net] # } { lappend l_lab_nets $net } # enaGetTftpServerInfo arr_tftp_info -router $router # if { # [info exists arr_tftp_info(tftp_addr)] && # [regexp {^(\d+)\.} $arr_tftp_info(tftp_addr) - net] # } { lappend l_lab_nets $net } else: # XXXJST the ones I've seen: l_lab_nets.add(IPv4Network('1.0.0.0/8')) l_lab_nets.add(IPv4Network('2.0.0.0/8')) l_lab_nets.add(IPv4Network('5.0.0.0/8')) l_lab_nets.add(IPv4Network('10.0.0.0/8')) l_lab_nets.add(IPv4Network('12.0.0.0/8')) l_lab_nets.add(IPv4Network('172.0.0.0/8')) # TFTP: l_lab_nets.add(IPv4Network('223.255.254.0/24')) from genie.libs.conf.interface import ManagementInterface netboot_link_name = 'netboot' for interface in self.interfaces.values(): is_netboot_interface = isinstance(interface, ManagementInterface) \ or (getattr(interface, 'link', None) and interface.link.name == netboot_link_name) if is_netboot_interface: l_netboot_intfs.add(interface) sw_acc_vlan = getattr(interface, 'sw_acc_vlan', None) if sw_acc_vlan is not None: l_netboot_switchport_access_vlans.add(sw_acc_vlan) if interface.ipv4: l_lab_nets.add(interface.ipv4.network) if interface.ipv6: l_lab_nets.add(interface.ipv6.network) show_run_out = self.execute('show run') show_run_tree = config_cli_to_tree( show_run_out, sort=True) from genie.libs.conf.device.nxos import Device as NxosDevice if isinstance(self, NxosDevice): for line1, subcli1 in show_run_tree or (): m = re.match(r'^feature (?P<feature>.+)', line1) if m: feature = m.group('feature') if feature not in ( 'telnet', 'ssh', 'rise', 'lldp', ): # n5000 5.2(1)N1(1b): lldp feature cannot be removed?!? cmds.append_line('no ' + line1) continue m = re.match(r'^ip route .*tunnel-te', line1) if m: # XXXJST CSC... tunnel routes must be removed before feature mpls traffic-eng cmds_first.append_line('no ' + line1) continue configurations.append_block(cmds_first) cmds_first.clear() configurations.append_block(cmds) cmds.clear() configurations.append_block(cmds_last) cmds_last.clear() if apply and configurations: # TODO enaTbClearFeatureCache $router show_run_out = self.execute('show run') show_run_tree = config_cli_to_tree( show_run_out, sort=True) l_system_channel_groups = set() for line1, subcli1 in show_run_tree or (): m = re.match(r'^!|^$|^end', line1) if m: continue m = re.match(r'^(ip(?:v4|v6)? access-list (?:extended|resequence|role-based|standard) \S+)', line1) if m: cmd = 'no ' + m.group(1) if cmd not in cmds_last: cmds_last.append_line(cmd) continue m = re.match(r'^vpdn enable', line1) \ or re.match(r'^mpls label range', line1) \ or re.match(r'^ip(?:v4|v6)? access-list', line1) \ or re.match(r'^system bridge-domain', line1) if m: cmd = 'no ' + line1 if cmd not in cmds_last: cmds_last.append_line(cmd) continue m = re.match(r'^multilink bundle-name authenticated$', line1) \ or re.match(r'^interface cmp-mgmt', line1) if m: # Ok... should not be test-affecting continue m = re.match(r'^(mpls ldp router-id) ', line1) \ or re.match(r'^(ip(?:v4|v6)? prefix-list \S+)', line1) if m: cmd = 'no ' + m.group(1) if cmd not in cmds: cmds.append_line(cmd) continue m = re.match(r'^(?:ip route|route ip(?:v4)?)(?: vrf \S+)? (?P<ip>\d+\.\d+\.\d+\.\d+)', line1) if m: ip = ip_address(m.group('ip')) if remove_static_routes and not any(ip in lab_net for lab_net in l_lab_nets): cmd = 'no ' + line1 if cmd not in cmds_first: cmds_first.append_line(cmd) continue m = re.match(r'^vrf context management$', line1) \ or re.match(r'^vrf definition (?:Mgmt-intf|mgmtVrf|Mgmt-vrf)$', line1) if m: with cmds.submode_context(line1, cancel_empty=True), \ cmds_first.submode_context(line1, cancel_empty=True): for line2, subcli2 in subcli1 or (): line2 = line2.strip() m = re.match(r'^!|^$', line2) if m: continue m = re.match(r'^(?:ip route|route ip(?:v4)?) (?P<ip>\d+\.\d+\.\d+\.\d+)', line2) if m: ip = ip_address(m.group('ip')) if remove_static_routes and not any(ip in lab_net for lab_net in l_lab_nets): cmd = 'no ' + line2 cmds_first.append_line(cmd) continue # TODO # cmd = 'no ' + line2 # cmds.append_line(cmd) m = re.match(r'^mpls ldp configuration$', line1) \ or re.match(r'^mpls traffic-eng configuration$', line1) if m: with cmds.submode_context(line1, cancel_empty=True): for line2, subcli2 in subcli1 or (): line2 = line2.strip() m = re.match(r'^!|^$', line2) if m: continue m = re.match(r'^no ', line2) if m: # Ok... should not be test-affecting continue cmd = 'no ' + line2 cmds.append_line(cmd) m = re.match(r'^cdp$', line1) \ or re.match(r'^bfd$', line1) \ or re.match(r'^ip(?:v4|v6)? route ', line1) \ or re.match(r'^route ip(?:v4|v6)? ', line1) \ or re.match(r'^arp', line1) \ or re.match(r'^vrf', line1) \ or re.match(r'^ip rsvp', line1) \ or re.match(r'^rsvp', line1) \ or re.match(r'^router msdp', line1) \ or re.match(r'^router ospf', line1) \ or re.match(r'^router isis', line1) \ or re.match(r'^router bgp', line1) \ or re.match(r'^router rip', line1) \ or re.match(r'^router eigrp', line1) \ or re.match(r'^router pim', line1) \ or re.match(r'^router igmp', line1) \ or re.match(r'^router mld', line1) \ or re.match(r'^segment-routing', line1) \ or re.match(r'^multicast-routing', line1) \ or re.match(r'^ipv6 router ospf', line1) \ or re.match(r'^mpls traffic-eng', line1) \ or re.match(r'^mpls optical-uni', line1) \ or re.match(r'^mpls optical-nni', line1) \ or re.match(r'^mpls ldp', line1) \ or re.match(r'^mpls label', line1) \ or re.match(r'^mpls static', line1) \ or re.match(r'^mpls oam', line1) \ or re.match(r'^mpls tp', line1) \ or re.match(r'^ethernet cfm', line1) \ or re.match(r'^interface [lL]oopback', line1) \ or re.match(r'^interface [tT]unnel', line1) \ or re.match(r'^interface [vV]lan(?!1$)', line1) \ or re.match(r'^interface nve', line1) \ or re.match(r'^interface Bundle', line1) \ or re.match(r'^interface PW-Ether', line1) \ or re.match(r'^interface PW-IW', line1) \ or re.match(r'^interface BVI', line1) \ or re.match(r'^interface multiservice', line1) \ or re.match(r'^interface Virtual-TokenRing', line1) \ or re.match(r'^interface .*[:.]\d', line1) \ or re.match(r'^interface .* l2transport', line1) \ or re.match(r'^interface preconfigure', line1) \ or re.match(r'^controller preconfigure', line1) \ or re.match(r'^explicit-path', line1) \ or re.match(r'^ip explicit-path', line1) \ or re.match(r'^ip forward-protocol', line1) \ or re.match(r'^ipv6 route ', line1) \ or re.match(r'^route ipv6 ', line1) \ or re.match(r'^l2 ', line1) \ or re.match(r'^l2vpn', line1) \ or re.match(r'^lldp', line1) \ or re.match(r'^evpn', line1) \ or re.match(r'^bridge-domain', line1) \ or re.match(r'^redundancy$', line1) \ or re.match(r'^lmp', line1) \ or re.match(r'^xconnect', line1) \ or re.match(r'^pw-class', line1) \ or re.match(r'^pseudowire-class', line1) \ or re.match(r'^port-profile', line1) \ or re.match(r'^tag-switching', line1) \ or re.match(r'^vpdn', line1) \ or re.match(r'^key chain', line1) \ or re.match(r'^route-map ', line1) \ or re.match(r'^community-set ', line1) \ or re.match(r'^route-policy ', line1) \ or re.match(r'^multilink ', line1) \ or re.match(r'^spanning-tree ', line1) \ or re.match(r'^generic-interface-list ', line1) if m: cmd = 'no ' + line1 if cmd not in cmds: cmds.append_line(cmd) continue m = re.match(r'^vlan (?P<vlan_spec>[\d,-]+)$', line1) if m: for vlan_range in m.group('vlan_spec').split(','): if '-' in vlan_range: vlan_min, vlan_max = vlan_range.split('-') vlan_range = range(int(vlan_min), int(vlan_max) + 1) else: vlan_range = (int(vlan_min),) for vlan_id in vlan_range: if vlan_id == 1: continue cmds.append_line('no vlan {}'.format(vlan_id)) continue m = re.match(r'^interface [pP]ort-channel(?P<channel_group>\d+)', line1) if m: # Special handling Port-channel interfaces used in VSS and FEX connections channel_group = int(m.group('channel_group')) is_system = False for line2, subcli2 in subcli1 or (): line2 = line2.strip() m = re.match(r'^switchport mode fex-fabric', line2) \ or re.match(r'^switch virtual link', line2) if m: is_system = True break if is_system: l_system_channel_groups.add(channel_group) continue cmd = 'no ' + line1 if cmd not in cmds: cmds.append_line(cmd) continue m = re.match(r'^router static$', line1) if m: with cmds.submode_context(line1, cancel_empty=True): for line2, subcli2 in subcli1 or (): line2 = line2.strip() m = re.match(r'^!|^$', line2) if m: continue m = re.match(r'^address-family ipv4 unicast$', line2) if m: with cmds.submode_context(line2, cancel_empty=True): for line3, subcli3 in subcli2 or (): line3 = line3.strip() m = re.match(r'^!|^$', line3) if m: continue m = re.match(r'^(?P<ip>\d+\.\d+\.\d+\.\d+|(?:::[A-Fa-f0-9]|[A-Fa-f0-9]+:)[A-Fa-f0-9:]*)', line3) if m: ip = ip_address(m.group('ip')) if remove_static_routes and not any(ip in lab_net for lab_net in l_lab_nets): cmd = 'no ' + line3 cmds.append_line(cmd) continue # For debugging only... if debug_clean_config: logger.warn('clean-config: Unrecognized CLI: {} | {} | {}'.format(line1, line2, line3)) continue m = re.match(r'^address-family ', line2) if m: cmd = 'no ' + line2 cmds.append_line(cmd) continue # For debugging only... if debug_clean_config: logger.warn('clean-config: Unrecognized CLI: {} | {}'.format(line1, line2)) continue m = re.match(r'^interface (?!GCC\d)(?P<name>\S+)', line1) \ or re.match(r'^controller (?!OTU\d|ODU\d)(?P<name>\S+)', line1) if m: interface_name = m.group('name') with cmds.submode_context(line1, cancel_empty=True): is_mgmt = any(interface.name == interface_name for interface in l_netboot_intfs) \ or interface_name.startswith('MgmtEth') \ or interface_name.startswith('mgmt') if not is_mgmt: m = re.match(r'^vlan(?P<vlan_id>\d+)$', interface_name) if m: vlan_id = int(m.group('vlan_id')) is_mgmt = vlan_id in l_netboot_switchport_access_vlans need_shutdown = (not is_mgmt) \ and isinstance(self, NxosDevice) is_system = False for line2, subcli2 in subcli1 or (): line2 = line2.strip() m = re.match(r'^channel-group (?P<channel_group>\d+)', line2) if m: channel_group = int(m.group('channel_group')) if channel_group in l_system_channel_groups: is_system = True break if not is_system: for line2, subcli2 in subcli1 or (): line2 = line2.strip() m = re.match(r'^!|^$', line2) if m: continue m = re.match(r'^description ', line2) \ or re.match(r'^bundle', line2) \ or re.match(r'^cdp', line2) \ or re.match(r'^ip(v4)? addr', line2) \ or re.match(r'^media-type ', line2) \ or re.match(r'^mac-address ', line2) \ or re.match(r'^switchport$', line2) \ or re.match(r'^vrf member', line2) \ or re.match(r'^ip vrf forwarding', line2) \ or re.match(r'^vrf forwarding', line2) if m: if not is_mgmt: cmd = 'no ' + line2 cmds.append_line(cmd) continue m = re.match(r'^no shutdown$', line2) if m: if not is_mgmt: need_shutdown = True continue m = re.match(r'^ipv6 ', line2) \ or re.match(r'^mtu ', line2) \ or re.match(r'^vrf', line2) \ or re.match(r'^ip router', line2) \ or re.match(r'^ip ospf', line2) \ or re.match(r'^xconnect', line2) \ or re.match(r'^service instance', line2) \ or re.match(r'^l2transport', line2) \ or re.match(r'^ip rsvp', line2) \ or re.match(r'^mpls ip', line2) \ or re.match(r'^mpls label', line2) \ or re.match(r'^mpls traffic-eng', line2) \ or re.match(r'^bundle id ', line2) \ or re.match(r'^bundle-id ', line2) \ or re.match(r'^channel-group ', line2) \ or re.match(r'^lacp period', line2) if m: cmd = 'no ' + line2 cmds.append_line(cmd) continue m = re.match(r'^(?P<kws>speed) ', line2) if m: cmd = 'no ' + m.group('kws') if is_mgmt: continue if re.match(r'^(?:' + r'|'.join([ r'n3\d\d\d', r'n5\d\d\d', ]) + r')$', self.platform): # Don't touch... # neptune3: # NAME: "Chassis", DESCR: "Nexus 3172 Chassis" # PID: N3K-C3172PQ-10GE , VID: V02 , SN: FOC1844R1AW # NAME: "Slot 1", DESCR: "48x10GE + 6x40G Supervisor" # PID: N3K-C3172PQ-10GE , VID: V02 , SN: FOC18454MAA # ERROR: Ethernet1/1: Configuration does not match the transceiver speed continue cmds.append_line(cmd) continue m = re.match(r'^(?P<kws>duplex) ', line2) if m: cmd = 'no ' + m.group('kws') if is_mgmt: continue cmds.append_line(cmd) continue m = re.match(r'^(?P<kws>port-mode) ', line2) \ or re.match(r'^(?P<kws>loopback) ', line2) if m: cmd = 'no ' + m.group('kws') cmds.append_line(cmd) continue m = re.match(r'^shutdown$', line2) if m: need_shutdown = False continue m = re.match(r'^negotiation auto$', line2) \ or re.match(r'^transceiver permit ', line2) \ or re.match(r'^no ', line2) if m: # Ok... should not be test-affecting continue # For debugging only... if debug_clean_config: logger.warn('clean-config: Unrecognized CLI: {} | {}'.format(line1, line2)) if need_shutdown: cmds.append_line('shutdown') continue m = re.match(r'^Building configuration', line1) \ or re.match(r'^Current configuration', line1) \ or re.match(r'^D?RP/\d+/(RP|RSP)?\d+/(CPU)?\d+:', line1) \ or re.match(r'^boot-end-marker$', line1) \ or re.match(r'^boot-start-marker$', line1) \ or re.match(r'^control-plane$', line1) \ or re.match(r'^redundancy$', line1) \ or re.match(r'^boot system ', line1) \ or re.match(r'^card \d', line1) \ or re.match(r'^clock timezone ', line1) \ or re.match(r'^clock summer-time ', line1) \ or re.match(r'^enable password ', line1) \ or re.match(r'^exception crashinfo ', line1) \ or re.match(r'^exception choice ', line1) \ or re.match(r'^exception core-file ', line1) \ or re.match(r'^exception protocol ', line1) \ or re.match(r'^exception dump ', line1) \ or re.match(r'^facility-alarm ', line1) \ or re.match(r'^install feature-set ', line1) \ or re.match(r'^feature-set ', line1) \ or re.match(r'^feature ', line1) \ or re.match(r'^hostname ', line1) \ or re.match(r'^switchname ', line1) \ or re.match(r'^ip classless$', line1) \ or re.match(r'^domain name ', line1) \ or re.match(r'^ip domain name ', line1) \ or re.match(r'^ip gratuitous-arps$', line1) \ or re.match(r'^ip host ', line1) \ or re.match(r'^ip subnet-zero$', line1) \ or re.match(r'^ip tftp source-interface ', line1) \ or re.match(r'^licence grace-period$', line1) \ or re.match(r'^line ', line1) \ or re.match(r'^ntp ', line1) \ or re.match(r'^service internal', line1) \ or re.match(r'^service timestamps ', line1) \ or re.match(r'^username ', line1) \ or re.match(r'^version ', line1) \ or re.match(r'^qos match statistics per-', line1) \ or re.match(r'^ipv4 virtual address ', line1) \ or re.match(r'^logging ', line1) \ or re.match(r'^telnet vrf default ipv4 server max-servers ', line1) \ or re.match(r'^vty-pool default ', line1) \ or re.match(r'^no ', line1) if m: # Ok... should not be test-affecting continue # For debugging only... if debug_clean_config: logger.warn('clean-config: Unrecognized CLI: {}'.format(line1)) if re.match(r'^(?:' + r'|'.join([ r'c?65\d\d', r'c?3750', ]) + r')$', self.platform): cmd = 'show vlan' # TODO # if { [OK] == [enaVerify "router_show '$cmd' result" {set kl [router_show -cmd $cmd -device $router -os_type ios] ; OK} [OK] -format ena_return_code -eval true -log false] } { # foreach vlan [keylkeys kl vlans] { # set cmd "no vlan $vlan" # if { # ![regexp default [keylget kl vlans.$vlan.name]] && # [lsearch -exact $l_netboot_switchport_access_vlans $vlan] == -1 && # [lsearch -exact $cmds_first $cmd] == -1 && # [lsearch -exact $cmds $cmd] == -1 && # [lsearch -exact $cmds_last $cmd] == -1 # } { # lappend cmds $cmd # } # } # } configurations.append_block(cmds_first) cmds_first.clear() configurations.append_block(cmds) cmds.clear() configurations.append_block(cmds_last) cmds_last.clear() if isinstance(self, NxosDevice): if apply and configurations: self.configure(str(configurations), # fail_invalid=True, -- best effort? ) configurations.clear() # TODO enaTbClearFeatureCache $router # Clear system-generated checkpoints to get rid of # any disabled feature configs that could reappear. cmd = 'clear checkpoint database system' self.execute(cmd) if postclean: # ^MAGG(config)# copp profile strict^M^M # ^MThis operation can cause disruption of control traffic. Proceed (y/n)? [no] ^M^M # TODO ignore {invalid-input commit-no-changes no-such-config} configurations.append_block(postclean) # TODO enaTbClearFeatureCache $router configurations.append_block( super().build_unconfig(clean=clean, apply=False, attributes=attributes, **kwargs)) if apply: if configurations: self.configure(str(configurations), # fail_invalid=True, -- best effort? ) else: # Return configuration return CliConfig(device=self, unconfig=True, cli_config=configurations, fail_invalid=True)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) with configurations.submode_context( attributes.format('interface {intf}', force=True)): # enable if attributes.value('enable'): configurations.append_line('ip pim sparse-mode') # last_member_query_interval if attributes.value('last_member_query_interval'): configurations.append_line( attributes.format( 'ip igmp last-member-query-interval ' '{last_member_query_interval}')) # group_policy if attributes.value('group_policy'): configurations.append_line( attributes.format( 'ip igmp access-group {group_policy}')) # immediate_leave if attributes.value('immediate_leave'): configurations.append_line( 'ip igmp immediate-leave ' 'group-list all-groups') # max_groups if attributes.value('max_groups'): configurations.append_line( attributes.format( 'ip igmp limit {max_groups}')) # query_interval if attributes.value('query_interval'): configurations.append_line( attributes.format( 'ip igmp query-interval {query_interval}')) # query_max_response_time if attributes.value('query_max_response_time'): configurations.append_line( attributes.format( 'ip igmp query-max-response-time ' '{query_max_response_time}')) # version if attributes.value('version'): configurations.append_line( attributes.format('ip igmp version {version}')) # Groups Attributes under top level config for groups, attributes2 in attributes.sequence_values( 'groups', sort=True): if unconfig: configurations.append_block( groups.build_unconfig( apply=False, attributes=attributes2, **kwargs)) else: configurations.append_block( groups.build_config(apply=False, attributes=attributes2, **kwargs)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) with configurations.submode_context(attributes.format( 'ssx exporter {exp_id}', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() if attributes.value('source_ip'): configurations.append_line( attributes.format('source {source_ip}')) if attributes.value('dest_ip'): configurations.append_line( attributes.format('destination {dest_ip} use-vrf default')) if attributes.value('source_port') and attributes.value('dest_port'): configurations.append_line( attributes.format('transport udp src-port {source_port} dst-port {dest_port}')) if attributes.value('dscp'): configurations.append_line( attributes.format('dscp {dscp}')) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) if attributes.iswildcard: # iosxe : mpls label protocol ldp configurations.append_line('mpls label protocol ldp', \ unconfig_cmd = 'default mpls label protocol') # iosxe : mpls ip configurations.append_line('mpls ip', \ unconfig_cmd = 'default mpls ip') # iosxe : no mpls ip if attributes.value('shutdown'): configurations.append_line('no mpls ip', \ unconfig_cmd = 'mpls ip') # iosxe : mpls ip default-route if attributes.value('default_route'): configurations.append_line('mpls ip default-route') # iosxe : mpls ldp nsr if attributes.value('nsr'): configurations.append_line('mpls ldp nsr') # iosxe : mpls ldp graceful-restart if attributes.value('gr'): configurations.append_line('mpls ldp graceful-restart') # iosxe : mpls ldp graceful-restart timers forwarding-holding <30-600> configurations.append_line(attributes.format(\ 'mpls ldp graceful-restart timers forwarding-holding {gr_fwdstate_holdtime}')) # iosxe : mpls ldp graceful-restart timers max-recovery <15-600> configurations.append_line(attributes.format(\ 'mpls ldp graceful-restart timers max-recovery {gr_max_recovery}')) # iosxe : mpls ldp graceful-restart timers neighbor-liveness <5-300> configurations.append_line(attributes.format(\ 'mpls ldp graceful-restart timers neighbor-liveness {gr_neighbor_liveness}')) # iosxe : mpls ldp discovery hello interval <1-65535> configurations.append_line(attributes.format(\ 'mpls ldp discovery hello interval {hello_interval}')) # iosxe : mpls ldp discovery hello holdtime <1-65535> configurations.append_line(attributes.format(\ 'mpls ldp discovery hello holdtime {hello_holdtime}')) # iosxe : mpls ldp discovery targeted-hello interval ... configurations.append_line(attributes.format(\ 'mpls ldp discovery targeted-hello interval {targetted_hello_interval}')) # iosxe : mpls ldp discovery targeted-hello holdtime ... configurations.append_line(attributes.format(\ 'mpls ldp discovery targeted-hello holdtime {targetted_hello_holdtime}')) # iosxe : mpls ldp discovery targeted-hello accept # iosxe : mpls ldp discovery targeted-hello accept from ACL_NAME if attributes.value('targeted_hello_accept'): if attributes.value( 'targeted_hello_accept_from_acl') is not None: configurations.append_line(attributes.format(\ 'mpls ldp discovery targeted-hello accept from {targeted_hello_accept_from_acl.name}')) else: configurations.append_line(attributes.format(\ 'mpls ldp discovery targeted-hello accept')) if attributes.value('advertise_expnull'): if attributes.value('advertise_expnull_for_acl') and \ attributes.value('advertise_expnull_to_acl'): configurations.append_line(attributes.format('mpls ldp explicit-null for {advertise_expnull_for_acl.name}'\ ' to {advertise_expnull_to_acl.name}')) elif attributes.value('advertise_expnull_for_acl'): configurations.append_line( attributes.format( 'mpls ldp explicit-null for {advertise_expnull_for_acl.name}' )) else: configurations.append_line('mpls ldp explicit-null') for sub, attributes2 in attributes.mapping_values('vrf_attr', keys=self.vrfs, sort=True): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) for sub, attributes2 in attributes.mapping_values( 'interface_attr', keys=self.interfaces, sort=True): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) if apply: if configurations: self.device.configure(str(configurations), fail_invalid=True) else: return CliConfig(device=self.device, unconfig=unconfig, cli_config=configurations, fail_invalid=True)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) with configurations.submode_context(attributes.format( 'ssx record {rec_id}', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() if attributes.value('egress_queue_drops'): configurations.append_line( attributes.format('collect egress queue drops')) if attributes.value('egress_queue_peak'): configurations.append_line( attributes.format('collect egress queue peak')) if attributes.value('egress_queue_depth'): configurations.append_line( attributes.format('collect egress queue depth')) if attributes.value('ingress_queue_drops'): configurations.append_line( attributes.format('collect ingress queue drops')) if attributes.value('ingress_queue_depth'): configurations.append_line( attributes.format('collect ingress queue depth')) if attributes.value('egress_queue_microburst'): configurations.append_line( attributes.format('collect egress queue microburst')) if attributes.value('ethernet_counters'): configurations.append_line( attributes.format('collect ethernet counters')) if attributes.value('egress_pool_group_depth'): configurations.append_line( attributes.format('collect egress pool-group depth')) if attributes.value('egress_buffer_depth'): configurations.append_line( attributes.format('collect egress buffer depth')) if attributes.value('record_interval'): configurations.append_line( attributes.format('interval {record_interval}')) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # nxos: vrf context vrf1 / address-family ipv4 unicast (config-vrf-af-ipv4) # nxos: vrf context vrf1 / address-family ipv6 unicast (config-vrf-af-ipv6) with configurations.submode_context( attributes.format( 'address-family {address_family.value}', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() # nxos: vrf context vrf1 / address-family ipv4 unicast / export map someword configurations.append_line( attributes.format( 'export map {export_route_policy.name}')) # nxos: vrf context vrf1 / address-family ipv4 unicast / import map someword configurations.append_line( attributes.format( 'import map {import_route_policy.name}')) # nxos: vrf context vrf1 / address-family ipv4 unicast / import vrf default map someword # nxos: vrf context vrf1 / address-family ipv4 unicast / import vrf default 1 map someword v = attributes.value( 'import_from_default_vrf_route_policy') if v is not None: cfg = 'import vrf default' cfg += attributes.format( ' {import_from_default_vrf_route_policy_maximum_prefixes}', force=True) cfg += ' map {}'.format(v) if attributes.value( 'import_from_default_vrf_advertise_as_vpn'): warnings.warn( 'import vrf default map advertise_as_vpn', UnsupportedAttributeWarning) configurations.append_line(cfg) # nxos: vrf context vrf1 / address-family ipv4 unicast / route-target both 1.2.3.4:1 # nxos: vrf context vrf1 / address-family ipv4 unicast / route-target both 100:200 both_route_targets = set(self.export_route_targets) & set( self.import_route_targets) # nxos: vrf context vrf1 / address-family ipv4 unicast / route-target export 1.2.3.4:1 # nxos: vrf context vrf1 / address-family ipv4 unicast / route-target export 100:200 for v, attributes2 in attributes.sequence_values( 'export_route_targets'): if v in both_route_targets: cfg = 'route-target both {}'.format(v.route_target) else: cfg = 'route-target export {}'.format( v.route_target) if v.stitching: cfg += ' auto evpn' configurations.append_line(cfg) # nxos: vrf context vrf1 / address-family ipv4 unicast / route-target import 1.2.3.4:1 # nxos: vrf context vrf1 / address-family ipv4 unicast / route-target import 100:200 for v, attributes2 in attributes.sequence_values( 'import_route_targets'): if v in both_route_targets: continue # done above else: cfg = 'route-target import {}'.format( v.route_target) if v.stitching: cfg += ' auto evpn' configurations.append_line(cfg) # nxos: vrf context vrf1 / address-family ipv4|ipv6 unicast / maximum routes 1 # nxos: vrf context vrf1 / address-family ipv4|ipv6 unicast / maximum routes 1 1 # nxos: vrf context vrf1 / address-family ipv4|ipv6 unicast / maximum routes 1 1 reinstall 1 # nxos: vrf context vrf1 / address-family ipv4|ipv6 unicast / maximum routes 1 warning-only cfg = attributes.format('maximum routes {maximum_prefix}') if cfg: if attributes.value('maximum_prefix_warning_only', force=True): cfg += ' warning-only' else: v = attributes.value('maximum_prefix_threshold', force=True) if v is not None: cfg += ' {}'.format(v) cfg += attributes.format( ' reinstall {maximum_prefix_reinstall_threshold}', force=True) configurations.append_line(cfg) # ---------- Genie Team latest Update --------------- # # import_from_global_map if attributes.value('import_from_global_map'): configurations.append_line( attributes.format( 'import vrf default map' ' {import_from_global_map}', force=True)) # routing_table_limit_number if attributes.value('routing_table_limit_number') and \ attributes.value('alert_percent_value'): configurations.append_line( attributes.format( 'maximum routes {routing_table_limit_number} ' '{alert_percent_value}')) elif attributes.value('routing_table_limit_number') and \ attributes.value('simple_alert'): configurations.append_line( attributes.format( 'maximum routes {routing_table_limit_number} ' 'warning-only')) # loop over all route-target for sub, attributes2 in attributes.mapping_values( 'route_target_attr', keys=self.route_target_attr.keys(), sort=True): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig, **kwargs)) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) # hardware-telemetry ssx with configurations.submode_context(attributes.format( 'hardware-telemetry ssx', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() # +- DeviceAttributes # +- ExporterAttributes for sub, attributes2 in attributes.mapping_values('exporter_attr', sort=True, keys=self.exporter_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) #+- SsxAttributes # +- RecordAttributes for sub, attributes2 in attributes.mapping_values('record_attr', sort=True, keys=self.record_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) #+- SsxAttributes # +- MonitorAttributes for sub, attributes2 in attributes.mapping_values('monitor_attr', sort=True, keys=self.monitor_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) if attributes.value('ssx_system_monitor'): for monitor in attributes.value('ssx_system_monitor'): attributes.obj.monitor_ssx = monitor configurations.append_line( attributes.format('ssx system monitor {monitor_ssx}')) if attributes.value('ssx_id'): configurations.append_line( attributes.format('ssx system system-id {ssx_id}')) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not apply attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) if unconfig: if attributes.attributes['rt_type'] == {'both': None} or\ attributes.attributes['rt_type'] == {'import': None} or\ attributes.attributes['rt_type'] == {'export': None}: for key, value in attributes.attributes[ 'rt_type'].items(): self.tmp_rt_type = key else: self.tmp_rt_type = attributes.attributes['rt_type'] if not self.tmp_rt_type: configurations.append_line( 'route-target import {rt}'.format(rt=self.rt)) configurations.append_line( 'route-target export {rt}'.format(rt=self.rt)) else: if self.tmp_rt_type == 'both' and self.rt != "auto": configurations.append_line( 'route-target import {rt}'.format( rt=self.rt), raw=True) configurations.append_line( 'route-target export {rt}'.format( rt=self.rt), raw=True) else: # route-target <rt_type> <rt> configurations.append_line( 'route-target {type} {rt}'.format( rt=self.rt, type=self.tmp_rt_type), raw=True) # route-target <rt_type> <rt> if not unconfig and attributes.value('rt_type'): if attributes.value( 'rt_type' ).value == 'both' and self.rt != "auto": configurations.append_line( 'route-target import {rt}'.format(rt=self.rt)) configurations.append_line( 'route-target export {rt}'.format(rt=self.rt)) else: # route-target <rt_type> <rt> configurations.append_line( 'route-target {type} {rt}'.format( rt=self.rt, type=attributes.value('rt_type').value)) for sub, attributes2 in attributes.mapping_values( 'protocol_attr', sort=True, keys=self.protocol_attr): configurations.append_block( sub.build_config(apply=False, attributes=attributes2, unconfig=unconfig)) if apply: if configurations: self.device.configure(configurations) else: return CliConfig(device=self.device, unconfig=unconfig, cli_config=configurations) return str(configurations)
def build_config(self, apply=True, attributes=None, unconfig=False, **kwargs): assert not kwargs, kwargs attributes = AttributesHelper(self, attributes) configurations = CliConfigBuilder(unconfig=unconfig) with configurations.submode_context( attributes.format('key {key_id}', force=True)): if unconfig and attributes.iswildcard: configurations.submode_unconfig() # key chain <key_chain> tunnel-encryption # key <key_id> # key-octet-string [key_enc_type] <key_string> [cryptographic-algorithm <crypto_algo>] if attributes.value('key_string'): # + key-octet-string key_string_str = 'key-octet-string' # + [key_enc_type] if attributes.value('key_enc_type'): key_string_str += attributes.format( ' {key_enc_type}') # + <key_string> key_string_str += attributes.format( ' {key_string}') # + [cryptographic-algorithm <crypto_algo>] if attributes.value('crypto_algo'): if attributes.value( 'crypto_algo').value == 'aes-128-cmac': key_string_str += ' cryptographic-algorithm AES_128_CMAC' elif attributes.value( 'crypto_algo').value == 'aes-128-cmac': key_string_str += ' cryptographic-algorithm AES_256_CMAC' configurations.append_line( attributes.format(key_string_str)) # key chain <key_chain> tunnel-encryption # key <key_id> # send-lifetime <lifetime_start> duration <lifetime_duration> if attributes.value( 'lifetime_start') and attributes.value( 'lifetime_duration'): # send-lifetime <lifetime_start> duration <lifetime_duration> lifetime_str = 'send-lifetime {lifetime_start} duration {lifetime_duration}' configurations.append_line( attributes.format(lifetime_str)) return str(configurations)