From: Kefu Chai Date: Wed, 27 Jan 2021 01:46:18 +0000 (+0800) Subject: cephadm: add CephadmContext.__contains__() X-Git-Tag: v17.1.0~3110^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b9fb0d9f3de9960ecdb8901cadcf5a735b3bc4d2;p=ceph.git cephadm: add CephadmContext.__contains__() more pythonic this way. Signed-off-by: Kefu Chai --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index c46bee0fbd29..c369de95b645 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -146,7 +146,7 @@ class CephadmContext: return "func" in self._args - def has(self, name: str) -> bool: + def __contains__(self, name: str) -> bool: return hasattr(self, name) @@ -1550,7 +1550,7 @@ def infer_fsid(func): if not is_fsid(daemon['fsid']): # 'unknown' fsid continue - elif ctx.has("name") or not ctx.name: + elif "name" in ctx or not ctx.name: # ctx.name not specified fsids_set.add(daemon['fsid']) elif daemon['name'] == ctx.name: @@ -1635,7 +1635,7 @@ def default_image(func): @wraps(func) def _default_image(ctx: CephadmContext): if not ctx.image: - if ctx.has("name") and ctx.name: + if "name" in ctx and ctx.name: type_ = ctx.name.split('.', 1)[0] if type_ in Monitoring.components: ctx.image = Monitoring.components[type_]['image'] @@ -2121,18 +2121,18 @@ def get_config_and_keyring(ctx): config = None keyring = None - if ctx.has("config_json") and ctx.config_json: + if "config_json" in ctx and ctx.config_json: d = get_parm(ctx.config_json) config = d.get('config') keyring = d.get('keyring') - if ctx.has("config") and ctx.config: + if "config" in ctx and ctx.config: with open(ctx.config, 'r') as f: config = f.read() - if ctx.has("key") and ctx.key: + if "key" in ctx and ctx.key: keyring = '[%s]\n\tkey = %s\n' % (ctx.name, ctx.key) - elif ctx.has("keyring") and ctx.keyring: + elif "keyring" in ctx and ctx.keyring: with open(ctx.keyring, 'r') as f: keyring = f.read() @@ -5025,7 +5025,7 @@ def command_check_host(ctx: CephadmContext) -> None: if not check_time_sync(ctx): errors.append('ERROR: No time synchronization is active') - if ctx.has("expect_hostname") and ctx.expect_hostname: + if "expect_hostname" in ctx and ctx.expect_hostname: if get_hostname().lower() != ctx.expect_hostname.lower(): errors.append('ERROR: hostname "%s" does not match expected hostname "%s"' % ( get_hostname(), ctx.expect_hostname)) @@ -5065,7 +5065,7 @@ def command_prepare_host(ctx: CephadmContext) -> None: # the service check_time_sync(ctx, enabler=pkg) - if ctx.has("expect_hostname") and ctx.expect_hostname and ctx.expect_hostname != get_hostname(): + if "expect_hostname" in ctx and ctx.expect_hostname and ctx.expect_hostname != get_hostname(): logger.warning('Adjusting hostname from %s -> %s...' % (get_hostname(), ctx.expect_hostname)) call_throws(ctx, ['hostname', ctx.expect_hostname]) with open('/etc/hostname', 'w') as f: