cephadm: shell: allow -e

Set environment variables for shell commands.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2020-02-10 15:44:08 -06:00
parent 366d3fc33e
commit 3346765dd0
2 changed files with 16 additions and 1 deletions

View File

@ -109,6 +109,7 @@ systemctl status docker && ( $CEPHADM --docker version | grep 'ceph version' )
## test shell before bootstrap, when crash dir isn't (yet) present on this host
$CEPHADM shell --fsid $FSID -- ceph -v | grep 'ceph version'
$CEPHADM shell --fsid $FSID -e FOO=BAR -- printenv | grep FOO=BAR
## bootstrap
ORIG_CONFIG=`mktemp -p $TMPDIR`

View File

@ -1488,8 +1488,9 @@ class CephContainer:
volume_mounts={},
cname='',
container_args=[],
envs=None,
privileged=False):
# type: (str, str, List[str], Dict[str, str], str, List[str], Optional[bool]) -> None
# type: (str, str, List[str], Dict[str, str], str, List[str], Optional[List[str]], Optional[bool]) -> None
self.image = image
self.entrypoint = entrypoint
self.args = args
@ -1497,6 +1498,7 @@ class CephContainer:
self.cname = cname
self.container_args = container_args
self.privileged = privileged
self.envs = envs
def run_cmd(self):
# type: () -> List[str]
@ -1519,6 +1521,9 @@ class CephContainer:
'-e', 'CONTAINER_IMAGE=%s' % self.image,
'-e', 'NODE_NAME=%s' % get_hostname(),
]
if self.envs:
for e in self.envs:
envs.extend(['-e', e])
cname = ['--name', self.cname] if self.cname else []
return [
str(container_path),
@ -1547,6 +1552,9 @@ class CephContainer:
'-e', 'CONTAINER_IMAGE=%s' % self.image,
'-e', 'NODE_NAME=%s' % get_hostname(),
]
if self.envs:
for e in self.envs:
envs.extend(['-e', e])
cmd_args = [] # type: List[str]
if cmd:
cmd_args = ['-c'] + cmd
@ -2085,6 +2093,7 @@ def command_shell():
args=[],
container_args=container_args,
volume_mounts=mounts,
envs=args.env,
privileged=True)
command = c.shell_cmd(command)
@ -2996,6 +3005,11 @@ def _get_parser():
parser_shell.add_argument(
'--keyring', '-k',
help='ceph.keyring to pass through to the container')
parser_shell.add_argument(
'--env', '-e',
action='append',
default=[],
help='set environment variable')
parser_shell.add_argument(
'command', nargs='*',
help='command (optional)')