Blog Viewer

Scripting How-To: Toggle an item in the Junos OS configuration

By Erdem posted 08-06-2015 22:20

  

Toggle an Item in the Junos OS Configuration

 

A simple configlet allows you to toggle the Junos OS configuration.
 
The following example shows how to activate a deactivated knob, or vice versa.

 

Code Example

 

<?xml version="1.0" encoding="iso-8859-1"?><cli-configlets>
<cli-configlet>
<!-- mandatory --><name>LBPolicy - toggle</name>
<!-- mandatory --><category>Example</category>
<context>/device|/device/configuration/routing-options/forwarding-table</context>
<!-- mandatory --><device-family>J/SRX/LN</device-family>
<description>Apply via the Device Management View; or Active Configuration with the forwarding-table selected.

This configlet will disable the export policy if it is already active.</description>
<!-- mandatory --><execution-type>Single</execution-type>
<preview-show-parameters>true</preview-show-parameters>
<preview-show-configuration>true</preview-show-configuration>
<postview-show-parameters>true</postview-show-parameters>
<postview-show-configuration>true</postview-show-configuration>

<cli-configlet-pages><!-- At least one configlet page required -->
<cli-configlet-page>
<page-number>1</page-number>
<!-- mandatory --><cli-text>## Only apply the following if a policy exists
#if ( $policy-check.get(0) != $LB_POLICY )
policy-options {
    policy-statement $LB_POLICY {
        then {
            load-balance per-packet;
        }
    }
}
#end
## Check for deactivated configuration:
#if ( $status.get(0).contains(&apos;&quot;inactive&quot;&apos;) )
routing-options {
    forwarding-table {
        active: export $LB_POLICY;
    }
}
## Check to see if the policy is already active
#elseif ( $export-check.get(0) == $LB_POLICY )
routing-options {
    forwarding-table {
        inactive: export $LB_POLICY;
    }
}
## if its not inactive; and not already there; then add it
#else
routing-options {
    forwarding-table {
        export $LB_POLICY;
    }
}
#end

</cli-text>
</cli-configlet-page>
</cli-configlet-pages>

<cli-configlet-params>
<cli-configlet-param>
<!-- mandatory --><parameter>LB_POLICY</parameter>
<!-- mandatory --><display-name>LB_POLICY</display-name>
<!-- mandatory --><parameter-type>Text Field</parameter-type>
<description/>
<regex-value/>
<configured-value-xpath/>
<default-value>load-balancing-policy</default-value>
<!-- mandatory --><parameter-order>1</parameter-order>
</cli-configlet-param>

<cli-configlet-param>
<!-- mandatory --><parameter>policy-check</parameter>
<!-- mandatory --><display-name>policy-check</display-name>
<!-- mandatory --><parameter-type>Invisible Field</parameter-type>
<description/>
<configured-value-xpath>/device/configuration/policy-options/policy-statement[name=&apos;$LB_POLICY&apos;]/name/text()</configured-value-xpath>
<default-value/>
<!-- mandatory --><parameter-order>2</parameter-order>
</cli-configlet-param>

<cli-configlet-param>
<!-- mandatory --><parameter>status</parameter>
<!-- mandatory --><display-name>status</display-name>
<!-- mandatory --><parameter-type>Invisible Field</parameter-type>
<description/>
<configured-value-xpath>/device/configuration/routing-options/forwarding-table/export/@inactive</configured-value-xpath>
<default-value/>
<!-- mandatory --><parameter-order>3</parameter-order>
</cli-configlet-param>

<cli-configlet-param>
<!-- mandatory --><parameter>export-check</parameter>
<!-- mandatory --><display-name>export-check</display-name>
<!-- mandatory --><parameter-type>Invisible Field</parameter-type>
<description/>
<configured-value-xpath>/device/configuration/routing-options/forwarding-table[export=&apos;$LB_POLICY&apos;]/export/text()</configured-value-xpath>
<default-value/>
<!-- mandatory --><parameter-order>4</parameter-order>
</cli-configlet-param>

</cli-configlet-params>

</cli-configlet>



</cli-configlets>
 

 


#How-To
#configlet
#JunosOS

Permalink