def normalize_openstack_facts(metadata, facts):
 facts['zone'] = metadata['availability_zone']
 local_ipv4 = metadata['ec2_compat']['local-ipv4'].split(',')[0]
 facts['network']['ip'] = local_ipv4
 facts['network']['public_ip'] = metadata['ec2_compat']['public-ipv4']
 for (f_var, h_var, ip_var) in [('hostname', 'hostname', 'local-ipv4'), ('public_hostname', 'public-hostname', 'public-ipv4')]:
  try:
   if (socket.gethostbyname(metadata['ec2_compat'][h_var]) == metadata['ec2_compat'][ip_var]):
    facts['network'][f_var] = metadata['ec2_compat'][h_var]
   else:
    facts['network'][f_var] = metadata['ec2_compat'][ip_var]
  except socket.gaierror:
   facts['network'][f_var] = metadata['ec2_compat'][ip_var]
 return facts

def normalize_openstack_facts ( metadata , facts ) : facts [ 'zone' ] = metadata [ 'availability_zone' ] local_ipv4 = metadata [ 'ec2_compat' ] [ 'local-ipv4' ] . split ( ',' ) [ 0 ] facts [ 'network' ] [ 'ip' ] = local_ipv4 facts [ 'network' ] [ 'public_ip' ] = metadata [ 'ec2_compat' ] [ 'public-ipv4' ] for ( f_var , h_var , ip_var ) in [ ( 'hostname' , 'hostname' , 'local-ipv4' ) , ( 'public_hostname' , 'public-hostname' , 'public-ipv4' ) ] : try : if ( socket . gethostbyname ( metadata [ 'ec2_compat' ] [ h_var ] ) == metadata [ 'ec2_compat' ] [ ip_var ] ) : facts [ 'network' ] [ f_var ] = metadata [ 'ec2_compat' ] [ h_var ] else : facts [ 'network' ] [ f_var ] = metadata [ 'ec2_compat' ] [ ip_var ] except socket . gaierror : facts [ 'network' ] [ f_var ] = metadata [ 'ec2_compat' ] [ ip_var ] return facts
normalize openstack facts args: metadata : provider metadata facts : facts to update returns: dict: the result of adding the normalized metadata to the provided facts dict .