Filter mounts based on include/exclude patterns

This commit is contained in:
Einar Forselv 2019-04-14 21:22:11 +02:00
parent 6d896757b7
commit f76c91e549
1 changed files with 19 additions and 5 deletions

View File

@ -39,13 +39,31 @@ class Container:
def is_oneoff(self): def is_oneoff(self):
return self.labels['com.docker.compose.oneoff'] == 'True' return self.labels['com.docker.compose.oneoff'] == 'True'
def filter_mounts(self):
"""Get all mounts for this container matching filters"""
for mount in self.mounts:
if self.include:
for pattern in self.include:
if pattern in mount.source:
yield mount
continue
elif self.exlude:
for pattern in self.exlude:
if pattern in mount.source:
continue
yield mount
else:
yield mount
def to_dict(self): def to_dict(self):
return { return {
'Id': self.id, 'Id': self.id,
'Names': self.names, 'Names': self.names,
'State': self.state, 'State': self.state,
'Labels': self.labels, 'Labels': self.labels,
'Mounts': [mnt.data for mnt in self.mounts] 'Mounts': [mnt.data for mnt in self.mounts],
'include': self.include,
'exclude': self.exlude,
} }
@ -137,10 +155,6 @@ class RunningContainers:
self.containers.append(container) self.containers.append(container)
def backup_volumes(self):
return self.backup_container.mounts
def gen_volumes(self, volume_type): def gen_volumes(self, volume_type):
"""Generator yielding volumes of a specific type""" """Generator yielding volumes of a specific type"""
for cont in self.containers: for cont in self.containers: