Ejemplo n.º 1
0
    def start(cls, container_id, veths, gateway):
        """start eths and continer"""
        try:
            cls.docker_cli.start(container=container_id,
                                 #extra_hosts={'ldap.xxx.com.cn':'172.16.11.3'},
                                 privileged=True)
        except dockerpy.errors.APIError as e:
            logger.error(traceback.format_exc())
            raise ContainerActionError(str(e))

        for index, (veth, link_to, ip_netmask) in enumerate(veths):
            macvlan_eth = MacvlanEth(veth, ip_netmask, link_to).create()
            container_pid = cls.docker_cli.inspect_container(container_id)['State']['Pid']

            if index == 0:
                macvlan_eth.attach_to_container(container_pid,
                                                is_route=True, gateway=gateway)
            else:
                macvlan_eth.attach_to_container(container_pid)
Ejemplo n.º 2
0
class TestMacvlan(unittest.TestCase):
    def setUp(self):
        self._veth_name = "testMacvlan"
        self._ip_mask = "192.168.16.10/24"
        self._macvlan = MacvlanEth(self._veth_name, self._ip_mask, "eth0")

    def test_create_delete_macvlan(self):
        self._macvlan.create()
        self.assertTrue(self._veth_name in ifconfig("-a"))

        self._macvlan.delete()
        self.assertFalse(self._veth_name in ifconfig("-a"))

    def tearDown(self):
        if "testMacvlan" in ifconfig("-a"):
            self._macvlan.delete()
Ejemplo n.º 3
0
class TestMacvlan(unittest.TestCase):
    def setUp(self):
        self._veth_name = 'testMacvlan'
        self._ip_mask = '192.168.16.10/24'
        self._macvlan = MacvlanEth(self._veth_name, self._ip_mask, 'eth0')

    def test_create_delete_macvlan(self):
        self._macvlan.create()
        self.assertTrue(self._veth_name in ifconfig('-a'))

        self._macvlan.delete()
        self.assertFalse(self._veth_name in ifconfig('-a'))

    def tearDown(self):
        if 'testMacvlan' in ifconfig('-a'):
            self._macvlan.delete()
Ejemplo n.º 4
0
    def start(cls, container_id, veths, gateway):
        """start eths and continer"""
        try:
            cls.docker_cli.start(
                container=container_id,
                #extra_hosts={'ldap.xxx.com.cn':'172.16.11.3'},
                privileged=True)
        except dockerpy.errors.APIError as e:
            logger.error(traceback.format_exc())
            raise ContainerActionError(str(e))

        for index, (veth, link_to, ip_netmask) in enumerate(veths):
            macvlan_eth = MacvlanEth(veth, ip_netmask, link_to).create()
            if index == 0:
                macvlan_eth.attach_to_container(container_id,
                                                is_route=True,
                                                gateway=gateway)
            else:
                macvlan_eth.attach_to_container(container_id)
Ejemplo n.º 5
0
 def setUp(self):
     self._veth_name = 'testMacvlan'
     self._ip_mask = '192.168.16.10/24'
     self._macvlan = MacvlanEth(self._veth_name, self._ip_mask, TEST_MOTHER_ETH_NAME)
Ejemplo n.º 6
0
 def setUp(self):
     self._veth_name = "testMacvlan"
     self._ip_mask = "192.168.16.10/24"
     self._macvlan = MacvlanEth(self._veth_name, self._ip_mask, "eth0")
Ejemplo n.º 7
0
 def setUp(self):
     self._veth_name = 'testMacvlan'
     self._ip_mask = '192.168.16.10/24'
     self._macvlan = MacvlanEth(self._veth_name, self._ip_mask, 'eth0')