cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1416
Views
0
Helpful
3
Replies

Can we update the ip address as <ip address>/<netmask> format?

yitung
Cisco Employee
Cisco Employee

Can we update the interface ip address as <ip address>/<netmask> instead of

seperateing in primary.address and primary.netmask??

If so, what does the syntax look like?

1 Accepted Solution

Accepted Solutions

saalvare
Cisco Employee
Cisco Employee

Hey, it's all software, so you can create your own levels of abstraction on top of what the model provides.

View solution in original post

3 Replies 3

einarnn
Cisco Employee
Cisco Employee

I'm afraid it's not possible to do that today. The API is generated from the underlying model, and typically models that need to understand both the address and the netmask will provide separate leaves in the YANG model, and the generated APIs today follow the structure of the model.

Is there any particular reason that you wish to combine the two into a single field?

Thanks,

Einar

saalvare
Cisco Employee
Cisco Employee

Hey, it's all software, so you can create your own levels of abstraction on top of what the model provides.

Hi Santiago,

Yes you are right. Just google that there're the abstraction for this purpose and tested work well...

Thanks a lot!!

import socket

import struct

def cidr_to_netmask(cidr):                         <<<<<

    network, net_bits = cidr.split('/')

    host_bits = 32 - int(net_bits)

    netmask = socket.inet_ntoa(struct.pack('!I', (1 << 32) - (1 << host_bits)))

    return network, netmask

def config_interface_configurations(keys, line, interface_configurations):

       words=line.split(",")

       ipaddr, netmask = cidr_to_netmask(words[15])               <<<<<<<<

       """Add config data to interface_configurations object."""

       # configure IPv4 loopback

       interface_configuration = interface_configurations.InterfaceConfiguration()

       primary = interface_configuration.ipv4_network.addresses.Primary()

       primary.address = ipaddr                                             <<<<<<<

       primary.netmask = netmask                                        <<<<<<<