Пример #1
0
 def test_in_subnet(self):
     '''
     Test for returns True if host is within specified
      subnet, otherwise False.
     '''
     with patch.object(salt.utils.network, 'in_subnet', return_value={}):
         self.assertDictEqual(network.in_subnet('iface'), {})
Пример #2
0
def ip_addrs(interface=None, include_loopback=False, cidr=None):
    '''
    Returns a list of IPv4 addresses assigned to the host. 127.0.0.1 is
    ignored, unless 'include_loopback=True' is indicated. If 'interface' is
    provided, then only IP addresses from that interface will be returned.
    Providing a CIDR via 'cidr="10.0.0.0/8"' will return only the addresses
    which are within that subnet.

    CLI Example:

    .. code-block:: bash

        salt '*' network.ip_addrs
    '''
    addrs = salt.utils.network.ip_addrs(interface=interface,
                                        include_loopback=include_loopback)
    if cidr:
        return sorted([i for i in addrs if in_subnet(cidr, [i])],
                      key=lambda item: socket.inet_aton(item))
    else:
        return addrs
Пример #3
0
def ip_addrs(interface=None, include_loopback=False, cidr=None):
    '''
    Returns a list of IPv4 addresses assigned to the host. 127.0.0.1 is
    ignored, unless 'include_loopback=True' is indicated. If 'interface' is
    provided, then only IP addresses from that interface will be returned.
    Providing a CIDR via 'cidr="10.0.0.0/8"' will return only the addresses
    which are within that subnet.

    CLI Example:

    .. code-block:: bash

        salt '*' network.ip_addrs
    '''
    addrs = salt.utils.network.ip_addrs(interface=interface,
                                        include_loopback=include_loopback)
    if cidr:
        return sorted([i for i in addrs if in_subnet(cidr, [i])],
                      key=lambda item: socket.inet_aton(item))
    else:
        return addrs