def add_ip_address(device, namespace, cidr, scope='global', add_broadcast=True): net = netaddr.IPNetwork(cidr) broadcast = None if add_broadcast and net.version == 4: # NOTE(slaweq): in case if cidr is /32 net.broadcast is None so # same IP address as cidr should be set as broadcast broadcast = str(net.broadcast or net.ip) privileged.add_ip_address(net.version, str(net.ip), net.prefixlen, device, namespace, scope, broadcast)
def add_ip_address(cidr, device, namespace=None, scope='global', add_broadcast=True): """Add an IP address. :param cidr: IP address to add, in CIDR notation :param device: Device name to use in adding address :param namespace: The name of the namespace in which to add the address :param scope: scope of address being added :param add_broadcast: should broadcast address be added """ net = netaddr.IPNetwork(cidr) broadcast = None if add_broadcast and net.version == 4: # NOTE(slaweq): in case if cidr is /32 net.broadcast is None so # same IP address as cidr should be set as broadcast broadcast = str(net.broadcast or net.ip) privileged.add_ip_address( net.version, str(net.ip), net.prefixlen, device, namespace, scope, broadcast)
def add_ip_address(cidr, device, namespace=None, scope='global', add_broadcast=True): """Add an IP address. :param cidr: IP address to add, in CIDR notation :param device: Device name to use in adding address :param namespace: The name of the namespace in which to add the address :param scope: scope of address being added :param add_broadcast: should broadcast address be added """ net = netaddr.IPNetwork(cidr) broadcast = None if add_broadcast and net.version == 4: # NOTE(slaweq): in case if cidr is /32 net.broadcast is None so # same IP address as cidr should be set as broadcast broadcast = str(net.broadcast or net.ip) privileged.add_ip_address(net.version, str(net.ip), net.prefixlen, device, namespace, scope, broadcast)