import copy
import os
-from typing import Dict, List, Optional, Any, Union, Tuple
+from typing import Dict, List, Optional, Any, Union, Tuple, cast
from .call_wrappers import call, call_throws, CallVerbosity
from .constants import DEFAULT_TIMEOUT
assert self.identity
return self.identity.container_name
- def build_run_cmd(self) -> List[str]:
- cmd_args: List[str] = [self._container_engine]
- cmd_args.append('run')
+ def build_engine_run_args(self) -> List[str]:
+ cmd_args: List[str] = []
if self.remove:
cmd_args.append('--rm')
if self.ipc:
+ envs
+ vols
+ binds
+ )
+
+ def build_run_cmd(self) -> List[str]:
+ return (
+ [self._container_engine, 'run']
+ + self.build_engine_run_args()
+ [self.image]
- + self.args
+ + list(self.args)
)
def build_rm_cmd(
return self.build_rm_cmd(storage=storage)
+class SidecarContainer(BasicContainer):
+ @classmethod
+ def from_primary_and_values(
+ cls,
+ ctx: CephadmContext,
+ primary: BasicContainer,
+ sidecar_name: str,
+ *,
+ image: str = '',
+ entrypoint: str = '',
+ args: Optional[List[str]] = None,
+ init: Optional[bool] = None,
+ ) -> 'SidecarContainer':
+ assert primary.identity
+ identity = DaemonSubIdentity.from_parent(
+ primary.identity, sidecar_name
+ )
+ ctr = cast(
+ SidecarContainer, cls.from_container(primary, ident=identity)
+ )
+ ctr.remove = True
+ if image:
+ ctr.image = image
+ if entrypoint:
+ ctr.entrypoint = entrypoint
+ if args:
+ ctr.args = args
+ if init is not None:
+ ctr.init = init
+ return ctr
+
+ def build_engine_run_args(self) -> List[str]:
+ assert isinstance(self.identity, DaemonSubIdentity)
+ cmd_args = super().build_engine_run_args()
+ if self._using_podman:
+ # sidecar containers are always services, otherwise they
+ # would not be sidecars
+ cmd_args += self.ctx.container_engine.service_args(
+ self.ctx, self.identity.sidecar_service_name
+ )
+ return cmd_args
+
+ def run_cmd(self) -> List[str]:
+ if not (self.envs and self.envs[0].startswith('NODE_NAME=')):
+ self.envs.insert(0, 'NODE_NAME=%s' % get_hostname())
+ return self.build_run_cmd()
+
+ def rm_cmd(self, storage: bool = False) -> List[str]:
+ return self.build_rm_cmd(storage=storage)
+
+ def stop_cmd(self, timeout: Optional[int] = None) -> List[str]:
+ return self.build_stop_cmd(timeout=timeout)
+
+
def is_container_running(ctx: CephadmContext, c: 'CephContainer') -> bool:
if ctx.name.split('.', 1)[0] in ['agent', 'cephadm-exporter']:
# these are non-containerized daemon types