<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import datetime <EOL> import os <EOL> import re <EOL> import fnmatch <EOL> import collections <EOL> import copy <EOL> import time <EOL> import salt . ext . six as six <EOL> from salt . ext . six . moves import range <EOL> import salt . config <EOL> import salt . minion <EOL> import salt . utils <EOL> import salt . utils . event <EOL> from salt . utils . network import host_to_ip as _host_to_ip <EOL> from salt . utils . network import remote_port_tcp as _remote_port_tcp <EOL> from salt . ext . six . moves import zip <EOL> from salt . utils . decorators import with_deprecated <EOL> from salt . exceptions import CommandExecutionError <EOL> __virtualname__ = '<STR_LIT:status>' <EOL> __opts__ = { } <EOL> __func_alias__ = { <EOL> '<STR_LIT>' : '<STR_LIT:time>' <EOL> } <EOL> def __virtual__ ( ) : <EOL> if salt . utils . is_windows ( ) : <EOL> return False , '<STR_LIT>' <EOL> return __virtualname__ <EOL> def _number ( text ) : <EOL> '''<STR_LIT>''' <EOL> if text . isdigit ( ) : <EOL> return int ( text ) <EOL> try : <EOL> return float ( text ) <EOL> except ValueError : <EOL> return text <EOL> def procs ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> uind = <NUM_LIT:0> <EOL> pind = <NUM_LIT:0> <EOL> cind = <NUM_LIT:0> <EOL> plines = __salt__ [ '<STR_LIT>' ] ( __grains__ [ '<STR_LIT>' ] ) . splitlines ( ) <EOL> guide = plines . pop ( <NUM_LIT:0> ) . split ( ) <EOL> if '<STR_LIT>' in guide : <EOL> uind = guide . index ( '<STR_LIT>' ) <EOL> elif '<STR_LIT>' in guide : <EOL> uind = guide . index ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in guide : <EOL> pind = guide . index ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in guide : <EOL> cind = guide . index ( '<STR_LIT>' ) <EOL> elif '<STR_LIT>' in guide : <EOL> cind = guide . index ( '<STR_LIT>' ) <EOL> for line in plines : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( ) <EOL> ret [ comps [ pind ] ] = { '<STR_LIT:user>' : comps [ uind ] , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' . join ( comps [ cind : ] ) } <EOL> return ret <EOL> def custom ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> conf = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT:status>' ) <EOL> for key , val in six . iteritems ( conf ) : <EOL> func = '<STR_LIT>' . format ( key . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> ] ) <EOL> vals = eval ( func ) <EOL> for item in val : <EOL> ret [ item ] = vals [ item ] <EOL> return ret <EOL> @ with_deprecated ( globals ( ) , "<STR_LIT>" ) <EOL> def uptime ( ) : <EOL> '''<STR_LIT>''' <EOL> ut_path = "<STR_LIT>" <EOL> if not os . path . exists ( ut_path ) : <EOL> raise CommandExecutionError ( "<STR_LIT>" . format ( ut_path = ut_path ) ) <EOL> ut_ret = { <EOL> '<STR_LIT>' : int ( float ( open ( ut_path ) . read ( ) . strip ( ) . split ( ) [ <NUM_LIT:0> ] ) ) <EOL> } <EOL> utc_time = datetime . datetime . utcfromtimestamp ( time . time ( ) - ut_ret [ '<STR_LIT>' ] ) <EOL> ut_ret [ '<STR_LIT>' ] = utc_time . isoformat ( ) <EOL> ut_ret [ '<STR_LIT>' ] = time . mktime ( utc_time . timetuple ( ) ) <EOL> ut_ret [ '<STR_LIT>' ] = ut_ret [ '<STR_LIT>' ] / <NUM_LIT> / <NUM_LIT> / <NUM_LIT> <EOL> hours = ( ut_ret [ '<STR_LIT>' ] - ( ut_ret [ '<STR_LIT>' ] * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) / <NUM_LIT> / <NUM_LIT> <EOL> minutes = ( ( ut_ret [ '<STR_LIT>' ] - ( ut_ret [ '<STR_LIT>' ] * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) ) / <NUM_LIT> ) - hours * <NUM_LIT> <EOL> ut_ret [ '<STR_LIT:time>' ] = '<STR_LIT>' . format ( hours , minutes ) <EOL> ut_ret [ '<STR_LIT>' ] = len ( __salt__ [ '<STR_LIT>' ] ( "<STR_LIT>" ) . split ( os . linesep ) ) <EOL> return ut_ret <EOL> def _uptime ( human_readable = True ) : <EOL> '''<STR_LIT>''' <EOL> if human_readable : <EOL> return __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> else : <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> out = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . split ( ) <EOL> if len ( out ) : <EOL> return out [ <NUM_LIT:0> ] <EOL> else : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def loadavg ( ) : <EOL> '''<STR_LIT>''' <EOL> load_avg = os . getloadavg ( ) <EOL> return { '<STR_LIT>' : load_avg [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : load_avg [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : load_avg [ <NUM_LIT:2> ] } <EOL> def cpustats ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_cpustats ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( ) <EOL> if comps [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> ret [ comps [ <NUM_LIT:0> ] ] = { '<STR_LIT>' : _number ( comps [ <NUM_LIT:4> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:5> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:6> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:2> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:7> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:8> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:3> ] ) , <EOL> '<STR_LIT:user>' : _number ( comps [ <NUM_LIT:1> ] ) } <EOL> elif comps [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> ret [ comps [ <NUM_LIT:0> ] ] = { '<STR_LIT>' : _number ( comps [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT>' : [ _number ( x ) for x in comps [ <NUM_LIT:2> : ] ] } <EOL> elif comps [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> ret [ comps [ <NUM_LIT:0> ] ] = { '<STR_LIT>' : _number ( comps [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT>' : [ _number ( x ) for x in comps [ <NUM_LIT:2> : ] ] } <EOL> else : <EOL> ret [ comps [ <NUM_LIT:0> ] ] = _number ( comps [ <NUM_LIT:1> ] ) <EOL> return ret <EOL> def freebsd_cpustats ( ) : <EOL> '''<STR_LIT>''' <EOL> vmstat = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> vm0 = vmstat [ <NUM_LIT:0> ] . split ( ) <EOL> cpu0loc = vm0 . index ( '<STR_LIT>' ) <EOL> vm1 = vmstat [ <NUM_LIT:1> ] . split ( ) <EOL> usloc = vm1 . index ( '<STR_LIT>' ) <EOL> vm2 = vmstat [ <NUM_LIT:2> ] . split ( ) <EOL> cpuctr = <NUM_LIT:0> <EOL> ret = { } <EOL> for cpu in vm0 [ cpu0loc : ] : <EOL> ret [ cpu ] = { '<STR_LIT>' : _number ( vm2 [ usloc + <NUM_LIT:3> * cpuctr ] ) , <EOL> '<STR_LIT>' : _number ( vm2 [ usloc + <NUM_LIT:1> + <NUM_LIT:3> * cpuctr ] ) , <EOL> '<STR_LIT:id>' : _number ( vm2 [ usloc + <NUM_LIT:2> + <NUM_LIT:3> * cpuctr ] ) , } <EOL> cpuctr += <NUM_LIT:1> <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_cpustats , <EOL> '<STR_LIT>' : freebsd_cpustats , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def meminfo ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_meminfo ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( ) <EOL> comps [ <NUM_LIT:0> ] = comps [ <NUM_LIT:0> ] . replace ( '<STR_LIT::>' , '<STR_LIT>' ) <EOL> ret [ comps [ <NUM_LIT:0> ] ] = { <EOL> '<STR_LIT:value>' : comps [ <NUM_LIT:1> ] , <EOL> } <EOL> if len ( comps ) > <NUM_LIT:2> : <EOL> ret [ comps [ <NUM_LIT:0> ] ] [ '<STR_LIT>' ] = comps [ <NUM_LIT:2> ] <EOL> return ret <EOL> def freebsd_meminfo ( ) : <EOL> '''<STR_LIT>''' <EOL> sysctlvm = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> sysctlvm = [ x for x in sysctlvm if x . startswith ( '<STR_LIT>' ) ] <EOL> sysctlvm = [ x . split ( '<STR_LIT::>' ) for x in sysctlvm ] <EOL> sysctlvm = [ [ y . strip ( ) for y in x ] for x in sysctlvm ] <EOL> sysctlvm = [ x for x in sysctlvm if x [ <NUM_LIT:1> ] ] <EOL> ret = { } <EOL> for line in sysctlvm : <EOL> ret [ line [ <NUM_LIT:0> ] ] = line [ <NUM_LIT:1> ] <EOL> sysctlvmtot = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> sysctlvmtot = [ x for x in sysctlvmtot if x ] <EOL> ret [ '<STR_LIT>' ] = sysctlvmtot <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_meminfo , <EOL> '<STR_LIT>' : freebsd_meminfo , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def cpuinfo ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_cpuinfo ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( '<STR_LIT::>' ) <EOL> comps [ <NUM_LIT:0> ] = comps [ <NUM_LIT:0> ] . strip ( ) <EOL> if comps [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> ret [ comps [ <NUM_LIT:0> ] ] = comps [ <NUM_LIT:1> ] . split ( ) <EOL> else : <EOL> ret [ comps [ <NUM_LIT:0> ] ] = comps [ <NUM_LIT:1> ] . strip ( ) <EOL> return ret <EOL> def freebsd_cpuinfo ( ) : <EOL> '''<STR_LIT>''' <EOL> freebsd_cmd = '<STR_LIT>' <EOL> ret = { } <EOL> for line in __salt__ [ '<STR_LIT>' ] ( freebsd_cmd ) . splitlines ( ) : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( '<STR_LIT::>' ) <EOL> comps [ <NUM_LIT:0> ] = comps [ <NUM_LIT:0> ] . strip ( ) <EOL> ret [ comps [ <NUM_LIT:0> ] ] = comps [ <NUM_LIT:1> ] . strip ( ) <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_cpuinfo , <EOL> '<STR_LIT>' : freebsd_cpuinfo , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def diskstats ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_diskstats ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( ) <EOL> ret [ comps [ <NUM_LIT:2> ] ] = { '<STR_LIT>' : _number ( comps [ <NUM_LIT:0> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:2> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:3> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:4> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:5> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:6> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:7> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:8> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:9> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:10> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:11> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:12> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT> ] ) } <EOL> return ret <EOL> def freebsd_diskstats ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> iostat = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> header = iostat [ <NUM_LIT:1> ] <EOL> for line in iostat [ <NUM_LIT:2> : ] : <EOL> comps = line . split ( ) <EOL> ret [ comps [ <NUM_LIT:0> ] ] = { } <EOL> for metric , value in zip ( header . split ( ) [ <NUM_LIT:1> : ] , comps [ <NUM_LIT:1> : ] ) : <EOL> ret [ comps [ <NUM_LIT:0> ] ] [ metric ] = _number ( value ) <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_diskstats , <EOL> '<STR_LIT>' : freebsd_diskstats , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def diskusage ( * args ) : <EOL> '''<STR_LIT>''' <EOL> selected = set ( ) <EOL> fstypes = set ( ) <EOL> if not args : <EOL> fstypes . add ( '<STR_LIT:*>' ) <EOL> else : <EOL> for arg in args : <EOL> if arg . startswith ( '<STR_LIT:/>' ) : <EOL> selected . add ( arg ) <EOL> else : <EOL> fstypes . add ( arg ) <EOL> if fstypes : <EOL> regex = re . compile ( <EOL> '<STR_LIT:|>' . join ( <EOL> fnmatch . translate ( fstype ) . format ( '<STR_LIT>' ) for fstype in fstypes <EOL> ) <EOL> ) <EOL> if __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> ifile = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . readlines ( ) <EOL> elif __grains__ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> ifile = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> else : <EOL> ifile = [ ] <EOL> for line in ifile : <EOL> comps = line . split ( ) <EOL> if len ( comps ) >= <NUM_LIT:3> : <EOL> mntpt = comps [ <NUM_LIT:1> ] <EOL> fstype = comps [ <NUM_LIT:2> ] <EOL> if regex . match ( fstype ) : <EOL> selected . add ( mntpt ) <EOL> ret = { } <EOL> for path in selected : <EOL> fsstats = os . statvfs ( path ) <EOL> blksz = fsstats . f_bsize <EOL> available = fsstats . f_bavail * blksz <EOL> total = fsstats . f_blocks * blksz <EOL> ret [ path ] = { "<STR_LIT>" : available , "<STR_LIT>" : total } <EOL> return ret <EOL> def vmstats ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_vmstats ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( ) <EOL> ret [ comps [ <NUM_LIT:0> ] ] = _number ( comps [ <NUM_LIT:1> ] ) <EOL> return ret <EOL> def freebsd_vmstats ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> for line in __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) : <EOL> comps = line . split ( ) <EOL> if comps [ <NUM_LIT:0> ] . isdigit ( ) : <EOL> ret [ '<STR_LIT:U+0020>' . join ( comps [ <NUM_LIT:1> : ] ) ] = _number ( comps [ <NUM_LIT:0> ] ) <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_vmstats , <EOL> '<STR_LIT>' : freebsd_vmstats , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def nproc ( ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> return int ( __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . strip ( ) ) <EOL> except ValueError : <EOL> return <NUM_LIT:0> <EOL> def netstats ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_netstats ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> headers = [ '<STR_LIT>' ] <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> comps = line . split ( ) <EOL> if comps [ <NUM_LIT:0> ] == headers [ <NUM_LIT:0> ] : <EOL> index = len ( headers ) - <NUM_LIT:1> <EOL> row = { } <EOL> for field in range ( index ) : <EOL> if field < <NUM_LIT:1> : <EOL> continue <EOL> else : <EOL> row [ headers [ field ] ] = _number ( comps [ field ] ) <EOL> rowname = headers [ <NUM_LIT:0> ] . replace ( '<STR_LIT::>' , '<STR_LIT>' ) <EOL> ret [ rowname ] = row <EOL> else : <EOL> headers = comps <EOL> return ret <EOL> def freebsd_netstats ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> for line in __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) : <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> if not line . startswith ( '<STR_LIT:\t>' ) : <EOL> key = line . split ( ) [ <NUM_LIT:0> ] <EOL> ret [ key ] = { } <EOL> else : <EOL> comps = line . split ( ) <EOL> if comps [ <NUM_LIT:0> ] . isdigit ( ) : <EOL> ret [ key ] [ '<STR_LIT:U+0020>' . join ( comps [ <NUM_LIT:1> : ] ) ] = comps [ <NUM_LIT:0> ] <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_netstats , <EOL> '<STR_LIT>' : freebsd_netstats , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def netdev ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_netdev ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> stats = salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> ret = { } <EOL> for line in stats : <EOL> if not line : <EOL> continue <EOL> if line . find ( '<STR_LIT::>' ) < <NUM_LIT:0> : <EOL> continue <EOL> comps = line . split ( ) <EOL> comps [ <NUM_LIT:0> ] = line . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] . strip ( ) <EOL> comps . insert ( <NUM_LIT:1> , line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] . strip ( ) . split ( ) [ <NUM_LIT:0> ] ) <EOL> ret [ comps [ <NUM_LIT:0> ] ] = { '<STR_LIT>' : comps [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:7> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:4> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:3> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:5> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:6> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:8> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:2> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:9> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:15> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:16> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:12> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:11> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT> ] ) , <EOL> '<STR_LIT>' : _number ( comps [ <NUM_LIT:10> ] ) } <EOL> return ret <EOL> def freebsd_netdev ( ) : <EOL> '''<STR_LIT>''' <EOL> _dict_tree = lambda : collections . defaultdict ( _dict_tree ) <EOL> ret = _dict_tree ( ) <EOL> netstat = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> netstat += __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) [ <NUM_LIT:1> : ] <EOL> header = netstat [ <NUM_LIT:0> ] . split ( ) <EOL> for line in netstat [ <NUM_LIT:1> : ] : <EOL> comps = line . split ( ) <EOL> for i in range ( <NUM_LIT:4> , <NUM_LIT> ) : <EOL> ret [ comps [ <NUM_LIT:0> ] ] [ comps [ <NUM_LIT:2> ] ] [ comps [ <NUM_LIT:3> ] ] [ header [ i ] ] = _number ( comps [ i ] ) <EOL> return ret <EOL> get_version = { <EOL> '<STR_LIT>' : linux_netdev , <EOL> '<STR_LIT>' : freebsd_netdev , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def w ( ) : <EOL> '''<STR_LIT>''' <EOL> user_list = [ ] <EOL> users = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) . splitlines ( ) <EOL> for row in users : <EOL> if not row : <EOL> continue <EOL> comps = row . split ( ) <EOL> rec = { '<STR_LIT>' : comps [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : comps [ <NUM_LIT:4> ] , <EOL> '<STR_LIT>' : comps [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : comps [ <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : comps [ <NUM_LIT:1> ] , <EOL> '<STR_LIT:user>' : comps [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' . join ( comps [ <NUM_LIT:6> : ] ) } <EOL> user_list . append ( rec ) <EOL> return user_list <EOL> def all_status ( ) : <EOL> '''<STR_LIT>''' <EOL> return { '<STR_LIT>' : cpuinfo ( ) , <EOL> '<STR_LIT>' : cpustats ( ) , <EOL> '<STR_LIT>' : diskstats ( ) , <EOL> '<STR_LIT>' : diskusage ( ) , <EOL> '<STR_LIT>' : loadavg ( ) , <EOL> '<STR_LIT>' : meminfo ( ) , <EOL> '<STR_LIT>' : netdev ( ) , <EOL> '<STR_LIT>' : netstats ( ) , <EOL> '<STR_LIT>' : uptime ( ) , <EOL> '<STR_LIT>' : vmstats ( ) , <EOL> '<STR_LIT:w>' : w ( ) } <EOL> def pid ( sig ) : <EOL> '''<STR_LIT>''' <EOL> cmd = __grains__ [ '<STR_LIT>' ] <EOL> output = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> pids = '<STR_LIT>' <EOL> for line in output . splitlines ( ) : <EOL> if '<STR_LIT>' in line : <EOL> continue <EOL> if re . search ( sig , line ) : <EOL> if pids : <EOL> pids += '<STR_LIT:\n>' <EOL> pids += line . split ( ) [ <NUM_LIT:1> ] <EOL> return pids <EOL> def version ( ) : <EOL> '''<STR_LIT>''' <EOL> def linux_version ( ) : <EOL> '''<STR_LIT>''' <EOL> procf = '<STR_LIT>' <EOL> if not os . path . isfile ( procf ) : <EOL> return { } <EOL> return salt . utils . fopen ( procf , '<STR_LIT:r>' ) . read ( ) . strip ( ) <EOL> get_version = { <EOL> '<STR_LIT>' : linux_version , <EOL> '<STR_LIT>' : lambda : __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) , <EOL> } <EOL> errmsg = '<STR_LIT>' <EOL> return get_version . get ( __grains__ [ '<STR_LIT>' ] , lambda : errmsg ) ( ) <EOL> def master ( master = None , connected = True ) : <EOL> '''<STR_LIT>''' <EOL> port = <NUM_LIT> <EOL> master_ip = None <EOL> if __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) != '<STR_LIT>' : <EOL> port = int ( __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) ) <EOL> if master is not None : <EOL> tmp_ip = _host_to_ip ( master ) <EOL> if tmp_ip is not None : <EOL> master_ip = tmp_ip <EOL> ips = _remote_port_tcp ( port ) <EOL> if connected : <EOL> if master_ip not in ips : <EOL> event = salt . utils . event . get_event ( '<STR_LIT>' , opts = __opts__ , listen = False ) <EOL> event . fire_event ( { '<STR_LIT>' : master } , '<STR_LIT>' ) <EOL> else : <EOL> if master_ip in ips : <EOL> event = salt . utils . event . get_event ( '<STR_LIT>' , opts = __opts__ , listen = False ) <EOL> event . fire_event ( { '<STR_LIT>' : master } , '<STR_LIT>' ) <EOL> def ping_master ( master ) : <EOL> '''<STR_LIT>''' <EOL> if master is None or master == '<STR_LIT>' : <EOL> return False <EOL> opts = copy . deepcopy ( __opts__ ) <EOL> opts [ '<STR_LIT>' ] = master <EOL> del opts [ '<STR_LIT>' ] <EOL> opts . update ( salt . minion . prep_ip_port ( opts ) ) <EOL> try : <EOL> opts . update ( salt . minion . resolve_dns ( opts , fallback = False ) ) <EOL> except Exception : <EOL> return False <EOL> timeout = opts . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> load = { '<STR_LIT>' : '<STR_LIT>' } <EOL> result = False <EOL> channel = salt . transport . client . ReqChannel . factory ( opts , crypt = '<STR_LIT>' ) <EOL> try : <EOL> payload = channel . send ( load , tries = <NUM_LIT:0> , timeout = timeout ) <EOL> result = True <EOL> except Exception as e : <EOL> pass <EOL> if result : <EOL> event = salt . utils . event . get_event ( '<STR_LIT>' , opts = __opts__ , listen = False ) <EOL> event . fire_event ( { '<STR_LIT>' : master } , '<STR_LIT>' ) <EOL> return result <EOL> def time_ ( format = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> dt = datetime . datetime . today ( ) <EOL> return dt . strftime ( format ) </s>
