def _bsd_memdata(osdata):
    '''
    Return the memory information for BSD-like systems
    '''
    grains = {'mem_total': 0, 'swap_total': 0}

    sysctl = salt.utils.path.which('sysctl')
    if sysctl:
        mem = __salt__['cmd.run']('{0} -n hw.physmem'.format(sysctl))
        if osdata['kernel'] == 'NetBSD' and mem.startswith('-'):
            mem = __salt__['cmd.run']('{0} -n hw.physmem64'.format(sysctl))
        grains['mem_total'] = int(mem) // 1024 // 1024

        if osdata['kernel'] in ['OpenBSD', 'NetBSD']:
            swapctl = salt.utils.path.which('swapctl')
            swap_data = __salt__['cmd.run']('{0} -sk'.format(swapctl))
            if swap_data == 'no swap devices configured':
                swap_total = 0
            else:
                swap_total = swap_data.split(' ')[1]
        else:
            swap_total = __salt__['cmd.run']('{0} -n vm.swap_total'.format(sysctl))
        grains['swap_total'] = int(swap_total) // 1024 // 1024
    return grains
def _bsd_memdata ( osdata ) : grains = { 'mem_total' : 0 , 'swap_total' : 0 } sysctl = salt . utils . path . which ( 'sysctl' ) if sysctl : mem = __salt__ [ 'cmd.run' ] ( '{0} -n hw.physmem' . format ( sysctl ) ) if osdata [ 'kernel' ] == 'NetBSD' and mem . startswith ( '-' ) : mem = __salt__ [ 'cmd.run' ] ( '{0} -n hw.physmem64' . format ( sysctl ) ) grains [ 'mem_total' ] = int ( mem ) // 1024 // 1024 if osdata [ 'kernel' ] in [ 'OpenBSD' , 'NetBSD' ] : swapctl = salt . utils . path . which ( 'swapctl' ) swap_data = __salt__ [ 'cmd.run' ] ( '{0} -sk' . format ( swapctl ) ) if swap_data == 'no swap devices configured' : swap_total = 0 else : swap_total = swap_data . split ( ' ' ) [ 1 ] else : swap_total = __salt__ [ 'cmd.run' ] ( '{0} -n vm.swap_total' . format ( sysctl ) ) grains [ 'swap_total' ] = int ( swap_total ) // 1024 // 1024 return grains
Return the memory information for BSD-like systems