cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1135
Views
5
Helpful
7
Comments
Chandra L
Cisco Employee
Cisco Employee

Hi,

 

I have a simple service to configure an IP under loopback interface, but how do I delete the IP, if the one I am going to configure is pre-existing on another interface or at least give a warning that this IP is already in use?

 

Here is my yang file - 

 

module colour {
namespace "http://com/example/colour";
prefix colour;

import ietf-inet-types {
prefix inet;
}
import tailf-ncs {
prefix ncs;
}
import tailf-common {
prefix tailf;
}
list colour {
key name;

leaf name {
type string;
}

uses ncs:service-data;
ncs:servicepoint "colour";

leaf colour {
tailf:info "Select the Colour for SLA";
type enumeration {
enum BLUE;
enum GREEN;
enum RED;
}
}

leaf intf {
tailf:info "Select Loopback Interface number";
type enumeration {
enum 101;
enum 102;
enum 103;
}
}
leaf ip_address {
tailf:info "Select IP Address";
type enumeration {
enum 11.1.1.1;
enum 11.1.1.100;
enum 11.1.1.200;
}
}
}
}

7 Comments
nso20
Level 1
Level 1

Hello,

I think this request needs python maapi intervention, you need to parse all the interfaces and check if any of them have ip address the same as the service is trying to configure. Then, in python, you can make your decision either fail and exit or just raise a log warning.

 

Chandra L
Cisco Employee
Cisco Employee

Thank you for giving me this hint. I had a brief look, it is not a simple logic that I could easily implement in the current YANG file. Looks like it is going to complicate my current service. Probably for now, I will just let the user know that they have to take care of this duplicate IP manually.

erdemk
Level 1
Level 1

Hello Chandra,

 

I am not completely sure if i understood your question correct, but afaiu you want ip_address to be unique through out your network. Below are 2 options to do that  : 

option 1 : 

leaf ip_address {
  tailf:info "Select IP Address";
  type enumeration {
    enum 11.1.1.1;
    enum 11.1.1.100;
    enum 11.1.1.200;
  }
  must "count(../../colour[name != current()/../name]/ip_address = current()) = 0" {
    error-message "ip address already in use.";
  }

}

 

option 2:


list colour {
  key name;

  leaf name {
  type string;
  }

  unique ip_address;

  ..

}

regards,

vleijon
Cisco Employee
Cisco Employee
I also want to mention tailf:unique-selector 5he standard YANG statement 'unique' can be used to check for uniqueness within a single list only. Specifically, it cannot be used to check for uniqueness of leafs within a sublist. But with unique-selector you can do more things like that. It is documented in the tailf_yang_extensions manpage.

Chandra L
Cisco Employee
Cisco Employee

Thank you erdemk for your suggestions, as I understand with option 1 you mentioned as below, NSO will check if the IP is already within colour service, if so "ip address already in use".  But if the IP address is not used in colour service, but in use on an interface on the router, will this logic still work?

 

  must "count(../../colour[name != current()/../name]/ip_address = current()) = 0" {
    error-message "ip address already in use.";

Chandra L
Cisco Employee
Cisco Employee

Thank you vleijon  and  erdemk for the information about "unique" option within the yang leaf, I will read this document to understand better on how to use this for my requirement.

For now I am just using the lab as I have it and instructing the users to be cautions about the duplicate IP, as I am running short of time, I will explore these options later on. 

erdemk
Level 1
Level 1

Hello Chandra,

Answer to your question is yes. You will need to model the interface and populate the interface data within NSO.

If this is the question, you can address other parts of your yang model to address for a contraint with must statement, ie. in your case other than "leaf ip_address".

Regards.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: