generate: container: Allow one volume to be mounted multiple times
Signed-off-by: Enno Tensing <tenno@suij.in>
This commit is contained in:
parent
8b7221363c
commit
7a794197f4
1 changed files with 17 additions and 7 deletions
|
@ -244,7 +244,7 @@ class Volume:
|
||||||
"""Container Volume."""
|
"""Container Volume."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
path: str
|
path: list
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, val: ConfigValue, logger: Log) -> list:
|
def from_json(cls, val: ConfigValue, logger: Log) -> list:
|
||||||
|
@ -254,7 +254,16 @@ class Volume:
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
logger.log_warning("Volume key is present, but malformed.")
|
logger.log_warning("Volume key is present, but malformed.")
|
||||||
return []
|
return []
|
||||||
return [cls(key, value) for key, value in val.items()]
|
return [
|
||||||
|
Volume.from_json_entry(key, value) for key, value in val.items()
|
||||||
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json_entry(cls, key: str, value: str | list) -> Self:
|
||||||
|
"""Create from JSON entry."""
|
||||||
|
if isinstance(value, str):
|
||||||
|
return cls(key, [value])
|
||||||
|
return cls(key, value)
|
||||||
|
|
||||||
def is_host_volume(self) -> bool:
|
def is_host_volume(self) -> bool:
|
||||||
"""Check if this Volume is a named or a host volume."""
|
"""Check if this Volume is a named or a host volume."""
|
||||||
|
@ -262,7 +271,10 @@ class Volume:
|
||||||
|
|
||||||
def command(self) -> str:
|
def command(self) -> str:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
return f"--volume {self.name}:{self.path}"
|
cmd = ""
|
||||||
|
for path in self.path:
|
||||||
|
cmd += f"\t--volume {self.name}:{path} \\\n"
|
||||||
|
return cmd
|
||||||
|
|
||||||
def create(self) -> str:
|
def create(self) -> str:
|
||||||
"""Create volume, if it does not exist."""
|
"""Create volume, if it does not exist."""
|
||||||
|
@ -324,9 +336,7 @@ class Secret:
|
||||||
options = maybe_or(val[key], "options", "")
|
options = maybe_or(val[key], "options", "")
|
||||||
if options is None:
|
if options is None:
|
||||||
options = ""
|
options = ""
|
||||||
secrets.append(
|
secrets.append(cls(name, str(secret_type), target, str(options)))
|
||||||
cls(name, str(secret_type), target, str(options))
|
|
||||||
)
|
|
||||||
|
|
||||||
return secrets
|
return secrets
|
||||||
|
|
||||||
|
@ -708,7 +718,7 @@ class Container:
|
||||||
for secret in self.secrets:
|
for secret in self.secrets:
|
||||||
cmd += f"{secret.command()}"
|
cmd += f"{secret.command()}"
|
||||||
for volume in self.volumes:
|
for volume in self.volumes:
|
||||||
cmd += f"\t{volume.command()} \\\n"
|
cmd += f"{volume.command()}"
|
||||||
for capability in self.capabilities:
|
for capability in self.capabilities:
|
||||||
cmd += f"\t{capability.command()} \\\n"
|
cmd += f"\t{capability.command()} \\\n"
|
||||||
cmd += f"{self.accounting.command()}"
|
cmd += f"{self.accounting.command()}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue