コード例 #1
0
ファイル: frules.py プロジェクト: toby82/calico
def _configure_ipip_device(config):
    """Creates and enables the IPIP tunnel device.
    :raises FailedSystemCall on failure.
    """
    if not devices.interface_exists(IP_IN_IP_DEV_NAME):
        # Make sure the IP-in-IP device exists; since we use the global
        # device, this command actually creates it as a side-effect of
        # initialising the kernel module rather than explicitly creating
        # it.
        _log.info("Tunnel device didn't exist; creating.")
        futils.check_call(["ip", "tunnel", "add", IP_IN_IP_DEV_NAME,
                           "mode", "ipip"])
    futils.check_call(["ip", "link", "set", IP_IN_IP_DEV_NAME, "mtu",
                       str(config.IP_IN_IP_MTU)])
    if not devices.interface_up(IP_IN_IP_DEV_NAME):
        _log.info("Tunnel device wasn't up; enabling.")
        futils.check_call(["ip", "link", "set", IP_IN_IP_DEV_NAME, "up"])
    # Allow an IP address to be added to the tunnel.  This is useful to
    # allow the host to have an IP on a private IPIP network so that it can
    # originate traffic and have it routed correctly.
    _log.info("Setting IPIP device IP to %s", config.IP_IN_IP_ADDR)
    tunnel_addrs = [config.IP_IN_IP_ADDR] if config.IP_IN_IP_ADDR else []
    devices.set_interface_ips(futils.IPV4, IP_IN_IP_DEV_NAME,
                              set(tunnel_addrs))
    _log.info("Configured IPIP device.")
コード例 #2
0
def _configure_ipip_device(config):
    """Creates and enables the IPIP tunnel device.
    :raises FailedSystemCall on failure.
    """
    if not devices.interface_exists(IP_IN_IP_DEV_NAME):
        # Make sure the IP-in-IP device exists; since we use the global
        # device, this command actually creates it as a side-effect of
        # initialising the kernel module rather than explicitly creating
        # it.
        _log.info("Tunnel device didn't exist; creating.")
        futils.check_call(
            ["ip", "tunnel", "add", IP_IN_IP_DEV_NAME, "mode", "ipip"])
    futils.check_call([
        "ip", "link", "set", IP_IN_IP_DEV_NAME, "mtu",
        str(config.IP_IN_IP_MTU)
    ])
    if not devices.interface_up(IP_IN_IP_DEV_NAME):
        _log.info("Tunnel device wasn't up; enabling.")
        futils.check_call(["ip", "link", "set", IP_IN_IP_DEV_NAME, "up"])
    # Allow an IP address to be added to the tunnel.  This is useful to
    # allow the host to have an IP on a private IPIP network so that it can
    # originate traffic and have it routed correctly.
    _log.info("Setting IPIP device IP to %s", config.IP_IN_IP_ADDR)
    tunnel_addrs = [config.IP_IN_IP_ADDR] if config.IP_IN_IP_ADDR else []
    devices.set_interface_ips(futils.IPV4, IP_IN_IP_DEV_NAME,
                              set(tunnel_addrs))
    _log.info("Configured IPIP device.")
コード例 #3
0
ファイル: test_devices.py プロジェクト: wrouesnel/calico
 def test_set_interface_ips(self):
     with mock.patch('calico.felix.futils.check_call',
                     autospec=True) as m_check_call:
         with mock.patch("calico.felix.devices.list_interface_ips",
                         autospec=True) as m_list_ips:
             m_list_ips.return_value = set(
                 [IPAddress("10.0.0.1"),
                  IPAddress("10.0.0.2")])
             devices.set_interface_ips(
                 futils.IPV4, "tunl0",
                 set([IPAddress("10.0.0.2"),
                      IPAddress("10.0.0.3")]))
             self.assertEqual(m_check_call.mock_calls, [
                 mock.call(
                     ["ip", "addr", "del", "10.0.0.1", "dev", "tunl0"]),
                 mock.call(
                     ["ip", "addr", "add", "10.0.0.3", "dev", "tunl0"]),
             ])
コード例 #4
0
ファイル: test_devices.py プロジェクト: is00hcw/calico
 def test_set_interface_ips(self):
     with mock.patch('calico.felix.futils.check_call',
                     autospec=True) as m_check_call:
         with mock.patch("calico.felix.devices.list_interface_ips",
                         autospec=True) as m_list_ips:
             m_list_ips.return_value = set([IPAddress("10.0.0.1"),
                                            IPAddress("10.0.0.2")])
             devices.set_interface_ips(
                 futils.IPV4,
                 "tunl0",
                 set([IPAddress("10.0.0.2"),
                      IPAddress("10.0.0.3")])
             )
             self.assertEqual(
                 m_check_call.mock_calls,
                 [
                     mock.call(["ip", "addr", "del", "10.0.0.1", "dev",
                                "tunl0"]),
                     mock.call(["ip", "addr", "add", "10.0.0.3", "dev",
                                "tunl0"]),
                 ]
             )