<s> '''<STR_LIT>''' <EOL> import os <EOL> import copy <EOL> import subprocess <EOL> def _is_docker ( ) : <EOL> """<STR_LIT>""" <EOL> docker = False <EOL> try : <EOL> docker = bool ( __grains__ . get ( '<STR_LIT>' ) ) <EOL> except ( ValueError , NameError , IndexError ) : <EOL> pass <EOL> if not docker : <EOL> try : <EOL> docker = '<STR_LIT>' in open ( '<STR_LIT>' ) . read ( ) <EOL> except ( IOError , OSError ) : <EOL> docker = False <EOL> if not docker : <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> docker = True <EOL> return docker <EOL> def _is_lxc ( ) : <EOL> """<STR_LIT>""" <EOL> lxc = None <EOL> if _is_docker ( ) : <EOL> lxc = False <EOL> if lxc is None : <EOL> try : <EOL> lxc = __grains__ . get ( '<STR_LIT>' , None ) <EOL> except ( ValueError , NameError , IndexError ) : <EOL> pass <EOL> if lxc is None : <EOL> try : <EOL> cgroups = open ( '<STR_LIT>' ) . read ( ) . splitlines ( ) <EOL> lxc = not '<STR_LIT:/>' == [ a . split ( '<STR_LIT::>' ) [ - <NUM_LIT:1> ] <EOL> for a in cgroups <EOL> if '<STR_LIT>' in a or <EOL> '<STR_LIT>' in a ] [ - <NUM_LIT:1> ] <EOL> except Exception : <EOL> lxc = False <EOL> return lxc and not _is_docker ( ) <EOL> def _is_container ( ) : <EOL> return _is_docker ( ) or _is_lxc ( ) <EOL> def _devhost_num ( ) : <EOL> return '<STR_LIT>' <EOL> def _routes ( ) : <EOL> routes , default_route = [ ] , { } <EOL> troutes = subprocess . Popen ( <EOL> '<STR_LIT>' , <EOL> shell = True , stdout = subprocess . PIPE <EOL> ) . stdout . read ( ) . strip ( ) <EOL> for route in troutes . splitlines ( ) [ <NUM_LIT:1> : ] : <EOL> try : <EOL> parts = route . split ( ) <EOL> if '<STR_LIT>' in parts [ <NUM_LIT:0> ] . lower ( ) : <EOL> continue <EOL> droute = { '<STR_LIT>' : parts [ - <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : parts [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : parts [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : parts [ <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : parts [ <NUM_LIT:4> ] , <EOL> '<STR_LIT>' : parts [ <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : parts [ <NUM_LIT:6> ] } <EOL> if parts [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> default_route = copy . deepcopy ( droute ) <EOL> routes . append ( droute ) <EOL> except Exception : <EOL> continue <EOL> return routes , default_route , default_route . get ( '<STR_LIT>' , None ) <EOL> def _is_vm ( ) : <EOL> ret = False <EOL> if _is_container ( ) : <EOL> ret = True <EOL> return ret <EOL> def _is_devhost ( ) : <EOL> return _devhost_num ( ) != '<STR_LIT>' <EOL> def _nodetype ( ) : <EOL> f = '<STR_LIT>' <EOL> if os . path . exists ( f ) : <EOL> with open ( f ) as fic : <EOL> return fic . read ( ) <EOL> return '<STR_LIT>' <EOL> def _is_upstart ( ) : <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> return True <EOL> return False <EOL> def _is_systemd ( ) : <EOL> try : <EOL> is_ = os . readlink ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> except ( IOError , OSError ) : <EOL> is_ = False <EOL> rd = '<STR_LIT>' <EOL> try : <EOL> if os . path . exists ( rd ) and len ( os . listdir ( rd ) ) > <NUM_LIT:4> : <EOL> is_ = True <EOL> except ( IOError , OSError ) : <EOL> is_ = False <EOL> return is_ <EOL> def _pgsql_vers ( ) : <EOL> vers = { '<STR_LIT>' : { } , '<STR_LIT>' : { } } <EOL> for i in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> pid = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( i ) ) <EOL> dbase = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( i ) ) <EOL> dglobal = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( i ) ) <EOL> running = False <EOL> has_data = False <EOL> if os . path . exists ( pid ) : <EOL> running = True <EOL> for d in [ dbase , dglobal ] : <EOL> if not os . path . exists ( d ) : <EOL> continue <EOL> if os . listdir ( d ) > <NUM_LIT:2> : <EOL> has_data = True <EOL> if running or has_data : <EOL> vers [ '<STR_LIT>' ] [ i ] = True <EOL> vers [ '<STR_LIT>' ] [ i ] = { '<STR_LIT>' : running , <EOL> '<STR_LIT>' : has_data } <EOL> return vers <EOL> def get_makina_grains ( ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> routes , default_route , gw = _routes ( ) <EOL> grains = { '<STR_LIT>' : _is_upstart ( ) , <EOL> '<STR_LIT>' : _is_container ( ) , <EOL> '<STR_LIT>' : _is_vm ( ) , <EOL> '<STR_LIT>' : _is_lxc ( ) , <EOL> '<STR_LIT>' : _nodetype ( ) , <EOL> '<STR_LIT>' : _is_systemd ( ) , <EOL> '<STR_LIT>' : _pgsql_vers ( ) , <EOL> '<STR_LIT>' : _is_docker ( ) , <EOL> '<STR_LIT>' : _devhost_num ( ) , <EOL> '<STR_LIT>' : default_route , <EOL> '<STR_LIT>' : gw , <EOL> '<STR_LIT>' : routes } <EOL> return grains </s>
