Blogs

Scripting How-To: Enable or disable physical interfaces

By Erdem posted 08-06-2015 22:18

  

Enable or Disable Physical Interfaces

 

You can use a simple configlet to allow multiple selected physical interfaces to be disabled or enabled. 


Similar to the Add Lag Member configlet, this configlet supports multiple selected interfaces across multiple devices. You can also select whether to have 802.3ah LFM protocol information added when enabling an interface, or remove the associated protocol information when disabling an interface. 

 

The configlet has been written so that you can also call it through the NBI. 

 

NOTE: The NBI doesn’t support an array of interfaces to be processed (unless you implement a workaround), unlike with the GUI where multiple interfaces can be used.

 

(Although, to overcome this limitation, I’ve updated the configlet so that it will support multiple interfaces through the NBI, but by using the format ge-1/0/0;ge-1/0/1;ge-1/0/2;... . The configlet just processes the string to create an array when called through the NBI, and ignores that step when called through the GUI.)

 

Code Example

 
01 <?xml version="1.0" encoding="UTF-8"?><cli-configlets>
02 <cli-configlet>
03 <!-- mandatory --><name>Interface Physical Deactivation</name>
04 <!-- mandatory --><category>Ops</category>
05 <context>/device/interface-information/physical-interface</context>
06 <!-- mandatory --><device-family>ACX/J/M/MX/T/TX/PTX/EX92xx</device-family>
07 <description>Deactivates one or multiple interfaces.</description>
08 <!-- mandatory --><execution-type>Grouped</execution-type>
09 <preview-show-parameters>false</preview-show-parameters>
10 <preview-show-configuration>true</preview-show-configuration>
11 <postview-show-parameters>false</postview-show-parameters>
12 <postview-show-configuration>true</postview-show-configuration>
13 <cli-configlet-pages><!-- At least one configlet page required -->
14 <cli-configlet-page>
15 <page-number>1</page-number>
16 <!-- mandatory --><cli-text>## $INTERFACE is an array when called via GUI but scalar when called via NBI
17 ## Convert to an array when not called via GUI
18 ## To support multiple interfaces via the NBI, use the format ge-1/0/0;ge-1/0/1;ge-1/0/2;...
19 #if ( !$CONTEXT )
20 #set ( $INTERFACE = $INTERFACE.split(";") )
21 #end
22 interfaces {
23 #foreach ( $INTF in $INTERFACE )
24     $INTF {
25         disable;
26     }
27 #end
28 }</cli-text>
29 </cli-configlet-page>
30 </cli-configlet-pages>
31 <cli-configlet-params>
32 </cli-configlet-params>
33 </cli-configlet>
34 <cli-configlet>
35 <!-- mandatory --><name>Interface Physical Activation</name>
36 <!-- mandatory --><category>Ops</category>
37 <context>/device/interface-information/physical-interface</context>
38 <!-- mandatory --><device-family>ACX/J/M/MX/T/TX/PTX/EX92xx</device-family>
39 <description>Activates one or multiple interfaces.</description>
40 <!-- mandatory --><execution-type>Grouped</execution-type>
41 <preview-show-parameters>false</preview-show-parameters>
42 <preview-show-configuration>true</preview-show-configuration>
43 <postview-show-parameters>false</postview-show-parameters>
44 <postview-show-configuration>true</postview-show-configuration>
45 <cli-configlet-pages><!-- At least one configlet page required -->
46 <cli-configlet-page>
47 <page-number>1</page-number>
48 <!-- mandatory --><cli-text>## $INTERFACE is an array when called via GUI but scalar when called via NBI
49 ## Convert to an array when not called via GUI
50 ## To support multiple interfaces via the NBI, use the format ge-1/0/0;ge-1/0/1;ge-1/0/2;...
51 #if ( !$CONTEXT )
52 #set ( $INTERFACE = $INTERFACE.split(";") )
53 #end
54 interfaces {
55 #foreach ( $INTF in $INTERFACE )
56     $INTF {
57         delete: disable;
58     }
59 #end
60 }</cli-text>
61 </cli-configlet-page>
62 </cli-configlet-pages>
63 <cli-configlet-params>
64 </cli-configlet-params>
65 </cli-configlet>
66 </cli-configlets>

 


#JunosSpace
#cli
#How-To
#configlet
#interface
#ScriptingHow-To
#NBI