Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _container_config(self, image, command, hostname=None, user=None,
network_disabled=False, entrypoint=None,
cpu_shares=None, working_dir=None,
domainname=None, memswap_limit=0, cpuset=None,
host_config=None):
host_config=None, mac_address=None):
if isinstance(command, six.string_types):
command = shlex.split(str(command))
if isinstance(environment, dict):
Expand Down Expand Up @@ -227,7 +227,8 @@ def _container_config(self, image, command, hostname=None, user=None,
'Cpuset': cpuset,
'WorkingDir': working_dir,
'MemorySwap': memswap_limit,
'HostConfig': host_config
'HostConfig': host_config,
'MacAddress': mac_address
}

def _post_json(self, url, data, **kwargs):
Expand Down Expand Up @@ -539,7 +540,8 @@ def create_container(self, image, command=None, hostname=None, user=None,
volumes=None, volumes_from=None,
network_disabled=False, name=None, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=0, cpuset=None, host_config=None):
memswap_limit=0, cpuset=None, host_config=None,
mac_address=None):

if isinstance(volumes, six.string_types):
volumes = [volumes, ]
Expand All @@ -551,7 +553,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
ports, environment, dns, volumes, volumes_from, network_disabled,
entrypoint, cpu_shares, working_dir, domainname,
memswap_limit, cpuset, host_config
memswap_limit, cpuset, host_config, mac_address
)
return self.create_container_from_config(config, name)

Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ from. Optionally a single string joining container id's with commas
* domainname (str or list): Set custom DNS search domains
* memswap_limit (int):
* host_config (dict): A [HostConfig](hostconfig.md) dictionary
* mac_address (str): The Mac Address to assign the container

**Returns** (dict): A dictionary with an image 'Id' key and a 'Warnings' key.

Expand Down
4 changes: 3 additions & 1 deletion tests/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def get_fake_inspect_container():
"StartedAt": "2013-09-25T14:01:18.869545111+02:00",
"Ghost": False
},
"MacAddress": "02:42:ac:11:00:0a"
}
return status_code, response

Expand Down Expand Up @@ -188,7 +189,8 @@ def get_fake_port():
'Ports': {
'1111': None,
'1111/tcp': [{'HostIp': '127.0.0.1', 'HostPort': '4567'}],
'2222': None}
'2222': None},
'MacAddress': '02:42:ac:11:00:0a'
}
}
return status_code, response
Expand Down
16 changes: 16 additions & 0 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,22 @@ def runTest(self):
self.client.kill(id)


class TestMacAddress(BaseTestCase):
def runTest(self):
mac_address_expected = "02:42:ac:11:00:0a"
container = self.client.create_container(
'busybox', ['sleep', '60'], mac_address=mac_address_expected)

id = container['Id']

self.client.start(container)
res = self.client.inspect_container(container['Id'])
self.assertEqual(mac_address_expected,
res['NetworkSettings']['MacAddress'])

self.client.kill(id)


class TestRestart(BaseTestCase):
def runTest(self):
container = self.client.create_container('busybox', ['sleep', '9999'])
Expand Down
12 changes: 12 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,18 @@ def test_create_container_with_port_binds(self):
docker.client.DEFAULT_TIMEOUT_SECONDS
)

def test_create_container_with_mac_address(self):
try:
mac_address_expected = "02:42:ac:11:00:0a"
container = self.client.create_container(
'busybox', ['sleep', '60'], mac_address=mac_address_expected)
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))

res = self.client.inspect_container(container['Id'])
self.assertEqual(mac_address_expected,
res['NetworkSettings']['MacAddress'])

def test_create_container_with_links(self):
try:
link_path = 'path'
Expand Down