(ifname, ipv4_if)
Set static IP address for target network interface

    Args:
        ifname  : Network device name
        ipv4_if : IPv4Interface object with the target interface address
Set static IP address for target network interface
Set static IP address for target network interface
def _set_static_iface_ip(ifname, ipv4_if):
    """Set static IP address for target network interface

    Args:
        ifname  : Network device name
        ipv4_if : IPv4Interface object with the target interface address

    """
    isinstance(ipv4_if, IPv4Interface)
    addr = str(ipv4_if.ip)
    addr_with_prefix = ipv4_if.with_prefixlen
    netmask = str(ipv4_if.netmask)

    if (which("netplan") is not None):
        _add_to_netplan(ifname, addr_with_prefix)
    elif (os.path.exists("/etc/network/interfaces.d/")):
        _add_to_interfaces_d(ifname, addr, netmask)
    elif (os.path.exists("/etc/sysconfig/network-scripts")):
        _add_to_sysconfig_net_scripts(ifname, addr, netmask)
    else:
        logger.warning("Falling back to \"ip addr add\" command")
        runner.run(["ip", "addr", "add", addr_with_prefix, "dev", ifname],
                   root=True)
def _set_static_iface_ip ( ifname , ipv4_if ) : isinstance ( ipv4_if , IPv4Interface ) addr = str ( ipv4_if . ip ) addr_with_prefix = ipv4_if . with_prefixlen netmask = str ( ipv4_if . netmask ) if ( which ( "netplan" ) is not None ) : _add_to_netplan ( ifname , addr_with_prefix ) elif ( os . path . exists ( "/etc/network/interfaces.d/" ) ) : _add_to_interfaces_d ( ifname , addr , netmask ) elif ( os . path . exists ( "/etc/sysconfig/network-scripts" ) ) : _add_to_sysconfig_net_scripts ( ifname , addr , netmask ) else : logger . warning ( "Falling back to \"ip addr add\" command" ) runner . run ( [ "ip" , "addr" , "add" , addr_with_prefix , "dev" , ifname ] , root = True )