def set_etcd_facts_if_unset(facts):
 if (('master' in facts) and safe_get_bool(facts['master']['embedded_etcd'])):
  etcd_facts = (facts['etcd'] if ('etcd' in facts) else dict())
  if ('etcd_data_dir' not in etcd_facts):
   try:
    master_cfg_path = os.path.join(facts['common']['config_base'], 'master/master-config.yaml')
    master_cfg_f = open(master_cfg_path, 'r')
    config = yaml.safe_load(master_cfg_f.read())
    master_cfg_f.close()
    etcd_facts['etcd_data_dir'] = config['etcdConfig']['storageDirectory']
    facts['etcd'] = etcd_facts
   except Exception:
    pass
 else:
  etcd_facts = (facts['etcd'] if ('etcd' in facts) else dict())
  try:
   ini_str = text_type(('[root]\n' + open('/etc/etcd/etcd.conf', 'r').read()), 'utf-8')
   ini_fp = io.StringIO(ini_str)
   config = configparser.RawConfigParser()
   config.readfp(ini_fp)
   etcd_data_dir = config.get('root', 'ETCD_DATA_DIR')
   if (etcd_data_dir.startswith('"') and etcd_data_dir.endswith('"')):
    etcd_data_dir = etcd_data_dir[1:(-1)]
   etcd_facts['etcd_data_dir'] = etcd_data_dir
   facts['etcd'] = etcd_facts
  except Exception:
   pass
 return facts

def set_etcd_facts_if_unset ( facts ) : if ( ( 'master' in facts ) and safe_get_bool ( facts [ 'master' ] [ 'embedded_etcd' ] ) ) : etcd_facts = ( facts [ 'etcd' ] if ( 'etcd' in facts ) else dict ( ) ) if ( 'etcd_data_dir' not in etcd_facts ) : try : master_cfg_path = os . path . join ( facts [ 'common' ] [ 'config_base' ] , 'master/master-config.yaml' ) master_cfg_f = open ( master_cfg_path , 'r' ) config = yaml . safe_load ( master_cfg_f . read ( ) ) master_cfg_f . close ( ) etcd_facts [ 'etcd_data_dir' ] = config [ 'etcdConfig' ] [ 'storageDirectory' ] facts [ 'etcd' ] = etcd_facts except Exception : pass else : etcd_facts = ( facts [ 'etcd' ] if ( 'etcd' in facts ) else dict ( ) ) try : ini_str = text_type ( ( '[root]\n' + open ( '/etc/etcd/etcd.conf' , 'r' ) . read ( ) ) , 'utf-8' ) ini_fp = io . StringIO ( ini_str ) config = configparser . RawConfigParser ( ) config . readfp ( ini_fp ) etcd_data_dir = config . get ( 'root' , 'ETCD_DATA_DIR' ) if ( etcd_data_dir . startswith ( '"' ) and etcd_data_dir . endswith ( '"' ) ) : etcd_data_dir = etcd_data_dir [ 1 : ( - 1 ) ] etcd_facts [ 'etcd_data_dir' ] = etcd_data_dir facts [ 'etcd' ] = etcd_facts except Exception : pass return facts
if using embedded etcd .