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)
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()
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()
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)
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)
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 setUp(self): self._veth_name = 'testMacvlan' self._ip_mask = '192.168.16.10/24' self._macvlan = MacvlanEth(self._veth_name, self._ip_mask, 'eth0')