Added support for 'cpuset'

This commit is contained in:
davy 2014-08-27 13:38:27 +02:00
parent c76fd8d914
commit 4388157fef
2 changed files with 31 additions and 5 deletions

View File

@ -102,8 +102,8 @@ class Client(requests.Session):
mem_limit=0, ports=None, environment=None, dns=None, mem_limit=0, ports=None, environment=None, dns=None,
volumes=None, volumes_from=None, volumes=None, volumes_from=None,
network_disabled=False, entrypoint=None, network_disabled=False, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None, cpu_shares=None, cpuset=None, working_dir=None,
memswap_limit=0): domainname=None, memswap_limit=0):
if isinstance(command, six.string_types): if isinstance(command, six.string_types):
command = shlex.split(str(command)) command = shlex.split(str(command))
if isinstance(environment, dict): if isinstance(environment, dict):
@ -216,6 +216,7 @@ class Client(requests.Session):
'NetworkDisabled': network_disabled, 'NetworkDisabled': network_disabled,
'Entrypoint': entrypoint, 'Entrypoint': entrypoint,
'CpuShares': cpu_shares, 'CpuShares': cpu_shares,
'Cpuset': cpuset,
'WorkingDir': working_dir, 'WorkingDir': working_dir,
'MemorySwap': memswap_limit 'MemorySwap': memswap_limit
} }
@ -500,8 +501,8 @@ class Client(requests.Session):
mem_limit=0, ports=None, environment=None, dns=None, mem_limit=0, ports=None, environment=None, dns=None,
volumes=None, volumes_from=None, volumes=None, volumes_from=None,
network_disabled=False, name=None, entrypoint=None, network_disabled=False, name=None, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None, cpu_shares=None, cpuset=None, working_dir=None,
memswap_limit=0): domainname=None, memswap_limit=0):
if isinstance(volumes, six.string_types): if isinstance(volumes, six.string_types):
volumes = [volumes, ] volumes = [volumes, ]
@ -509,7 +510,8 @@ class Client(requests.Session):
config = self._container_config( config = self._container_config(
image, command, hostname, user, detach, stdin_open, tty, mem_limit, image, command, hostname, user, detach, stdin_open, tty, mem_limit,
ports, environment, dns, volumes, volumes_from, network_disabled, ports, environment, dns, volumes, volumes_from, network_disabled,
entrypoint, cpu_shares, working_dir, domainname, memswap_limit entrypoint, cpu_shares, cpuset, working_dir, domainname,
memswap_limit
) )
return self.create_container_from_config(config, name) return self.create_container_from_config(config, name)

View File

@ -348,6 +348,30 @@ class DockerClientTest(Cleanup, unittest.TestCase):
self.assertEqual(args[1]['headers'], self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'}) {'Content-Type': 'application/json'})
def test_create_container_with_cpuset(self):
try:
self.client.create_container('busybox', 'ls',
cpuset='0,1')
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
args = fake_request.call_args
self.assertEqual(args[0][0],
url_prefix + 'containers/create')
self.assertEqual(json.loads(args[1]['data']),
json.loads('''
{"Tty": false, "Image": "busybox",
"Cmd": ["ls"], "AttachStdin": false,
"Memory": 0,
"AttachStderr": true,
"AttachStdout": true, "OpenStdin": false,
"StdinOnce": false,
"NetworkDisabled": false,
"Cpuset": "0,1",
"MemorySwap": 0}'''))
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})
def test_create_container_with_working_dir(self): def test_create_container_with_working_dir(self):
try: try:
self.client.create_container('busybox', 'ls', self.client.create_container('busybox', 'ls',