return workunit.task(ctx, _config)
+def _node_info(ctx, role_name, **kwargs):
+ (remote,) = ctx.cluster.only(role_name).remotes.keys()
+ info = dict(remote.inventory_info)
+ info['_role_name'] = role_name
+ info['shortname'] = remote.shortname
+ info['ip_address'] = remote.ip_address
+ info.update(kwargs)
+ return info
+
+
@contextlib.contextmanager
def write_metadata_file(ctx, config, *, roles=None):
obj = {
}
if config.get('admin_node'):
role = config.get('admin_node')
- (remote,) = ctx.cluster.only(role).remotes.keys()
- n = obj['admin_node'] = remote.inventory_info
- n['shortname'] = remote.shortname
- n['ip_address'] = remote.ip_address
+ obj['admin_node'] = _node_info(ctx, role)
if config.get('smb_nodes'):
- snodes = obj['smb_nodes'] = []
- for node in config.get('smb_nodes'):
- (remote,) = ctx.cluster.only(node).remotes.keys()
- n = dict(remote.inventory_info)
- n['shortname'] = remote.shortname
- n['ip_address'] = remote.ip_address
- snodes.append(n)
+ obj['smb_nodes'] = [
+ _node_info(ctx, node) for node in config.get('smb_nodes')
+ ]
+ if config.get('clients'):
+ obj['client_nodes'] = [
+ _node_info(ctx, node, client_name=node)
+ for node in config.get('clients')
+ ]
data = json.dumps(obj)
log.debug('smb metadata: %r', obj)