<s> """<STR_LIT>""" <EOL> DOCUMENTATION = '''<STR_LIT>''' <EOL> EXAMPLES = '''<STR_LIT:U+0020>''' <EOL> import ConfigParser <EOL> import copy <EOL> import os <EOL> import StringIO <EOL> import yaml <EOL> from distutils . util import strtobool <EOL> from distutils . version import LooseVersion <EOL> import struct <EOL> import socket <EOL> from dbus import SystemBus , Interface <EOL> from dbus . exceptions import DBusException <EOL> def migrate_docker_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> } <EOL> if '<STR_LIT>' not in facts : <EOL> facts [ '<STR_LIT>' ] = { } <EOL> for role in params . keys ( ) : <EOL> if role in facts : <EOL> for param in params [ role ] : <EOL> old_param = '<STR_LIT>' + param <EOL> if old_param in facts [ role ] : <EOL> facts [ '<STR_LIT>' ] [ param ] = facts [ role ] . pop ( old_param ) <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] and isinstance ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , basestring ) : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] . split ( "<STR_LIT:U+002C>" ) <EOL> return facts <EOL> def migrate_common_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' ) <EOL> } <EOL> if '<STR_LIT>' not in facts : <EOL> facts [ '<STR_LIT>' ] = { } <EOL> for role in params . keys ( ) : <EOL> if role in facts : <EOL> for param in params [ role ] : <EOL> if param in facts [ role ] : <EOL> facts [ '<STR_LIT>' ] [ param ] = facts [ role ] . pop ( param ) <EOL> return facts <EOL> def migrate_node_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' ) , <EOL> } <EOL> if '<STR_LIT>' not in facts : <EOL> facts [ '<STR_LIT>' ] = { } <EOL> for role in params . keys ( ) : <EOL> if role in facts : <EOL> for param in params [ role ] : <EOL> if param in facts [ role ] : <EOL> facts [ '<STR_LIT>' ] [ param ] = facts [ role ] . pop ( param ) <EOL> return facts <EOL> def migrate_local_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> migrated_facts = copy . deepcopy ( facts ) <EOL> migrated_facts = migrate_docker_facts ( migrated_facts ) <EOL> migrated_facts = migrate_common_facts ( migrated_facts ) <EOL> migrated_facts = migrate_node_facts ( migrated_facts ) <EOL> migrated_facts = migrate_hosted_facts ( migrated_facts ) <EOL> return migrated_facts <EOL> def migrate_hosted_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' not in facts : <EOL> facts [ '<STR_LIT>' ] = { } <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { } <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> return facts <EOL> def first_ip ( network ) : <EOL> """<STR_LIT>""" <EOL> atoi = lambda addr : struct . unpack ( "<STR_LIT>" , socket . inet_aton ( addr ) ) [ <NUM_LIT:0> ] <EOL> itoa = lambda addr : socket . inet_ntoa ( struct . pack ( "<STR_LIT>" , addr ) ) <EOL> ( address , netmask ) = network . split ( '<STR_LIT:/>' ) <EOL> netmask_i = ( <NUM_LIT> << ( <NUM_LIT:32> - atoi ( netmask ) ) ) & <NUM_LIT> <EOL> return itoa ( ( atoi ( address ) & netmask_i ) + <NUM_LIT:1> ) <EOL> def hostname_valid ( hostname ) : <EOL> """<STR_LIT>""" <EOL> if ( not hostname or <EOL> hostname . startswith ( '<STR_LIT:localhost>' ) or <EOL> hostname . endswith ( '<STR_LIT>' ) or <EOL> len ( hostname . split ( '<STR_LIT:.>' ) ) < <NUM_LIT:2> ) : <EOL> return False <EOL> return True <EOL> def choose_hostname ( hostnames = None , fallback = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> hostname = fallback <EOL> if hostnames is None : <EOL> return hostname <EOL> ip_regex = r'<STR_LIT>' <EOL> ips = [ i for i in hostnames <EOL> if ( i is not None and isinstance ( i , basestring ) <EOL> and re . match ( ip_regex , i ) ) ] <EOL> hosts = [ i for i in hostnames <EOL> if i is not None and i != '<STR_LIT>' and i not in ips ] <EOL> for host_list in ( hosts , ips ) : <EOL> for host in host_list : <EOL> if hostname_valid ( host ) : <EOL> return host <EOL> return hostname <EOL> def query_metadata ( metadata_url , headers = None , expect_json = False ) : <EOL> """<STR_LIT>""" <EOL> result , info = fetch_url ( module , metadata_url , headers = headers ) <EOL> if info [ '<STR_LIT:status>' ] != <NUM_LIT:200> : <EOL> raise OpenShiftFactsMetadataUnavailableError ( "<STR_LIT>" ) <EOL> if expect_json : <EOL> return module . from_json ( result . read ( ) ) <EOL> else : <EOL> return [ line . strip ( ) for line in result . readlines ( ) ] <EOL> def walk_metadata ( metadata_url , headers = None , expect_json = False ) : <EOL> """<STR_LIT>""" <EOL> metadata = dict ( ) <EOL> for line in query_metadata ( metadata_url , headers , expect_json ) : <EOL> if line . endswith ( '<STR_LIT:/>' ) and not line == '<STR_LIT>' : <EOL> key = line [ : - <NUM_LIT:1> ] <EOL> metadata [ key ] = walk_metadata ( metadata_url + line , <EOL> headers , expect_json ) <EOL> else : <EOL> results = query_metadata ( metadata_url + line , headers , <EOL> expect_json ) <EOL> if len ( results ) == <NUM_LIT:1> : <EOL> metadata [ line ] = results . pop ( ) <EOL> else : <EOL> metadata [ line ] = results <EOL> return metadata <EOL> def get_provider_metadata ( metadata_url , supports_recursive = False , <EOL> headers = None , expect_json = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if supports_recursive : <EOL> metadata = query_metadata ( metadata_url , headers , <EOL> expect_json ) <EOL> else : <EOL> metadata = walk_metadata ( metadata_url , headers , <EOL> expect_json ) <EOL> except OpenShiftFactsMetadataUnavailableError : <EOL> metadata = None <EOL> return metadata <EOL> def normalize_gce_facts ( metadata , facts ) : <EOL> """<STR_LIT>""" <EOL> for interface in metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> int_info = dict ( ips = [ interface [ '<STR_LIT>' ] ] , network_type = '<STR_LIT>' ) <EOL> int_info [ '<STR_LIT>' ] = [ ac [ '<STR_LIT>' ] for ac <EOL> in interface [ '<STR_LIT>' ] ] <EOL> int_info [ '<STR_LIT>' ] . extend ( interface [ '<STR_LIT>' ] ) <EOL> _ , _ , network_id = interface [ '<STR_LIT>' ] . rpartition ( '<STR_LIT:/>' ) <EOL> int_info [ '<STR_LIT>' ] = network_id <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( int_info ) <EOL> _ , _ , zone = metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] . rpartition ( '<STR_LIT:/>' ) <EOL> facts [ '<STR_LIT>' ] = zone <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> pub_ip = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = pub_ip <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return facts <EOL> def normalize_aws_facts ( metadata , facts ) : <EOL> """<STR_LIT>""" <EOL> for interface in sorted ( <EOL> metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] . values ( ) , <EOL> key = lambda x : x [ '<STR_LIT>' ] <EOL> ) : <EOL> int_info = dict ( ) <EOL> var_map = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> for ips_var , int_var in var_map . iteritems ( ) : <EOL> ips = interface . get ( int_var ) <EOL> if isinstance ( ips , basestring ) : <EOL> int_info [ ips_var ] = [ ips ] <EOL> else : <EOL> int_info [ ips_var ] = ips <EOL> if '<STR_LIT>' in interface : <EOL> int_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> int_info [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if int_info [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> int_info [ '<STR_LIT>' ] = interface [ '<STR_LIT>' ] <EOL> else : <EOL> int_info [ '<STR_LIT>' ] = None <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( int_info ) <EOL> facts [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata . get ( '<STR_LIT>' ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata . get ( '<STR_LIT>' ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata . get ( '<STR_LIT>' ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata . get ( '<STR_LIT>' ) <EOL> return facts <EOL> def normalize_openstack_facts ( metadata , facts ) : <EOL> """<STR_LIT>""" <EOL> facts [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] <EOL> local_ipv4 = metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:0> ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = local_ipv4 <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = metadata [ '<STR_LIT>' ] <EOL> pub_h = metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = pub_h <EOL> return facts <EOL> def normalize_provider_facts ( provider , metadata ) : <EOL> """<STR_LIT>""" <EOL> if provider is None or metadata is None : <EOL> return { } <EOL> facts = dict ( name = provider , metadata = metadata , <EOL> network = dict ( interfaces = [ ] , ipv6_enabled = False ) ) <EOL> if provider == '<STR_LIT>' : <EOL> facts = normalize_gce_facts ( metadata , facts ) <EOL> elif provider == '<STR_LIT>' : <EOL> facts = normalize_aws_facts ( metadata , facts ) <EOL> elif provider == '<STR_LIT>' : <EOL> facts = normalize_openstack_facts ( metadata , facts ) <EOL> return facts <EOL> def set_flannel_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> use_flannel = False <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = use_flannel <EOL> return facts <EOL> def set_nuage_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> use_nuage = False <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = use_nuage <EOL> return facts <EOL> def set_node_schedulability ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in facts : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = False <EOL> else : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> return facts <EOL> def set_selectors ( facts ) : <EOL> """<STR_LIT>""" <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if deployment_type == '<STR_LIT>' : <EOL> selector = "<STR_LIT>" <EOL> else : <EOL> selector = "<STR_LIT>" <EOL> if '<STR_LIT>' not in facts : <EOL> facts [ '<STR_LIT>' ] = { } <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { } <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] or facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] in [ None , '<STR_LIT:None>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = selector <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = selector <EOL> return facts <EOL> def set_metrics_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> use_cluster_metrics = False <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = use_cluster_metrics <EOL> return facts <EOL> def set_dnsmasq_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] and facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> else : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = False <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> else : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT> <EOL> return facts <EOL> def set_project_cfg_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> if '<STR_LIT>' in facts : <EOL> for key , value in config . items ( ) : <EOL> if key not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ key ] = value <EOL> return facts <EOL> def set_identity_providers_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> identity_provider = dict ( <EOL> name = '<STR_LIT>' , challenge = True , login = True , <EOL> kind = '<STR_LIT>' <EOL> ) <EOL> if deployment_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> identity_provider = dict ( <EOL> name = '<STR_LIT>' , challenge = True , login = True , <EOL> kind = '<STR_LIT>' <EOL> ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ identity_provider ] <EOL> return facts <EOL> def set_url_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> hostname = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> cluster_hostname = facts [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> cluster_public_hostname = facts [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> public_hostname = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> api_hostname = cluster_hostname if cluster_hostname else hostname <EOL> api_public_hostname = cluster_public_hostname if cluster_public_hostname else public_hostname <EOL> console_path = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> etcd_hosts = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> use_ssl = dict ( <EOL> api = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> public_api = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> loopback_api = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> console = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> public_console = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> etcd = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> ) <EOL> ports = dict ( <EOL> api = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> public_api = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> loopback_api = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> console = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> public_console = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> etcd = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> ) <EOL> etcd_urls = [ ] <EOL> if etcd_hosts != '<STR_LIT>' : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = ports [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = False <EOL> for host in etcd_hosts : <EOL> etcd_urls . append ( format_url ( use_ssl [ '<STR_LIT>' ] , host , <EOL> ports [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> etcd_urls = [ format_url ( use_ssl [ '<STR_LIT>' ] , hostname , <EOL> ports [ '<STR_LIT>' ] ) ] <EOL> facts [ '<STR_LIT>' ] . setdefault ( '<STR_LIT>' , etcd_urls ) <EOL> prefix_hosts = [ ( '<STR_LIT>' , api_hostname ) , <EOL> ( '<STR_LIT>' , api_public_hostname ) , <EOL> ( '<STR_LIT>' , hostname ) ] <EOL> for prefix , host in prefix_hosts : <EOL> facts [ '<STR_LIT>' ] . setdefault ( prefix + '<STR_LIT>' , format_url ( use_ssl [ prefix ] , <EOL> host , <EOL> ports [ prefix ] ) ) <EOL> r_lhn = "<STR_LIT>" . format ( hostname , ports [ '<STR_LIT>' ] ) . replace ( '<STR_LIT:.>' , '<STR_LIT:->' ) <EOL> r_lhu = "<STR_LIT>" . format ( api_hostname , ports [ '<STR_LIT>' ] ) . replace ( '<STR_LIT:.>' , '<STR_LIT:->' ) <EOL> facts [ '<STR_LIT>' ] . setdefault ( '<STR_LIT>' , r_lhn ) <EOL> facts [ '<STR_LIT>' ] . setdefault ( '<STR_LIT>' , "<STR_LIT>" . format ( r_lhn ) ) <EOL> facts [ '<STR_LIT>' ] . setdefault ( '<STR_LIT>' , r_lhu ) <EOL> prefix_hosts = [ ( '<STR_LIT>' , api_hostname ) , ( '<STR_LIT>' , api_public_hostname ) ] <EOL> for prefix , host in prefix_hosts : <EOL> facts [ '<STR_LIT>' ] . setdefault ( prefix + '<STR_LIT>' , format_url ( use_ssl [ prefix ] , <EOL> host , <EOL> ports [ prefix ] , <EOL> console_path ) ) <EOL> return facts <EOL> def set_aggregate_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> all_hostnames = set ( ) <EOL> internal_hostnames = set ( ) <EOL> kube_svc_ip = first_ip ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in facts : <EOL> all_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> all_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> all_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> all_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = kube_svc_ip <EOL> internal_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> internal_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> cluster_domain = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> all_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> all_hostnames . add ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> svc_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' + cluster_domain , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' + cluster_domain ] <EOL> all_hostnames . update ( svc_names ) <EOL> internal_hostnames . update ( svc_names ) <EOL> all_hostnames . add ( kube_svc_ip ) <EOL> internal_hostnames . add ( kube_svc_ip ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = list ( all_hostnames ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = list ( internal_hostnames ) <EOL> return facts <EOL> def set_etcd_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts and facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> etcd_facts = facts [ '<STR_LIT>' ] if '<STR_LIT>' in facts else dict ( ) <EOL> if '<STR_LIT>' not in etcd_facts : <EOL> try : <EOL> master_cfg_path = os . path . join ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) <EOL> master_cfg_f = open ( master_cfg_path , '<STR_LIT:r>' ) <EOL> config = yaml . safe_load ( master_cfg_f . read ( ) ) <EOL> master_cfg_f . close ( ) <EOL> etcd_facts [ '<STR_LIT>' ] = config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] = etcd_facts <EOL> except Exception : <EOL> pass <EOL> else : <EOL> etcd_facts = facts [ '<STR_LIT>' ] if '<STR_LIT>' in facts else dict ( ) <EOL> try : <EOL> ini_str = '<STR_LIT>' + open ( '<STR_LIT>' , '<STR_LIT:r>' ) . read ( ) <EOL> ini_fp = StringIO . StringIO ( ini_str ) <EOL> config = ConfigParser . RawConfigParser ( ) <EOL> config . readfp ( ini_fp ) <EOL> etcd_data_dir = config . get ( '<STR_LIT:root>' , '<STR_LIT>' ) <EOL> if etcd_data_dir . startswith ( '<STR_LIT:">' ) and etcd_data_dir . endswith ( '<STR_LIT:">' ) : <EOL> etcd_data_dir = etcd_data_dir [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> etcd_facts [ '<STR_LIT>' ] = etcd_data_dir <EOL> facts [ '<STR_LIT>' ] = etcd_facts <EOL> except Exception : <EOL> pass <EOL> return facts <EOL> def set_deployment_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> service_type = '<STR_LIT>' <EOL> if deployment_type == '<STR_LIT>' : <EOL> service_type = '<STR_LIT>' <EOL> elif deployment_type in [ '<STR_LIT>' ] : <EOL> service_type = '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = service_type <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> config_base = '<STR_LIT>' <EOL> if deployment_type in [ '<STR_LIT>' ] : <EOL> config_base = '<STR_LIT>' <EOL> if not os . path . exists ( config_base ) and os . path . exists ( '<STR_LIT>' ) : <EOL> config_base = '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = config_base <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> data_dir = '<STR_LIT>' <EOL> if deployment_type in [ '<STR_LIT>' ] : <EOL> data_dir = '<STR_LIT>' <EOL> if not os . path . exists ( data_dir ) and os . path . exists ( '<STR_LIT>' ) : <EOL> data_dir = '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = data_dir <EOL> if '<STR_LIT>' in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if deployment_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> addtl_regs = facts [ '<STR_LIT>' ] . get ( '<STR_LIT>' , [ ] ) <EOL> ent_reg = '<STR_LIT>' <EOL> if ent_reg not in addtl_regs : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = addtl_regs + [ ent_reg ] <EOL> for role in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if role in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in facts [ role ] : <EOL> registry_url = '<STR_LIT>' <EOL> if deployment_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> registry_url = '<STR_LIT>' <EOL> elif deployment_type == '<STR_LIT>' : <EOL> registry_url = '<STR_LIT>' <EOL> facts [ role ] [ '<STR_LIT>' ] = registry_url <EOL> if '<STR_LIT>' in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> openshift_features = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if deployment_type == '<STR_LIT>' : <EOL> curr_disabled_features = set ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = list ( curr_disabled_features . union ( openshift_features ) ) <EOL> else : <EOL> if deployment_type == '<STR_LIT>' : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = openshift_features <EOL> if '<STR_LIT>' in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> if deployment_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> return facts <EOL> def set_version_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> version = get_openshift_version ( facts ) <EOL> if version is not None : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] = version <EOL> if deployment_type == '<STR_LIT>' : <EOL> version_gte_3_1_or_1_1 = LooseVersion ( version ) >= LooseVersion ( '<STR_LIT>' ) <EOL> version_gte_3_1_1_or_1_1_1 = LooseVersion ( version ) >= LooseVersion ( '<STR_LIT>' ) <EOL> version_gte_3_2_or_1_2 = LooseVersion ( version ) >= LooseVersion ( '<STR_LIT>' ) <EOL> else : <EOL> version_gte_3_1_or_1_1 = LooseVersion ( version ) >= LooseVersion ( '<STR_LIT>' ) <EOL> version_gte_3_1_1_or_1_1_1 = LooseVersion ( version ) >= LooseVersion ( '<STR_LIT>' ) <EOL> version_gte_3_2_or_1_2 = LooseVersion ( version ) >= LooseVersion ( '<STR_LIT>' ) <EOL> else : <EOL> version_gte_3_1_or_1_1 = True <EOL> version_gte_3_1_1_or_1_1_1 = True <EOL> version_gte_3_2_or_1_2 = True <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = version_gte_3_1_or_1_1 <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = version_gte_3_1_1_or_1_1_1 <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = version_gte_3_2_or_1_2 <EOL> if version_gte_3_2_or_1_2 : <EOL> examples_content_version = '<STR_LIT>' <EOL> elif version_gte_3_1_or_1_1 : <EOL> examples_content_version = '<STR_LIT>' <EOL> else : <EOL> examples_content_version = '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = examples_content_version <EOL> return facts <EOL> def set_manageiq_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> raise OpenShiftFactsInternalError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return facts <EOL> def set_sdn_facts_if_unset ( facts , system_facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> use_sdn = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if not ( use_sdn == '<STR_LIT>' or isinstance ( use_sdn , bool ) ) : <EOL> use_sdn = safe_get_bool ( use_sdn ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = use_sdn <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> plugin = '<STR_LIT>' if use_sdn else '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = plugin <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> node_ip = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> for val in system_facts . itervalues ( ) : <EOL> if isinstance ( val , dict ) and '<STR_LIT>' in val : <EOL> mtu = val [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in val and val [ '<STR_LIT>' ] . get ( '<STR_LIT:address>' ) == node_ip : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = str ( mtu - <NUM_LIT:50> ) <EOL> return facts <EOL> def migrate_oauth_template_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { "<STR_LIT>" : facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] } <EOL> elif '<STR_LIT>' not in facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return facts <EOL> def format_url ( use_ssl , hostname , port , path = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> scheme = '<STR_LIT>' if use_ssl else '<STR_LIT:http>' <EOL> netloc = hostname <EOL> if ( use_ssl and port != '<STR_LIT>' ) or ( not use_ssl and port != '<STR_LIT>' ) : <EOL> netloc += "<STR_LIT>" % port <EOL> return urlparse . urlunparse ( ( scheme , netloc , path , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def get_current_config ( facts ) : <EOL> """<STR_LIT>""" <EOL> current_config = dict ( ) <EOL> roles = [ role for role in facts if role not in [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> for role in roles : <EOL> if '<STR_LIT>' in current_config : <EOL> current_config [ '<STR_LIT>' ] . append ( role ) <EOL> else : <EOL> current_config [ '<STR_LIT>' ] = [ role ] <EOL> kubeconfig_dir = '<STR_LIT>' <EOL> if role == '<STR_LIT>' : <EOL> kubeconfig_dir = os . path . join ( <EOL> kubeconfig_dir , "<STR_LIT>" % facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> ) <EOL> kubeconfig_path = os . path . join ( kubeconfig_dir , '<STR_LIT>' ) <EOL> if ( os . path . isfile ( '<STR_LIT>' ) <EOL> and os . path . isfile ( kubeconfig_path ) ) : <EOL> try : <EOL> _ , output , _ = module . run_command ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" % kubeconfig_path ] , <EOL> check_rc = False <EOL> ) <EOL> config = json . loads ( output ) <EOL> cad = '<STR_LIT>' <EOL> try : <EOL> for cluster in config [ '<STR_LIT>' ] : <EOL> config [ '<STR_LIT>' ] [ cluster ] [ cad ] = '<STR_LIT>' <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> for user in config [ '<STR_LIT>' ] : <EOL> config [ '<STR_LIT>' ] [ user ] [ cad ] = '<STR_LIT>' <EOL> config [ '<STR_LIT>' ] [ user ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> except KeyError : <EOL> pass <EOL> current_config [ '<STR_LIT>' ] = config <EOL> except Exception : <EOL> pass <EOL> return current_config <EOL> def build_kubelet_args ( facts ) : <EOL> """<STR_LIT>""" <EOL> cloud_cfg_path = os . path . join ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' in facts : <EOL> kubelet_args = { } <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> kubelet_args [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> kubelet_args [ '<STR_LIT>' ] = [ cloud_cfg_path + '<STR_LIT>' ] <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> kubelet_args [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> kubelet_args [ '<STR_LIT>' ] = [ cloud_cfg_path + '<STR_LIT>' ] <EOL> if kubelet_args != { } : <EOL> facts = merge_facts ( { '<STR_LIT>' : { '<STR_LIT>' : kubelet_args } } , facts , [ ] , [ ] ) <EOL> return facts <EOL> def build_controller_args ( facts ) : <EOL> """<STR_LIT>""" <EOL> cloud_cfg_path = os . path . join ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' in facts : <EOL> controller_args = { } <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> controller_args [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> controller_args [ '<STR_LIT>' ] = [ cloud_cfg_path + '<STR_LIT>' ] <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> controller_args [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> controller_args [ '<STR_LIT>' ] = [ cloud_cfg_path + '<STR_LIT>' ] <EOL> if controller_args != { } : <EOL> facts = merge_facts ( { '<STR_LIT>' : { '<STR_LIT>' : controller_args } } , facts , [ ] , [ ] ) <EOL> return facts <EOL> def build_api_server_args ( facts ) : <EOL> """<STR_LIT>""" <EOL> cloud_cfg_path = os . path . join ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' in facts : <EOL> api_server_args = { } <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> api_server_args [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> api_server_args [ '<STR_LIT>' ] = [ cloud_cfg_path + '<STR_LIT>' ] <EOL> if facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> api_server_args [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> api_server_args [ '<STR_LIT>' ] = [ cloud_cfg_path + '<STR_LIT>' ] <EOL> if api_server_args != { } : <EOL> facts = merge_facts ( { '<STR_LIT>' : { '<STR_LIT>' : api_server_args } } , facts , [ ] , [ ] ) <EOL> return facts <EOL> def is_service_running ( service ) : <EOL> """<STR_LIT>""" <EOL> service_running = False <EOL> bus = SystemBus ( ) <EOL> systemd = bus . get_object ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> manager = Interface ( systemd , dbus_interface = '<STR_LIT>' ) <EOL> try : <EOL> service_unit = service if service . endswith ( '<STR_LIT>' ) else manager . GetUnit ( '<STR_LIT>' . format ( service ) ) <EOL> service_proxy = bus . get_object ( '<STR_LIT>' , str ( service_unit ) ) <EOL> service_properties = Interface ( service_proxy , dbus_interface = '<STR_LIT>' ) <EOL> service_load_state = service_properties . Get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> service_active_state = service_properties . Get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if service_load_state == '<STR_LIT>' and service_active_state == '<STR_LIT>' : <EOL> service_running = True <EOL> except DBusException : <EOL> pass <EOL> return service_running <EOL> def get_version_output ( binary , version_cmd ) : <EOL> """<STR_LIT>""" <EOL> cmd = [ ] <EOL> for item in ( binary , version_cmd ) : <EOL> if isinstance ( item , list ) : <EOL> cmd . extend ( item ) <EOL> else : <EOL> cmd . append ( item ) <EOL> if os . path . isfile ( cmd [ <NUM_LIT:0> ] ) : <EOL> _ , output , _ = module . run_command ( cmd ) <EOL> return output <EOL> def get_docker_version_info ( ) : <EOL> """<STR_LIT>""" <EOL> result = None <EOL> if is_service_running ( '<STR_LIT>' ) : <EOL> version_info = yaml . safe_load ( get_version_output ( '<STR_LIT>' , '<STR_LIT:version>' ) ) <EOL> if '<STR_LIT>' in version_info : <EOL> result = { <EOL> '<STR_LIT>' : version_info [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT:version>' : version_info [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> } <EOL> return result <EOL> def get_openshift_version ( facts ) : <EOL> """<STR_LIT>""" <EOL> version = None <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT:version>' in facts [ '<STR_LIT>' ] and facts [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] is not None : <EOL> return facts [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] <EOL> if os . path . isfile ( '<STR_LIT>' ) : <EOL> _ , output , _ = module . run_command ( [ '<STR_LIT>' , '<STR_LIT:version>' ] ) <EOL> version = parse_openshift_version ( output ) <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] and safe_get_bool ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> version = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return version <EOL> def parse_openshift_version ( output ) : <EOL> """<STR_LIT>""" <EOL> versions = dict ( e . split ( '<STR_LIT>' ) for e in output . splitlines ( ) if '<STR_LIT>' in e ) <EOL> return versions . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def apply_provider_facts ( facts , provider_facts ) : <EOL> """<STR_LIT>""" <EOL> if not provider_facts : <EOL> return facts <EOL> common_vars = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> for h_var , ip_var in common_vars : <EOL> ip_value = provider_facts [ '<STR_LIT>' ] . get ( ip_var ) <EOL> if ip_value : <EOL> facts [ '<STR_LIT>' ] [ ip_var ] = ip_value <EOL> facts [ '<STR_LIT>' ] [ h_var ] = choose_hostname ( <EOL> [ provider_facts [ '<STR_LIT>' ] . get ( h_var ) ] , <EOL> facts [ '<STR_LIT>' ] [ ip_var ] <EOL> ) <EOL> facts [ '<STR_LIT>' ] = provider_facts <EOL> return facts <EOL> def merge_facts ( orig , new , additive_facts_to_overwrite , protected_facts_to_overwrite ) : <EOL> """<STR_LIT>""" <EOL> additive_facts = [ '<STR_LIT>' ] <EOL> protected_facts = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> inventory_json_facts = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> facts = dict ( ) <EOL> for key , value in orig . iteritems ( ) : <EOL> if key in new : <EOL> if key in inventory_json_facts : <EOL> if isinstance ( new [ key ] , basestring ) : <EOL> facts [ key ] = yaml . safe_load ( new [ key ] ) <EOL> else : <EOL> facts [ key ] = copy . deepcopy ( new [ key ] ) <EOL> elif isinstance ( value , dict ) and isinstance ( new [ key ] , dict ) : <EOL> relevant_additive_facts = [ ] <EOL> for item in additive_facts_to_overwrite : <EOL> if '<STR_LIT:.>' in item and item . startswith ( key + '<STR_LIT:.>' ) : <EOL> relevant_additive_facts . append ( item ) <EOL> relevant_protected_facts = [ ] <EOL> for item in protected_facts_to_overwrite : <EOL> if '<STR_LIT:.>' in item and item . startswith ( key + '<STR_LIT:.>' ) : <EOL> relevant_protected_facts . append ( item ) <EOL> facts [ key ] = merge_facts ( value , new [ key ] , relevant_additive_facts , relevant_protected_facts ) <EOL> elif key in additive_facts and key not in [ x . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] for x in additive_facts_to_overwrite ] : <EOL> if isinstance ( value , list ) and isinstance ( new [ key ] , list ) : <EOL> new_fact = [ ] <EOL> for item in copy . deepcopy ( value ) + copy . deepcopy ( new [ key ] ) : <EOL> if item not in new_fact : <EOL> new_fact . append ( item ) <EOL> facts [ key ] = new_fact <EOL> elif key in protected_facts and key not in [ x . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] for x in protected_facts_to_overwrite ] : <EOL> if key == '<STR_LIT>' : <EOL> if int ( value ) <= int ( new [ key ] ) : <EOL> facts [ key ] = copy . deepcopy ( new [ key ] ) <EOL> else : <EOL> module . fail_json ( msg = '<STR_LIT>' ) <EOL> if key == '<STR_LIT>' : <EOL> if safe_get_bool ( value ) != safe_get_bool ( new [ key ] ) : <EOL> module . fail_json ( msg = '<STR_LIT>' ) <EOL> else : <EOL> facts [ key ] = value <EOL> else : <EOL> facts [ key ] = copy . deepcopy ( new [ key ] ) <EOL> else : <EOL> facts [ key ] = copy . deepcopy ( value ) <EOL> new_keys = set ( new . keys ( ) ) - set ( orig . keys ( ) ) <EOL> for key in new_keys : <EOL> if key in inventory_json_facts and isinstance ( new [ key ] , basestring ) : <EOL> facts [ key ] = yaml . safe_load ( new [ key ] ) <EOL> else : <EOL> facts [ key ] = copy . deepcopy ( new [ key ] ) <EOL> return facts <EOL> def save_local_facts ( filename , facts ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> fact_dir = os . path . dirname ( filename ) <EOL> if not os . path . exists ( fact_dir ) : <EOL> os . makedirs ( fact_dir ) <EOL> with open ( filename , '<STR_LIT:w>' ) as fact_file : <EOL> fact_file . write ( module . jsonify ( facts ) ) <EOL> os . chmod ( filename , <NUM_LIT> ) <EOL> except ( IOError , OSError ) as ex : <EOL> raise OpenShiftFactsFileWriteError ( <EOL> "<STR_LIT>" % ( filename , ex ) <EOL> ) <EOL> def get_local_facts_from_file ( filename ) : <EOL> """<STR_LIT>""" <EOL> local_facts = dict ( ) <EOL> try : <EOL> ini_facts = ConfigParser . SafeConfigParser ( ) <EOL> ini_facts . read ( filename ) <EOL> for section in ini_facts . sections ( ) : <EOL> local_facts [ section ] = dict ( ) <EOL> for key , value in ini_facts . items ( section ) : <EOL> local_facts [ section ] [ key ] = value <EOL> except ( ConfigParser . MissingSectionHeaderError , <EOL> ConfigParser . ParsingError ) : <EOL> try : <EOL> with open ( filename , '<STR_LIT:r>' ) as facts_file : <EOL> local_facts = json . load ( facts_file ) <EOL> except ( ValueError , IOError ) : <EOL> pass <EOL> return local_facts <EOL> def sort_unique ( alist ) : <EOL> """<STR_LIT>""" <EOL> alist . sort ( ) <EOL> out = list ( ) <EOL> for i in alist : <EOL> if i not in out : <EOL> out . append ( i ) <EOL> return out <EOL> def safe_get_bool ( fact ) : <EOL> """<STR_LIT>""" <EOL> return bool ( strtobool ( str ( fact ) ) ) <EOL> def set_proxy_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> common = facts [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in common or '<STR_LIT>' in common : <EOL> if '<STR_LIT>' in common and common [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in common and isinstance ( common [ '<STR_LIT>' ] , basestring ) : <EOL> common [ '<STR_LIT>' ] = common [ '<STR_LIT>' ] . split ( "<STR_LIT:U+002C>" ) <EOL> else : <EOL> common [ '<STR_LIT>' ] = [ ] <EOL> if '<STR_LIT>' in common : <EOL> common [ '<STR_LIT>' ] . extend ( common [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> common [ '<STR_LIT>' ] . append ( '<STR_LIT:.>' + common [ '<STR_LIT>' ] ) <EOL> common [ '<STR_LIT>' ] . append ( common [ '<STR_LIT>' ] ) <EOL> common [ '<STR_LIT>' ] = sort_unique ( common [ '<STR_LIT>' ] ) <EOL> facts [ '<STR_LIT>' ] = common <EOL> if '<STR_LIT>' in facts : <EOL> builddefaults = facts [ '<STR_LIT>' ] <EOL> common = facts [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in builddefaults and '<STR_LIT>' in common : <EOL> builddefaults [ '<STR_LIT>' ] = common [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in builddefaults and '<STR_LIT>' in common : <EOL> builddefaults [ '<STR_LIT>' ] = common [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in builddefaults and '<STR_LIT>' in common : <EOL> builddefaults [ '<STR_LIT>' ] = common [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in builddefaults and '<STR_LIT>' in builddefaults : <EOL> builddefaults [ '<STR_LIT>' ] = builddefaults [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in builddefaults and '<STR_LIT>' in builddefaults : <EOL> builddefaults [ '<STR_LIT>' ] = builddefaults [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = dict ( ) <EOL> if '<STR_LIT>' in builddefaults and ( '<STR_LIT>' in builddefaults or '<STR_LIT>' in builddefaults ) : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] . update ( builddefaults [ '<STR_LIT>' ] ) <EOL> facts [ '<STR_LIT>' ] = builddefaults <EOL> return facts <EOL> def set_container_facts_if_unset ( facts ) : <EOL> """<STR_LIT>""" <EOL> deployment_type = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if deployment_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> master_image = '<STR_LIT>' <EOL> cli_image = master_image <EOL> node_image = '<STR_LIT>' <EOL> ovs_image = '<STR_LIT>' <EOL> etcd_image = '<STR_LIT>' <EOL> pod_image = '<STR_LIT>' <EOL> router_image = '<STR_LIT>' <EOL> registry_image = '<STR_LIT>' <EOL> deployer_image = '<STR_LIT>' <EOL> elif deployment_type == '<STR_LIT>' : <EOL> master_image = '<STR_LIT>' <EOL> cli_image = master_image <EOL> node_image = '<STR_LIT>' <EOL> ovs_image = '<STR_LIT>' <EOL> etcd_image = '<STR_LIT>' <EOL> pod_image = '<STR_LIT>' <EOL> router_image = '<STR_LIT>' <EOL> registry_image = '<STR_LIT>' <EOL> deployer_image = '<STR_LIT>' <EOL> else : <EOL> master_image = '<STR_LIT>' <EOL> cli_image = master_image <EOL> node_image = '<STR_LIT>' <EOL> ovs_image = '<STR_LIT>' <EOL> etcd_image = '<STR_LIT>' <EOL> pod_image = '<STR_LIT>' <EOL> router_image = '<STR_LIT>' <EOL> registry_image = '<STR_LIT>' <EOL> deployer_image = '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = os . path . isfile ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = cli_image <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = pod_image <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = router_image <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = registry_image <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = deployer_image <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = etcd_image <EOL> if '<STR_LIT>' in facts and '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = master_image <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = node_image <EOL> if '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = ovs_image <EOL> if safe_get_bool ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return facts <EOL> def set_installed_variant_rpm_facts ( facts ) : <EOL> """<STR_LIT>""" <EOL> installed_rpms = [ ] <EOL> for base_rpm in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> optional_rpms = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> variant_rpms = [ base_rpm ] + [ '<STR_LIT>' . format ( base_rpm , r ) for r in optional_rpms ] + [ '<STR_LIT>' % base_rpm ] <EOL> for rpm in variant_rpms : <EOL> exit_code , _ , _ = module . run_command ( [ '<STR_LIT>' , '<STR_LIT>' , rpm ] ) <EOL> if exit_code == <NUM_LIT:0> : <EOL> installed_rpms . append ( rpm ) <EOL> facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = installed_rpms <EOL> return facts <EOL> class OpenShiftFactsInternalError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class OpenShiftFactsUnsupportedRoleError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class OpenShiftFactsFileWriteError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class OpenShiftFactsMetadataUnavailableError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class OpenShiftFacts ( object ) : <EOL> """<STR_LIT>""" <EOL> known_roles = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def __init__ ( self , role , filename , local_facts , <EOL> additive_facts_to_overwrite = None , <EOL> openshift_env = None , <EOL> openshift_env_structures = None , <EOL> protected_facts_to_overwrite = None ) : <EOL> self . changed = False <EOL> self . filename = filename <EOL> if role not in self . known_roles : <EOL> raise OpenShiftFactsUnsupportedRoleError ( <EOL> "<STR_LIT>" % role <EOL> ) <EOL> self . role = role <EOL> self . system_facts = ansible_facts ( module ) <EOL> self . facts = self . generate_facts ( local_facts , <EOL> additive_facts_to_overwrite , <EOL> openshift_env , <EOL> openshift_env_structures , <EOL> protected_facts_to_overwrite ) <EOL> def generate_facts ( self , <EOL> local_facts , <EOL> additive_facts_to_overwrite , <EOL> openshift_env , <EOL> openshift_env_structures , <EOL> protected_facts_to_overwrite ) : <EOL> """<STR_LIT>""" <EOL> local_facts = self . init_local_facts ( local_facts , <EOL> additive_facts_to_overwrite , <EOL> openshift_env , <EOL> openshift_env_structures , <EOL> protected_facts_to_overwrite ) <EOL> roles = local_facts . keys ( ) <EOL> if '<STR_LIT>' in local_facts and '<STR_LIT>' in local_facts [ '<STR_LIT>' ] : <EOL> deployment_type = local_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> deployment_type = '<STR_LIT>' <EOL> defaults = self . get_defaults ( roles , deployment_type ) <EOL> provider_facts = self . init_provider_facts ( ) <EOL> facts = apply_provider_facts ( defaults , provider_facts ) <EOL> facts = merge_facts ( facts , <EOL> local_facts , <EOL> additive_facts_to_overwrite , <EOL> protected_facts_to_overwrite ) <EOL> facts = migrate_oauth_template_facts ( facts ) <EOL> facts [ '<STR_LIT>' ] = get_current_config ( facts ) <EOL> facts = set_url_facts_if_unset ( facts ) <EOL> facts = set_project_cfg_facts_if_unset ( facts ) <EOL> facts = set_flannel_facts_if_unset ( facts ) <EOL> facts = set_nuage_facts_if_unset ( facts ) <EOL> facts = set_node_schedulability ( facts ) <EOL> facts = set_selectors ( facts ) <EOL> facts = set_metrics_facts_if_unset ( facts ) <EOL> facts = set_identity_providers_if_unset ( facts ) <EOL> facts = set_sdn_facts_if_unset ( facts , self . system_facts ) <EOL> facts = set_deployment_facts_if_unset ( facts ) <EOL> facts = set_container_facts_if_unset ( facts ) <EOL> facts = build_kubelet_args ( facts ) <EOL> facts = build_controller_args ( facts ) <EOL> facts = build_api_server_args ( facts ) <EOL> facts = set_version_facts_if_unset ( facts ) <EOL> facts = set_dnsmasq_facts_if_unset ( facts ) <EOL> facts = set_manageiq_facts_if_unset ( facts ) <EOL> facts = set_aggregate_facts ( facts ) <EOL> facts = set_etcd_facts_if_unset ( facts ) <EOL> facts = set_proxy_facts ( facts ) <EOL> if not safe_get_bool ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> facts = set_installed_variant_rpm_facts ( facts ) <EOL> return dict ( openshift = facts ) <EOL> def get_defaults ( self , roles , deployment_type ) : <EOL> """<STR_LIT>""" <EOL> defaults = { } <EOL> ip_addr = self . system_facts [ '<STR_LIT>' ] [ '<STR_LIT:address>' ] <EOL> exit_code , output , _ = module . run_command ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> hostname_f = output . strip ( ) if exit_code == <NUM_LIT:0> else '<STR_LIT>' <EOL> hostname_values = [ hostname_f , self . system_facts [ '<STR_LIT>' ] , <EOL> self . system_facts [ '<STR_LIT>' ] ] <EOL> hostname = choose_hostname ( hostname_values , ip_addr ) <EOL> defaults [ '<STR_LIT>' ] = dict ( use_openshift_sdn = True , ip = ip_addr , <EOL> public_ip = ip_addr , <EOL> deployment_type = deployment_type , <EOL> hostname = hostname , <EOL> public_hostname = hostname , <EOL> portal_net = '<STR_LIT>' , <EOL> client_binary = '<STR_LIT>' , admin_binary = '<STR_LIT>' , <EOL> dns_domain = '<STR_LIT>' , <EOL> install_examples = True , <EOL> debug_level = <NUM_LIT:2> ) <EOL> if '<STR_LIT>' in roles : <EOL> scheduler_predicates = [ <EOL> { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : [ "<STR_LIT>" ] } } } <EOL> ] <EOL> scheduler_priorities = [ <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:1> } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:1> } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:2> , "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT:label>" : "<STR_LIT>" } } } <EOL> ] <EOL> defaults [ '<STR_LIT>' ] = dict ( api_use_ssl = True , api_port = '<STR_LIT>' , <EOL> controllers_port = '<STR_LIT>' , <EOL> console_use_ssl = True , <EOL> console_path = '<STR_LIT>' , <EOL> console_port = '<STR_LIT>' , etcd_use_ssl = True , <EOL> etcd_hosts = '<STR_LIT>' , etcd_port = '<STR_LIT>' , <EOL> portal_net = '<STR_LIT>' , <EOL> embedded_etcd = True , embedded_kube = True , <EOL> embedded_dns = True , <EOL> bind_addr = '<STR_LIT>' , <EOL> session_max_seconds = <NUM_LIT> , <EOL> session_name = '<STR_LIT>' , <EOL> session_secrets_file = '<STR_LIT>' , <EOL> access_token_max_seconds = <NUM_LIT> , <EOL> auth_token_max_seconds = <NUM_LIT> , <EOL> oauth_grant_method = '<STR_LIT>' , <EOL> scheduler_predicates = scheduler_predicates , <EOL> scheduler_priorities = scheduler_priorities , <EOL> dynamic_provisioning_enabled = True ) <EOL> if '<STR_LIT>' in roles : <EOL> defaults [ '<STR_LIT>' ] = dict ( labels = { } , annotations = { } , <EOL> iptables_sync_period = '<STR_LIT>' , <EOL> local_quota_per_fsgroup = "<STR_LIT>" , <EOL> set_node_ip = False ) <EOL> if '<STR_LIT>' in roles : <EOL> docker = dict ( disable_push_dockerhub = False ) <EOL> version_info = get_docker_version_info ( ) <EOL> if version_info is not None : <EOL> docker [ '<STR_LIT>' ] = version_info [ '<STR_LIT>' ] <EOL> docker [ '<STR_LIT:version>' ] = version_info [ '<STR_LIT:version>' ] <EOL> defaults [ '<STR_LIT>' ] = docker <EOL> if '<STR_LIT>' in roles : <EOL> defaults [ '<STR_LIT>' ] = dict ( kind = None ) <EOL> if '<STR_LIT>' in roles or self . role == '<STR_LIT>' : <EOL> defaults [ '<STR_LIT>' ] = dict ( <EOL> metrics = dict ( <EOL> deploy = False , <EOL> duration = <NUM_LIT:7> , <EOL> resolution = <NUM_LIT:10> , <EOL> storage = dict ( <EOL> kind = None , <EOL> volume = dict ( <EOL> name = '<STR_LIT>' , <EOL> size = '<STR_LIT>' <EOL> ) , <EOL> nfs = dict ( <EOL> directory = '<STR_LIT>' , <EOL> options = '<STR_LIT>' ) , <EOL> host = None , <EOL> access_modes = [ '<STR_LIT>' ] , <EOL> create_pv = True <EOL> ) <EOL> ) , <EOL> registry = dict ( <EOL> storage = dict ( <EOL> kind = None , <EOL> volume = dict ( <EOL> name = '<STR_LIT>' , <EOL> size = '<STR_LIT>' <EOL> ) , <EOL> nfs = dict ( <EOL> directory = '<STR_LIT>' , <EOL> options = '<STR_LIT>' ) , <EOL> host = None , <EOL> access_modes = [ '<STR_LIT>' ] , <EOL> create_pv = True <EOL> ) <EOL> ) , <EOL> router = dict ( ) <EOL> ) <EOL> return defaults <EOL> def guess_host_provider ( self ) : <EOL> """<STR_LIT>""" <EOL> product_name = self . system_facts [ '<STR_LIT>' ] <EOL> product_version = self . system_facts [ '<STR_LIT>' ] <EOL> virt_type = self . system_facts [ '<STR_LIT>' ] <EOL> virt_role = self . system_facts [ '<STR_LIT>' ] <EOL> provider = None <EOL> metadata = None <EOL> bios_vendor = get_file_content ( <EOL> '<STR_LIT>' <EOL> ) <EOL> if bios_vendor == '<STR_LIT>' : <EOL> provider = '<STR_LIT>' <EOL> metadata_url = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } <EOL> metadata = get_provider_metadata ( metadata_url , True , headers , <EOL> True ) <EOL> if metadata : <EOL> metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] . pop ( '<STR_LIT>' , None ) <EOL> metadata [ '<STR_LIT>' ] . pop ( '<STR_LIT>' , None ) <EOL> elif ( virt_type == '<STR_LIT>' and virt_role == '<STR_LIT>' <EOL> and re . match ( r'<STR_LIT>' , product_version ) ) : <EOL> provider = '<STR_LIT>' <EOL> metadata_url = '<STR_LIT>' <EOL> metadata = get_provider_metadata ( metadata_url ) <EOL> elif re . search ( r'<STR_LIT>' , product_name ) : <EOL> provider = '<STR_LIT>' <EOL> metadata_url = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> metadata = get_provider_metadata ( metadata_url , True , None , <EOL> True ) <EOL> if metadata : <EOL> ec2_compat_url = '<STR_LIT>' <EOL> metadata [ '<STR_LIT>' ] = get_provider_metadata ( <EOL> ec2_compat_url <EOL> ) <EOL> metadata . pop ( '<STR_LIT>' , None ) <EOL> metadata . pop ( '<STR_LIT>' , None ) <EOL> if not metadata [ '<STR_LIT>' ] : <EOL> metadata = None <EOL> return dict ( name = provider , metadata = metadata ) <EOL> def init_provider_facts ( self ) : <EOL> """<STR_LIT>""" <EOL> provider_info = self . guess_host_provider ( ) <EOL> provider_facts = normalize_provider_facts ( <EOL> provider_info . get ( '<STR_LIT:name>' ) , <EOL> provider_info . get ( '<STR_LIT>' ) <EOL> ) <EOL> return provider_facts <EOL> @ staticmethod <EOL> def split_openshift_env_fact_keys ( openshift_env_fact , openshift_env_structures ) : <EOL> """<STR_LIT>""" <EOL> fact_keys = openshift_env_fact . split ( '<STR_LIT:_>' ) <EOL> matching_structure = None <EOL> if openshift_env_structures != None : <EOL> for structure in openshift_env_structures : <EOL> if re . match ( structure , openshift_env_fact ) : <EOL> matching_structure = structure <EOL> if matching_structure is None : <EOL> return fact_keys <EOL> final_keys = [ ] <EOL> structure_keys = matching_structure . split ( '<STR_LIT:.>' ) <EOL> for structure_key in structure_keys : <EOL> if structure_key == fact_keys [ structure_keys . index ( structure_key ) ] : <EOL> final_keys . append ( structure_key ) <EOL> elif structure_key == '<STR_LIT:*>' : <EOL> final_keys . append ( '<STR_LIT:_>' . join ( fact_keys [ structure_keys . index ( structure_key ) : ] ) ) <EOL> else : <EOL> return fact_keys <EOL> return final_keys <EOL> def init_local_facts ( self , facts = None , <EOL> additive_facts_to_overwrite = None , <EOL> openshift_env = None , <EOL> openshift_env_structures = None , <EOL> protected_facts_to_overwrite = None ) : <EOL> """<STR_LIT>""" <EOL> changed = False <EOL> facts_to_set = dict ( ) <EOL> if facts is not None : <EOL> facts_to_set [ self . role ] = facts <EOL> if openshift_env != { } and openshift_env != None : <EOL> for fact , value in openshift_env . iteritems ( ) : <EOL> oo_env_facts = dict ( ) <EOL> current_level = oo_env_facts <EOL> keys = self . split_openshift_env_fact_keys ( fact , openshift_env_structures ) [ <NUM_LIT:1> : ] <EOL> if len ( keys ) > <NUM_LIT:0> and keys [ <NUM_LIT:0> ] != self . role : <EOL> continue <EOL> for key in keys : <EOL> if key == keys [ - <NUM_LIT:1> ] : <EOL> current_level [ key ] = value <EOL> elif key not in current_level : <EOL> current_level [ key ] = dict ( ) <EOL> current_level = current_level [ key ] <EOL> facts_to_set = merge_facts ( orig = facts_to_set , <EOL> new = oo_env_facts , <EOL> additive_facts_to_overwrite = [ ] , <EOL> protected_facts_to_overwrite = [ ] ) <EOL> local_facts = get_local_facts_from_file ( self . filename ) <EOL> migrated_facts = migrate_local_facts ( local_facts ) <EOL> new_local_facts = merge_facts ( migrated_facts , <EOL> facts_to_set , <EOL> additive_facts_to_overwrite , <EOL> protected_facts_to_overwrite ) <EOL> if '<STR_LIT>' in new_local_facts : <EOL> for cat in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> key = '<STR_LIT>' . format ( cat ) <EOL> if key in new_local_facts [ '<STR_LIT>' ] : <EOL> val = new_local_facts [ '<STR_LIT>' ] [ key ] <EOL> if isinstance ( val , basestring ) : <EOL> val = [ x . strip ( ) for x in val . split ( '<STR_LIT:U+002C>' ) ] <EOL> new_local_facts [ '<STR_LIT>' ] [ key ] = list ( set ( val ) - set ( [ '<STR_LIT>' ] ) ) <EOL> if '<STR_LIT>' in new_local_facts [ '<STR_LIT>' ] and isinstance ( new_local_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , basestring ) : <EOL> new_local_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] = new_local_facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) <EOL> new_local_facts = self . remove_empty_facts ( new_local_facts ) <EOL> if new_local_facts != local_facts : <EOL> self . validate_local_facts ( new_local_facts ) <EOL> changed = True <EOL> if not module . check_mode : <EOL> save_local_facts ( self . filename , new_local_facts ) <EOL> self . changed = changed <EOL> return new_local_facts <EOL> def remove_empty_facts ( self , facts = None ) : <EOL> """<STR_LIT>""" <EOL> facts_to_remove = [ ] <EOL> for fact , value in facts . iteritems ( ) : <EOL> if isinstance ( facts [ fact ] , dict ) : <EOL> facts [ fact ] = self . remove_empty_facts ( facts [ fact ] ) <EOL> else : <EOL> if value == "<STR_LIT>" or value == [ "<STR_LIT>" ] or value is None : <EOL> facts_to_remove . append ( fact ) <EOL> for fact in facts_to_remove : <EOL> del facts [ fact ] <EOL> return facts <EOL> def validate_local_facts ( self , facts = None ) : <EOL> """<STR_LIT>""" <EOL> invalid_facts = dict ( ) <EOL> invalid_facts = self . validate_master_facts ( facts , invalid_facts ) <EOL> if invalid_facts : <EOL> msg = '<STR_LIT>' <EOL> for key in invalid_facts . keys ( ) : <EOL> msg += '<STR_LIT>' . format ( key , invalid_facts [ key ] ) <EOL> module . fail_json ( msg = msg , <EOL> changed = self . changed ) <EOL> @ staticmethod <EOL> def validate_master_facts ( facts , invalid_facts ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in facts : <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> session_auth_secrets = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if not issubclass ( type ( session_auth_secrets ) , list ) : <EOL> invalid_facts [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> invalid_facts [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif len ( session_auth_secrets ) != len ( facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> invalid_facts [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> for secret in session_auth_secrets : <EOL> if len ( secret ) < <NUM_LIT:32> : <EOL> invalid_facts [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' in facts [ '<STR_LIT>' ] : <EOL> session_encryption_secrets = facts [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if not issubclass ( type ( session_encryption_secrets ) , list ) : <EOL> invalid_facts [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif '<STR_LIT>' not in facts [ '<STR_LIT>' ] : <EOL> invalid_facts [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> for secret in session_encryption_secrets : <EOL> if len ( secret ) not in [ <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT:32> ] : <EOL> invalid_facts [ '<STR_LIT>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return invalid_facts <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> global module <EOL> module = AnsibleModule ( <EOL> argument_spec = dict ( <EOL> role = dict ( default = '<STR_LIT>' , required = False , <EOL> choices = OpenShiftFacts . known_roles ) , <EOL> local_facts = dict ( default = None , type = '<STR_LIT>' , required = False ) , <EOL> additive_facts_to_overwrite = dict ( default = [ ] , type = '<STR_LIT:list>' , required = False ) , <EOL> openshift_env = dict ( default = { } , type = '<STR_LIT>' , required = False ) , <EOL> openshift_env_structures = dict ( default = [ ] , type = '<STR_LIT:list>' , required = False ) , <EOL> protected_facts_to_overwrite = dict ( default = [ ] , type = '<STR_LIT:list>' , required = False ) , <EOL> ) , <EOL> supports_check_mode = True , <EOL> add_file_common_args = True , <EOL> ) <EOL> role = module . params [ '<STR_LIT>' ] <EOL> local_facts = module . params [ '<STR_LIT>' ] <EOL> additive_facts_to_overwrite = module . params [ '<STR_LIT>' ] <EOL> openshift_env = module . params [ '<STR_LIT>' ] <EOL> openshift_env_structures = module . params [ '<STR_LIT>' ] <EOL> protected_facts_to_overwrite = module . params [ '<STR_LIT>' ] <EOL> fact_file = '<STR_LIT>' <EOL> openshift_facts = OpenShiftFacts ( role , <EOL> fact_file , <EOL> local_facts , <EOL> additive_facts_to_overwrite , <EOL> openshift_env , <EOL> openshift_env_structures , <EOL> protected_facts_to_overwrite ) <EOL> file_params = module . params . copy ( ) <EOL> file_params [ '<STR_LIT:path>' ] = fact_file <EOL> file_args = module . load_file_common_arguments ( file_params ) <EOL> changed = module . set_fs_attributes_if_different ( file_args , <EOL> openshift_facts . changed ) <EOL> return module . exit_json ( changed = changed , <EOL> ansible_facts = openshift_facts . facts ) <EOL> from ansible . module_utils . basic import * <EOL> from ansible . module_utils . facts import * <EOL> from ansible . module_utils . urls import * <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
