User Tools

Site Tools


guides:user:scenarios:cmd_parse_juniper

Command parsing on Juniper for interfaces and BGP

Create a new Command Job and save it using a desired name.

Command Job

The job is “empty”. It still requires something though, so it's filled with a '!'.

!

Parsing template basic_error_check

You'll see in the command parsing that no checks are needed since we expect an error as a result. (This is specifically the case for Juniper when applying a show command for which it can't find a result)

!

Parsing template show_bgp_neighbor

The static values are: Peer: and AS. Everything behind AS is ignored. The peerip variable is filled with anything up to the word AS.

Peer: <peerip:AS> AS |*|

Job scenario

# Some variables that are needed in the chained task and templates.
cpe_hostname := CPE-name
Vrf_id := 12345

# These variables are retrieved without additional input.
pe := <node>
PE_interface := <PE_interface@Connected_CPE>
sub_int1 := <sub_int@Connected_CPE>
sub_int2 := <Vlan_id@Connected_CPE>
cpe_ip := <Net_ip_ZV@Connected_CPE>

Description PE parsing and configuration on <node> 
task := scn_pe_config

Scenario scn_pe_config

Description PE parsing checks on <node>

# Test whether node is live and reachable
reachable -n <node>
if <error>
     LogAction -n <node> -a Command_job -m "<node> is not reachable"
    stop
endif
LogAction -n <node> -a Command_job -m "<node> is reachable"

<%cmd> := Parse_cmd -n <node> -t basic_error_check -r "show interfaces <PE_interface>.<sub_int1>"
if <error>
    # The Juniper will provide an error if the interface and subinterface don't exist.
    <succes> := "1"
else
    log -m "Interface exists. Will stop."
    <succes> := "0"
    stop
endif

<%cmd> := Parse_cmd -n <node> -t basic_error_check -r "show interfaces <PE_interface>.<sub_int>"
if <error>
    # The Juniper will provide an error if the interface and subinterface don't exist.
    <succes> := "1"
else
    log -m "Interface exists. Will stop."
    <succes> := "0"
    stop
endif

<%cmd> := Parse_cmd -n <node> -t show_bgp_neighbor -r "show bgp neighbor <cpe_ip>"
if <error>
    log -m "Show bgp neighbor gave an error. Will stop."
    <succes> := "0"
    stop
endif
if <peerip%cmd>
    log -m "BGP neighbor already exists. <peerip%cmd>."
    <succes> := "0"
    stop
else
    <succes> := "1"
endif

# Create the configuration using the template "PE_CPE" and provide the parameters
# "cpe_hostname" and "Vrf_id". These are required for the relation used within the template. 
config_create -n <node> -t PE_CPE
if <error>
  Logaction -n <node> -m "Failed to create PE <node> commands for CPE <CPE_node>"
  Stop
endif

config_exec -n <node>
if <error>
  Logaction -n <node> -m "Failed to configure PE <node> commands for CPE <CPE_node>"
  Stop
endif
guides/user/scenarios/cmd_parse_juniper.txt · Last modified: 2024/07/03 12:31 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki