Junos Space Developer
Highlighted
Junos Space Developer

Configlet - removing a logical unit

‎08-04-2016 02:40 PM

I'm trying to delete a logical unit, leaving all the other units and the physical interface untouched.   

My configlet looks as follows:

configlet.jpg

 

When I try to deploy this, I go to the logical interface I wish to delete, right-click and select the configlet, and the following appears - for some reason the built-in variable $UNIT seems to be producing the physical interface name in curly brackets.  Naturally this isn't valid config, and validation fails:

 

Mconfiglet-error.jpg

 

Maybe I'm missing something obvious?   If I try "delete: $UNIT.get(0)" I get this in the validation window instead:

 

interfaces {
 ge-1/0/9 {
   delete: $UNIT.get(0)
 }
}

 

Any pointers for a configlet newbie?

 

Cheers,

A.

 

 

 

 

5 REPLIES 5
Highlighted
Junos Space Developer

Re: Configlet - removing a logical unit

‎08-05-2016 01:41 AM

Hi Andrew

 

The reason your configlet didn't work is the $UNIT builtin variable is a map, not a simple scalar variable.

 

Similar to the $INTERFACE variable being an array (allowing you to select multiple interfaces), the $UNIT variable contains the name of the INTERFACE to which the UNIT belongs and also supports multiple values.  So the $UNIT varibale is a map of arrays.

 

So selecting ge-0/0/1.0 will result in the following:

 

$INTERFACE = [ "ge-0/0/1" ]

$UNIT = { "ge-0/0/1" = [ "0" ] }

 

So for the case where you can only select a single interface you should de-reference the UNIT by saying:

 

$UNIT.get($INTERFACE.get(0)).get(0)

 

For example:

 

Configlet_unit_01.JPG

 

Leads to this result:

 

Configlet_unit_02.JPG

 

C

Highlighted
Junos Space Developer

Re: Configlet - removing a logical unit

‎08-05-2016 01:43 AM

Here is the configlet:

 

Configlet_unit_03.JPG

Highlighted
Junos Space Developer

Re: Configlet - removing a logical unit

‎08-05-2016 09:04 AM

All working - thanks Ashley.  Here's my configlet:

 

## Configlet executes in the logical interface context. Means you can right-click a
## logical interface and run this configlet to delete it. The configlet inherits the
## physical and logical interface details from where the user is in the GUI.
## No parameters apart from the built-in ones $UNIT and $INTERFACE are
## needed, so the parameter page of the configlet is blank.
##
## First, delete the logical unit:

interfaces {
  $INTERFACE.get(0) {
    delete: unit $UNIT.get($INTERFACE.get(0)).get(0);
  }
}

## Then delete the same interface from the routing instance:

routing-instances {
  INTERNET-VRF {
    delete: interface $INTERFACE.get(0).$UNIT.get($INTERFACE.get(0)).get(0);
  }
}

 

It needs more work, but thanks - you got me over a hurdle.


Cheers,

A.

Highlighted
Junos Space Developer

Re: Configlet - removing a logical unit

‎02-28-2018 05:19 AM

I have a almost similar situation, i have created a cli configlet with a selectionfield of what reth interface to put a vlan. 

 

/device/configuration/interfaces/interface[name="$INTERFACE.get(0)).get(0)"]/unit/name/text()

 

But the validation looks like this.

 

interface [reth0].12;

That failes. How do i strip the []?

 

Highlighted
Junos Space Developer

Re: Configlet - removing a logical unit

‎03-20-2019 05:53 AM

In your configlet add "$interface[0]" for parameter and variable.

in your  next window edit your parameter and select "selection" next > "selection action xpath "  add this string "/device/interface-information/physical-interface/name/text()"

 

should be good to go.