Return usage information for volumes mounted on this minion

    .. versionchanged:: 2019.2.0

        Default for SunOS changed to 1 kilobyte blocks

    CLI Example:

    .. code-block:: bash

        salt '*' disk.usage
436045
def usage(args=None):
    '''
    
    '''
    flags = _clean_flags(args, 'disk.usage')
    if not os.path.isfile('/etc/mtab') and __grains__['kernel'] == 'Linux':
        log.error('df cannot run without /etc/mtab')
        if __grains__.get('virtual_subtype') == 'LXC':
            log.error('df command failed and LXC detected. If you are running '
                     'a Docker container, consider linking /proc/mounts to '
                     '/etc/mtab or consider running Docker with -privileged')
        return {}
    if __grains__['kernel'] == 'Linux':
        cmd = 'df -P'
    elif __grains__['kernel'] == 'OpenBSD' or __grains__['kernel'] == 'AIX':
        cmd = 'df -kP'
    elif __grains__['kernel'] == 'SunOS':
        cmd = 'df -k'
    else:
        cmd = 'df'
    if flags:
        cmd += ' -{0}'.format(flags)
    ret = {}
    out = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
    oldline = None
    for line in out:
        if not line:
            continue
        if line.startswith('Filesystem'):
            continue
        if oldline:
            line = oldline + " " + line
        comps = line.split()
        if len(comps) == 1:
            oldline = line
            continue
        else:
            oldline = None
        while len(comps) >= 2 and not comps[1].isdigit():
            comps[0] = '{0} {1}'.format(comps[0], comps[1])
            comps.pop(1)
        if len(comps) < 2:
            continue
        try:
            if __grains__['kernel'] == 'Darwin':
                ret[comps[8]] = {
                        'filesystem': comps[0],
                        '512-blocks': comps[1],
                        'used': comps[2],
                        'available': comps[3],
                        'capacity': comps[4],
                        'iused': comps[5],
                        'ifree': comps[6],
                        '%iused': comps[7],
                }
            else:
                ret[comps[5]] = {
                        'filesystem': comps[0],
                        '1K-blocks': comps[1],
                        'used': comps[2],
                        'available': comps[3],
                        'capacity': comps[4],
                }
        except IndexError:
            log.error('Problem parsing disk usage information')
            ret = {}
    return ret
460043
def compile_state_usage(self):
        '''
        
        '''
        err = []
        top = self.get_top()
        err += self.verify_tops(top)

        if err:
            return err

        matches = self.top_matches(top)
        state_usage = {}

        for saltenv, states in self.avail.items():
            env_usage = {
                'used': [],
                'unused': [],
                'count_all': 0,
                'count_used': 0,
                'count_unused': 0
            }

            env_matches = matches.get(saltenv)

            for state in states:
                env_usage['count_all'] += 1
                if state in env_matches:
                    env_usage['count_used'] += 1
                    env_usage['used'].append(state)
                else:
                    env_usage['count_unused'] += 1
                    env_usage['unused'].append(state)

            state_usage[saltenv] = env_usage

        return state_usage
43559
def os_volumes(self):
        
        if not self.__os_volumes:
            self.__os_volumes = OsVolumes(self.__connection)
        return self.__os_volumes
1184544
def memory_usage(self, **kwargs):
        

        def memory_usage_builder(df, **kwargs):
            return df.memory_usage(**kwargs)

        func = self._build_mapreduce_func(memory_usage_builder, **kwargs)
        return self._full_axis_reduce(0, func)
503586
def _find_unused_partition() -> RootPartitions:
    
    which = subprocess.check_output(['ot-unused-partition']).strip()
    return {b'2': RootPartitions.TWO,
            b'3': RootPartitions.THREE}[which]
662552
def container_fs_usage_bytes(self, metric, scraper_config):
        
        metric_name = scraper_config['namespace'] + '.filesystem.usage'
        if metric.type not in METRIC_TYPES:
            self.log.error("Metric type %s unsupported for metric %s" % (metric.type, metric.name))
            return
        self._process_usage_metric(metric_name, metric, self.fs_usage_bytes, scraper_config)
664833
def _get_fs(self):
        '''
        
        '''

        data = dict()
        for dev, dev_data in salt.utils.fsutils._blkid().items():
            dev = self._get_disk_size(dev)
            device = dev.pop('device')
            dev['type'] = dev_data['type']
            data[device] = dev

        return data
