12-12-2016 08:28 PM
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?
Solved! Go to Solution.
12-13-2016 02:58 PM
Hey, it's all software, so you can create your own levels of abstraction on top of what the model provides.
12-13-2016 01:27 AM
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
12-13-2016 02:58 PM
Hey, it's all software, so you can create your own levels of abstraction on top of what the model provides.
12-13-2016 07:37 PM
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 <<<<<<<
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide