Kaydet (Commit) ab2f7a5e authored tarafından Ben Firshman's avatar Ben Firshman

Add cpu_shares option to create_container

üst 8e8b355a
......@@ -56,7 +56,7 @@ c.create_container(image, command=None, hostname=None, user=None,
detach=False, stdin_open=False, tty=False, mem_limit=0,
ports=None, environment=None, dns=None, volumes=None,
volumes_from=None, network_disabled=False, name=None,
entrypoint=None)
entrypoint=None, cpu_shares=None)
```
Creates a container that can then be `start`ed. Parameters are similar
......
......@@ -122,7 +122,8 @@ class Client(requests.Session):
detach=False, stdin_open=False, tty=False,
mem_limit=0, ports=None, environment=None, dns=None,
volumes=None, volumes_from=None,
network_disabled=False, entrypoint=None):
network_disabled=False, entrypoint=None,
cpu_shares=None):
if isinstance(command, six.string_types):
command = shlex.split(str(command))
if isinstance(environment, dict):
......@@ -176,7 +177,8 @@ class Client(requests.Session):
'Volumes': volumes,
'VolumesFrom': volumes_from,
'NetworkDisabled': network_disabled,
'Entrypoint': entrypoint
'Entrypoint': entrypoint,
'CpuShares': cpu_shares
}
def _post_json(self, url, data, **kwargs):
......@@ -407,12 +409,13 @@ class Client(requests.Session):
detach=False, stdin_open=False, tty=False,
mem_limit=0, ports=None, environment=None, dns=None,
volumes=None, volumes_from=None,
network_disabled=False, name=None, entrypoint=None):
network_disabled=False, name=None, entrypoint=None,
cpu_shares=None):
config = self._container_config(
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
ports, environment, dns, volumes, volumes_from, network_disabled,
entrypoint
entrypoint, cpu_shares
)
return self.create_container_from_config(config, name)
......
......@@ -251,6 +251,28 @@ class DockerClientTest(unittest.TestCase):
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})
def test_create_container_with_cpu_shares(self):
try:
self.client.create_container('busybox', 'ls',
cpu_shares=5)
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
args = fake_request.call_args
self.assertEqual(args[0][0],
'unix://var/run/docker.sock/v1.6/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,
"NetworkDisabled": false,
"CpuShares": 5}'''))
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})
def test_create_named_container(self):
try:
self.client.create_container('busybox', 'true',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment