mirror of
https://github.com/docker/compose.git
synced 2025-07-21 04:34:38 +02:00
Add number to container
This commit is contained in:
parent
5d9a5a0c84
commit
8ed86ed551
@ -46,6 +46,13 @@ class Container(object):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return self.dictionary['Name'][1:]
|
return self.dictionary['Name'][1:]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def number(self):
|
||||||
|
try:
|
||||||
|
return int(self.name.split('_')[-1])
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def human_readable_ports(self):
|
def human_readable_ports(self):
|
||||||
self.inspect_if_not_inspected()
|
self.inspect_if_not_inspected()
|
||||||
|
@ -35,3 +35,17 @@ class ContainerTest(DockerClientTestCase):
|
|||||||
'FOO': 'BAR',
|
'FOO': 'BAR',
|
||||||
'BAZ': 'DOGE',
|
'BAZ': 'DOGE',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def test_number(self):
|
||||||
|
container = Container.from_ps(self.client, {
|
||||||
|
"Id":"abc",
|
||||||
|
"Image":"ubuntu:12.04",
|
||||||
|
"Command":"sleep 300",
|
||||||
|
"Created":1387384730,
|
||||||
|
"Status":"Up 8 seconds",
|
||||||
|
"Ports":None,
|
||||||
|
"SizeRw":0,
|
||||||
|
"SizeRootFs":0,
|
||||||
|
"Names":["/db_1"]
|
||||||
|
}, has_been_inspected=True)
|
||||||
|
self.assertEqual(container.number, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user