Merge pull request #4220 from shin-/4211-default_network_labels

Add default labels to networks and volumes created by Compose
This commit is contained in:
Joffrey F 2016-12-20 02:34:57 -08:00 committed by GitHub
commit 09690e1758
7 changed files with 68 additions and 10 deletions

View file

@ -11,7 +11,9 @@ LABEL_CONTAINER_NUMBER = 'com.docker.compose.container-number'
LABEL_ONE_OFF = 'com.docker.compose.oneoff'
LABEL_PROJECT = 'com.docker.compose.project'
LABEL_SERVICE = 'com.docker.compose.service'
LABEL_NETWORK = 'com.docker.compose.network'
LABEL_VERSION = 'com.docker.compose.version'
LABEL_VOLUME = 'com.docker.compose.volume'
LABEL_CONFIG_HASH = 'com.docker.compose.config-hash'
COMPOSEFILE_V1 = '1'

View file

@ -7,8 +7,11 @@ from docker.errors import NotFound
from docker.types import IPAMConfig
from docker.types import IPAMPool
from docker.utils import version_gte
from docker.utils import version_lt
from .config import ConfigurationError
from .const import LABEL_NETWORK
from .const import LABEL_PROJECT
log = logging.getLogger(__name__)
@ -72,8 +75,8 @@ class Network(object):
ipam=self.ipam,
internal=self.internal,
enable_ipv6=self.enable_ipv6,
labels=self.labels,
attachable=version_gte(self.client._version, '1.24') or None
labels=self._labels,
attachable=version_gte(self.client._version, '1.24') or None,
)
def remove(self):
@ -93,6 +96,17 @@ class Network(object):
return self.external_name
return '{0}_{1}'.format(self.project, self.name)
@property
def _labels(self):
if version_lt(self.client._version, '1.23'):
return None
labels = self.labels.copy() if self.labels else {}
labels.update({
LABEL_PROJECT: self.project,
LABEL_NETWORK: self.name,
})
return labels
def create_ipam_config_from_dict(ipam_dict):
if not ipam_dict:

View file

@ -4,8 +4,11 @@ from __future__ import unicode_literals
import logging
from docker.errors import NotFound
from docker.utils import version_lt
from .config import ConfigurationError
from .const import LABEL_PROJECT
from .const import LABEL_VOLUME
log = logging.getLogger(__name__)
@ -23,7 +26,7 @@ class Volume(object):
def create(self):
return self.client.create_volume(
self.full_name, self.driver, self.driver_opts, labels=self.labels
self.full_name, self.driver, self.driver_opts, labels=self._labels
)
def remove(self):
@ -53,6 +56,17 @@ class Volume(object):
return self.external_name
return '{0}_{1}'.format(self.project, self.name)
@property
def _labels(self):
if version_lt(self.client._version, '1.23'):
return None
labels = self.labels.copy() if self.labels else {}
labels.update({
LABEL_PROJECT: self.project,
LABEL_VOLUME: self.name,
})
return labels
class ProjectVolumes(object):