378007
def get_disk_size(vm_, swap, linode_id):
    
    '''
    disk_size = get_linode(kwargs={'linode_id': linode_id})['TOTALHD']
    return config.get_cloud_config_value(
        'disk_size', vm_, __opts__, default=disk_size - swap
    )
301861
def get_harddisk_sleep():
    '''
    
    '''
    ret = salt.utils.mac_utils.execute_return_result(
        'systemsetup -getharddisksleep')
    return salt.utils.mac_utils.parse_return(ret)
766918
def _get_system_volume(vm_):
    '''
    
    '''

    # Override system volume size if 'disk_size' is defined in cloud profile
    disk_size = get_size(vm_)['disk']
    if 'disk_size' in vm_:
        disk_size = vm_['disk_size']

    # Construct the system volume
    volume = Volume(
        name='{0} Storage'.format(vm_['name']),
        size=disk_size,
        disk_type=get_disk_type(vm_)
    )

    if 'image_password' in vm_:
        image_password = vm_['image_password']
        volume.image_password = image_password

    # Retrieve list of SSH public keys
    ssh_keys = get_public_keys(vm_)
    volume.ssh_keys = ssh_keys

    if 'image_alias' in vm_.keys():
        volume.image_alias = vm_['image_alias']
    else:
        volume.image = get_image(vm_)['id']
        # Set volume availability zone if defined in the cloud profile
        if 'disk_availability_zone' in vm_:
            volume.availability_zone = vm_['disk_availability_zone']

    return volume
202728
def check_disk_usage(filehandle, meta):
    
    # limit it at twenty kilobytes if no default is provided
    MAX_DISK_USAGE = current_app.config.get('MAX_DISK_USAGE', 20 * 1024)
    CURRENT_USAGE = really_bad_du(current_app.config['UPLOAD_PATH'])
    filehandle.seek(0, os.SEEK_END)

    if CURRENT_USAGE + filehandle.tell() > MAX_DISK_USAGE:
        filehandle.close()
        raise UploadError("Upload exceeds allotment.")
    filehandle.seek(0)
    return filehandle
174471
def get_disk_usage(path):
    
    cmd = 'du -sh --block-size=1 {0}'.format(path)
    total = getoutput(cmd).split()[0]
    return int(total)
267911
def _volume_get(self, volume_id):
        '''
        
        '''
        if self.volume_conn is None:
            raise SaltCloudSystemExit('No cinder endpoint available')
        nt_ks = self.volume_conn
        volume = nt_ks.volumes.get(volume_id)
        response = {'name': volume.display_name,
                    'size': volume.size,
                    'id': volume.id,
                    'description': volume.display_description,
                    'attachments': volume.attachments,
                    'status': volume.status
                    }
        return response
314081
def disk_usage(path, human=False):
    """"""
    command = ['du', '-s', path]
    if human:
        command.append('-h')

    return subprocess.check_output(command).split()[0].decode('utf-8')
793216
def avail_sizes(call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The avail_sizes function must be called with '
            '-f or --function, or with the --list-sizes option'
        )

    rcode, items = query(command='my/packages')
    if rcode not in VALID_RESPONSE_CODES:
        return {}
    return key_list(items=items)
649785
def usage() -> None:
    

    print()
    print('Usage: setnym.py <config-ini>')
    print()
    print('where <config-ini> represents the path to the configuration file.')
    print()
    print('The operation submits a nym to a trustee anchor to send to the ledger,')
    print('if the ledger does not have it already as configured.')
    print()
    print('The configuration file has sections and entries as follows:')
    print('  * section [Node Pool]:')
    print('    - name: the name of the node pool to which the operation applies')
    print('    - genesis.txn.path: the path to the genesis transaction file')
    print('        for the node pool (may omit if node pool already exists)')
    print('  * section [Trustee Anchor]:')
    print("    - name: the trustee anchor's (wallet) name")
    print("    - wallet.type: (default blank) the trustee anchor's wallet type")
    print("    - wallet.access: (default blank) the trustee anchor's")
    print('        wallet access credential (password) value')
    print('  * section [VON Anchor]:')
    print('    - role: the role to request in the send-nym transaction; specify:')
    print('        - (default) empty value for user with no additional write privileges')
    print('        - TRUST_ANCHOR for VON anchor with write privileges for indy artifacts')
    print('        - TRUSTEE for VON anchor sending further cryptonyms to the ledger')
    print("    - name: the VON anchor's (wallet) name")
    print("    - seed: the VON anchor's seed (optional, for wallet creation only)")
    print("    - did: the VON anchor's DID (optional, for wallet creation only)")
    print('    - wallet.create: whether create the wallet if it does not yet exist')
    print('        (value True/False, 1/0, or Yes/No)')
    print("    - wallet.type: (default blank) the VON anchor's wallet type")
    print("    - wallet.access: (default blank) the VON anchor's")
    print('        wallet access credential (password) value.')
    print()
479530
def find_usage(self):
        
        logger.debug("Checking usage for service %s", self.service_name)
        self.connect()
        for lim in self.limits.values():
            lim._reset_usage()
        self._find_cluster_manual_snapshots()
        self._find_cluster_subnet_groups()
        self._have_usage = True
        logger.debug("Done checking usage.")