- Can we update the interface ip address as <ip address>/<netmask> instead of
- separating in primary.address and primary.netmask.
- If so, what does the syntax look like.
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.
it's all software, so you can create your own levels of abstraction on top of what the model provides.
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 <<<<<<<
Comments
0 comments
Please sign in to leave a comment.