def info(name, **kwargs):
    '''
    Return info about a container

    .. note::

        The container must be running for ``machinectl`` to gather information
        about it. If the container is stopped, then this function will start
        it.

    start : False
        If ``True``, then the container will be started to retrieve the info. A
        ``Started`` key will be in the return data if the container was
        started.

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.info arch1
        salt myminion nspawn.info arch1 force_start=False
    '''
    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    start_ = kwargs.pop('start', False)
    if kwargs:
        salt.utils.args.invalid_kwargs(kwargs)

    if not start_:
        _ensure_running(name)
    elif name not in list_running():
        start(name)

    # Have to parse 'machinectl status' here since 'machinectl show' doesn't
    # contain IP address info or OS info. *shakes fist angrily*
    c_info = _machinectl('status {0}'.format(name))
    if c_info['retcode'] != 0:
        raise CommandExecutionError(
            'Unable to get info for container \'{0}\''.format(name)
        )
    # Better human-readable names. False means key should be ignored.
    key_name_map = {
        'Iface': 'Network Interface',
        'Leader': 'PID',
        'Service': False,
        'Since': 'Running Since',
    }
    ret = {}
    kv_pair = re.compile(r'^\s+([A-Za-z]+): (.+)$')
    tree = re.compile(r'[|`]')
    lines = c_info['stdout'].splitlines()
    multiline = False
    cur_key = None
    for idx in range(len(lines)):
        match = kv_pair.match(lines[idx])
        if match:
            key, val = match.groups()
            # Get a better key name if one exists
            key = key_name_map.get(key, key)
            if key is False:
                continue
            elif key == 'PID':
                try:
                    val = val.split()[0]
                except IndexError:
                    pass
            cur_key = key
            if multiline:
                multiline = False
            ret[key] = val
        else:
            if cur_key is None:
                continue
            if tree.search(lines[idx]):
                # We've reached the process tree, bail out
                break
            if multiline:
                ret[cur_key].append(lines[idx].strip())
            else:
                ret[cur_key] = [ret[key], lines[idx].strip()]
                multiline = True
    return ret
def info ( name , ** kwargs ) : kwargs = salt . utils . args . clean_kwargs ( ** kwargs ) start_ = kwargs . pop ( 'start' , False ) if kwargs : salt . utils . args . invalid_kwargs ( kwargs ) if not start_ : _ensure_running ( name ) elif name not in list_running ( ) : start ( name ) c_info = _machinectl ( 'status {0}' . format ( name ) ) if c_info [ 'retcode' ] != 0 : raise CommandExecutionError ( 'Unable to get info for container \'{0}\'' . format ( name ) ) key_name_map = { 'Iface' : 'Network Interface' , 'Leader' : 'PID' , 'Service' : False , 'Since' : 'Running Since' , } ret = { } kv_pair = re . compile ( r'^\s+([A-Za-z]+): (.+)$' ) tree = re . compile ( r'[|`]' ) lines = c_info [ 'stdout' ] . splitlines ( ) multiline = False cur_key = None for idx in range ( len ( lines ) ) : match = kv_pair . match ( lines [ idx ] ) if match : key , val = match . groups ( ) key = key_name_map . get ( key , key ) if key is False : continue elif key == 'PID' : try : val = val . split ( ) [ 0 ] except IndexError : pass cur_key = key if multiline : multiline = False ret [ key ] = val else : if cur_key is None : continue if tree . search ( lines [ idx ] ) : break if multiline : ret [ cur_key ] . append ( lines [ idx ] . strip ( ) ) else : ret [ cur_key ] = [ ret [ key ] , lines [ idx ] . strip ( ) ] multiline = True return ret
Return info about a container

    .. note::

        The container must be running for ``machinectl`` to gather information
        about it. If the container is stopped, then this function will start
        it.

    start : False
        If ``True``, then the container will be started to retrieve the info. A
        ``Started`` key will be in the return data if the container was
        started.

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.info arch1
        salt myminion nspawn.info arch1 force_start=False