def normalize_aws_facts(metadata, facts):
 for interface in sorted(metadata['network']['interfaces']['macs'].values(), key=(lambda x: x['device-number'])):
  int_info = dict()
  var_map = {'ips': 'local-ipv4s', 'public_ips': 'public-ipv4s'}
  for (ips_var, int_var) in iteritems(var_map):
   ips = interface.get(int_var)
   if isinstance(ips, string_types):
    int_info[ips_var] = [ips]
   else:
    int_info[ips_var] = ips
  if ('vpc-id' in interface):
   int_info['network_type'] = 'vpc'
  else:
   int_info['network_type'] = 'classic'
  if (int_info['network_type'] == 'vpc'):
   int_info['network_id'] = interface['subnet-id']
  else:
   int_info['network_id'] = None
  facts['network']['interfaces'].append(int_info)
 facts['zone'] = metadata['placement']['availability-zone']
 facts['network']['ip'] = metadata.get('local-ipv4')
 facts['network']['public_ip'] = metadata.get('public-ipv4')
 facts['network']['hostname'] = metadata.get('local-hostname')
 facts['network']['public_hostname'] = metadata.get('public-hostname')
 return facts

def normalize_aws_facts ( metadata , facts ) : for interface in sorted ( metadata [ 'network' ] [ 'interfaces' ] [ 'macs' ] . values ( ) , key = ( lambda x : x [ 'device-number' ] ) ) : int_info = dict ( ) var_map = { 'ips' : 'local-ipv4s' , 'public_ips' : 'public-ipv4s' } for ( ips_var , int_var ) in iteritems ( var_map ) : ips = interface . get ( int_var ) if isinstance ( ips , string_types ) : int_info [ ips_var ] = [ ips ] else : int_info [ ips_var ] = ips if ( 'vpc-id' in interface ) : int_info [ 'network_type' ] = 'vpc' else : int_info [ 'network_type' ] = 'classic' if ( int_info [ 'network_type' ] == 'vpc' ) : int_info [ 'network_id' ] = interface [ 'subnet-id' ] else : int_info [ 'network_id' ] = None facts [ 'network' ] [ 'interfaces' ] . append ( int_info ) facts [ 'zone' ] = metadata [ 'placement' ] [ 'availability-zone' ] facts [ 'network' ] [ 'ip' ] = metadata . get ( 'local-ipv4' ) facts [ 'network' ] [ 'public_ip' ] = metadata . get ( 'public-ipv4' ) facts [ 'network' ] [ 'hostname' ] = metadata . get ( 'local-hostname' ) facts [ 'network' ] [ 'public_hostname' ] = metadata . get ( 'public-hostname' ) return facts
normalize aws facts args: metadata : provider metadata facts : facts to update returns: dict: the result of adding the normalized metadata to the provided facts dict .