Exemplo n.º 1
0
    def test_get_iface_from_addr(self, mock_log, mock_ifaddresses,
                                 mock_interfaces):
        mock_ifaddresses.side_effect = lambda iface: DUMMY_ADDRESSES[iface]
        mock_interfaces.return_value = sorted(DUMMY_ADDRESSES.keys())
        addr = 'fe80::3e97:eff:fe8b:1cf7'
        self.assertEqual(net_ip.get_iface_from_addr(addr), 'eth0')

        with nose.tools.assert_raises(Exception):
            net_ip.get_iface_from_addr('1.2.3.4')
def get_mgmt_interface():
    '''
    Returns the managment interface.
    '''
    mgmt_interface = config('mgmt-interface')
    if not mgmt_interface:
        return get_iface_from_addr(unit_get('private-address'))
    elif interface_exists(mgmt_interface):
        return mgmt_interface
    else:
        log('Provided managment interface %s does not exist'
            % mgmt_interface)
        return get_iface_from_addr(unit_get('private-address'))
Exemplo n.º 3
0
def save_ip_tables(host, source_port, dest_port):
    iface = get_iface_from_addr(unit_private_ip())
    host_port = {'host': host, 'source_port': source_port,
                 'dest_port': dest_port, 'iface': iface}
    call("iptables -t nat -A PREROUTING -i {iface} -p tcp --dport {source_port} "
         "-j DNAT --to {host}:{dest_port}".format(**host_port).split())
    call("iptables-save > /etc/iptables/rules.v4".split())
Exemplo n.º 4
0
def get_mgmt_interface():
    '''
    Returns the managment interface.
    '''
    mgmt_interface = config('mgmt-interface')
    if not mgmt_interface:
        try:
            return get_iface_from_addr(unit_get('private-address'))
        except:
            for bridge_interface in get_bridges():
                if (get_host_ip(unit_get('private-address'))
                        in get_iface_addr(bridge_interface)):
                    return bridge_interface
    elif interface_exists(mgmt_interface):
        return mgmt_interface
    else:
        log('Provided managment interface %s does not exist' % mgmt_interface)
        return get_iface_from_addr(unit_get('private-address'))
def get_mgmt_interface():
    '''
    Returns the managment interface.
    '''
    mgmt_interface = config('mgmt-interface')
    if not mgmt_interface:
        try:
            return get_iface_from_addr(unit_get('private-address'))
        except:
            for bridge_interface in get_bridges():
                if (get_host_ip(unit_get('private-address'))
                        in get_iface_addr(bridge_interface)):
                    return bridge_interface
    elif interface_exists(mgmt_interface):
        return mgmt_interface
    else:
        log('Provided managment interface %s does not exist'
            % mgmt_interface)
        return get_iface_from_addr(unit_get('private-address'))