return self._version
def get_version(self, ctx: CephadmContext) -> None:
- out, _, _ = call_throws(ctx, [self.path, 'version', '--format', '{{.Client.Version}}'])
+ out, _, _ = call_throws(ctx, [self.path, 'version', '--format', '{{.Client.Version}}'], verbosity=CallVerbosity.QUIET)
self._version = _parse_podman_version(out)
def __str__(self) -> str:
_, err, code = call(ctx, [
ctx.container_engine.path, 'exec', container_id, cmd,
'--version'
- ], verbosity=CallVerbosity.DEBUG)
+ ], verbosity=CallVerbosity.QUIET)
if code == 0:
break
cmd = 'alertmanager' # reset cmd for version extraction
else:
_, err, code = call(ctx, [
ctx.container_engine.path, 'exec', container_id, cmd, '--version'
- ], verbosity=CallVerbosity.DEBUG)
+ ], verbosity=CallVerbosity.QUIET)
if code == 0 and \
err.startswith('%s, version ' % cmd):
version = err.split(' ')[2]
out, err, code = call(ctx,
[ctx.container_engine.path, 'exec', container_id,
NFSGanesha.entrypoint, '-v'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if code == 0:
match = re.search(r'NFS-Ganesha Release\s*=\s*[V]*([\d.]+)', out)
if match:
out, err, code = call(ctx,
[ctx.container_engine.path, 'exec', container_id,
'/usr/bin/python3', '-c', "import pkg_resources; print(pkg_resources.require('ceph_iscsi')[0].version)"],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if code == 0:
version = out.strip()
return version
try:
while True:
if not self.is_locked:
- logger.debug('Acquiring lock %s on %s', lock_id,
- lock_filename)
+ logger.log(QUIET_LOG_LEVEL, 'Acquiring lock %s on %s', lock_id,
+ lock_filename)
self._acquire()
if self.is_locked:
- logger.debug('Lock %s acquired on %s', lock_id,
- lock_filename)
+ logger.log(QUIET_LOG_LEVEL, 'Lock %s acquired on %s', lock_id,
+ lock_filename)
break
elif timeout >= 0 and time.time() - start_time > timeout:
logger.warning('Timeout acquiring lock %s on %s', lock_id,
lock_filename)
raise Timeout(self._lock_file)
else:
- logger.debug(
+ logger.log(
+ QUIET_LOG_LEVEL,
'Lock %s not acquired on %s, waiting %s seconds ...',
lock_id, lock_filename, poll_intervall
)
installed = False
try:
out, err, code = call(ctx, ['systemctl', 'is-enabled', unit_name],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if code == 0:
enabled = True
installed = True
state = 'unknown'
try:
out, err, code = call(ctx, ['systemctl', 'is-active', unit_name],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
out = out.strip()
if out in ['active']:
state = 'running'
image=img,
entrypoint='stat',
args=['-c', '%u %g', fp]
- ).run()
+ ).run(verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
uid, gid = out.split(' ')
return int(uid), int(gid)
except RuntimeError as e:
]
return ret
- def run(self, timeout=DEFAULT_TIMEOUT):
- # type: (Optional[int]) -> str
+ def run(self, timeout=DEFAULT_TIMEOUT, verbosity=CallVerbosity.VERBOSE_ON_FAILURE):
+ # type: (Optional[int], CallVerbosity) -> str
out, _, _ = call_throws(self.ctx, self.run_cmd(),
- desc=self.entrypoint, timeout=timeout)
+ desc=self.entrypoint, timeout=timeout, verbosity=verbosity)
return out
cmd_str = ' '.join(cmd)
for sleep_secs in [1, 4, 25]:
- out, err, ret = call(ctx, cmd)
+ out, err, ret = call(ctx, cmd, verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
if not ret:
return
timeout = ctx.timeout if ctx.timeout else 60 # seconds
out, err, ret = call(ctx, c.run_cmd(),
desc=c.entrypoint,
- timeout=timeout)
+ timeout=timeout,
+ verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
return ret == 0
is_available(ctx, 'mon', is_mon_available)
# type: () -> bool
timeout = ctx.timeout if ctx.timeout else 60 # seconds
try:
- out = clifunc(['status', '-f', 'json-pretty'], timeout=timeout)
+ out = clifunc(['status', '-f', 'json-pretty'],
+ timeout=timeout,
+ verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
j = json.loads(out)
return j.get('mgrmap', {}).get('available', False)
except Exception as e:
tmp_config = write_tmp(config, uid, gid)
# a CLI helper to reduce our typing
- def cli(cmd, extra_mounts={}, timeout=DEFAULT_TIMEOUT):
- # type: (List[str], Dict[str, str], Optional[int]) -> str
+ def cli(cmd, extra_mounts={}, timeout=DEFAULT_TIMEOUT, verbosity=CallVerbosity.VERBOSE_ON_FAILURE):
+ # type: (List[str], Dict[str, str], Optional[int], CallVerbosity) -> str
mounts = {
log_dir: '/var/log/ceph:z',
admin_keyring.name: '/etc/ceph/ceph.client.admin.keyring:z',
entrypoint='/usr/bin/ceph',
args=cmd,
volume_mounts=mounts,
- ).run(timeout=timeout)
+ ).run(timeout=timeout, verbosity=verbosity)
wait_for_mon(ctx, mon_id, mon_dir, admin_keyring.name, tmp_config.name)
# stat' command first, then fall back to 'mgr dump' if
# necessary
try:
- j = json_loads_retry(lambda: cli(['mgr', 'stat']))
+ j = json_loads_retry(lambda: cli(['mgr', 'stat'], verbosity=CallVerbosity.QUIET_UNLESS_ERROR))
except Exception:
- j = json_loads_retry(lambda: cli(['mgr', 'dump']))
+ j = json_loads_retry(lambda: cli(['mgr', 'dump'], verbosity=CallVerbosity.QUIET_UNLESS_ERROR))
epoch = j['epoch']
# wait for mgr to have it
volume_mounts=mounts,
)
- out, err, code = call_throws(ctx, c.run_cmd())
+ out, err, code = call_throws(ctx, c.run_cmd(), verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
if not code:
print(out)
execstr: Optional[str] = find_executable('ip')
if not execstr:
raise FileNotFoundError("unable to find 'ip' command")
- out, _, _ = call_throws(ctx, [execstr, 'route', 'ls'])
+ out, _, _ = call_throws(ctx, [execstr, 'route', 'ls'], verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
return _parse_ipv4_route(out)
execstr: Optional[str] = find_executable('ip')
if not execstr:
raise FileNotFoundError("unable to find 'ip' command")
- routes, _, _ = call_throws(ctx, [execstr, '-6', 'route', 'ls'])
- ips, _, _ = call_throws(ctx, [execstr, '-6', 'addr', 'ls'])
+ routes, _, _ = call_throws(ctx, [execstr, '-6', 'route', 'ls'], verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
+ ips, _, _ = call_throws(ctx, [execstr, '-6', 'addr', 'ls'], verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
return _parse_ipv6_route(routes, ips)
out, err, code = call(
ctx,
[container_path, 'stats', '--format', '{{.ID}},{{.MemUsage}}', '--no-stream'],
- verbosity=CallVerbosity.DEBUG
+ verbosity=CallVerbosity.QUIET
)
seen_memusage_cid_len, seen_memusage = _parse_mem_usage(code, out)
out, err, code = call(
ctx,
[container_path, 'stats', '--format', '{{.ID}},{{.CPUPerc}}', '--no-stream'],
- verbosity=CallVerbosity.DEBUG
+ verbosity=CallVerbosity.QUIET
)
seen_cpuperc_cid_len, seen_cpuperc = _parse_cpu_perc(code, out)
try:
out, err, code = call(ctx,
['ceph', '-v'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if not code and out.startswith('ceph version '):
host_version = out.split(' ')[2]
except Exception:
container_path, 'image', 'inspect', image_id,
'--format', '{{.RepoDigests}}',
],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if not code:
image_digests = list(set(map(
normalize_image_digest,
out, err, code = call(ctx,
[container_path, 'exec', container_id,
'ceph', '-v'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if not code and \
out.startswith('ceph version '):
version = out.split(' ')[2]
out, err, code = call(ctx,
[container_path, 'exec', container_id,
'grafana-server', '-v'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if not code and \
out.startswith('Version '):
version = out.split(' ')[1]
out, err, code = call(ctx,
[container_path, 'exec', container_id,
'haproxy', '-v'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if not code and \
out.startswith('HA-Proxy version '):
version = out.split(' ')[2]
out, err, code = call(ctx,
[container_path, 'exec', container_id,
'keepalived', '--version'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
if not code and \
err.startswith('Keepalived '):
version = err.split(' ')[1]
'--format', '{{.Id}},{{.Config.Image}},{{.Image}},{{.Created}},{{index .Config.Labels "io.ceph.version"}}',
name
]
- out, err, code = call(ctx, cmd, verbosity=CallVerbosity.DEBUG)
+ out, err, code = call(ctx, cmd, verbosity=CallVerbosity.QUIET)
if not code:
break
return out, err, code
security = {}
try:
out, err, code = call(self.ctx, ['sestatus'],
- verbosity=CallVerbosity.DEBUG)
+ verbosity=CallVerbosity.QUIET)
security['type'] = 'SELinux'
status, mode, policy = '', '', ''
for line in out.split('\n'):