def normalize_gce_facts(metadata, facts):
 for interface in metadata['instance']['networkInterfaces']:
  int_info = dict(ips=[interface['ip']], network_type='gce')
  int_info['public_ips'] = [ac['externalIp'] for ac in interface['accessConfigs']]
  int_info['public_ips'].extend(interface['forwardedIps'])
  (_, _, network_id) = interface['network'].rpartition('/')
  int_info['network_id'] = network_id
  facts['network']['interfaces'].append(int_info)
 (_, _, zone) = metadata['instance']['zone'].rpartition('/')
 facts['zone'] = zone
 facts['network']['ip'] = facts['network']['interfaces'][0]['ips'][0]
 pub_ip = facts['network']['interfaces'][0]['public_ips'][0]
 facts['network']['public_ip'] = pub_ip
 facts['network']['hostname'] = metadata['instance']['hostname']
 facts['network']['public_hostname'] = facts['network']['public_ip']
 return facts

def normalize_gce_facts ( metadata , facts ) : for interface in metadata [ 'instance' ] [ 'networkInterfaces' ] : int_info = dict ( ips = [ interface [ 'ip' ] ] , network_type = 'gce' ) int_info [ 'public_ips' ] = [ ac [ 'externalIp' ] for ac in interface [ 'accessConfigs' ] ] int_info [ 'public_ips' ] . extend ( interface [ 'forwardedIps' ] ) ( _ , _ , network_id ) = interface [ 'network' ] . rpartition ( '/' ) int_info [ 'network_id' ] = network_id facts [ 'network' ] [ 'interfaces' ] . append ( int_info ) ( _ , _ , zone ) = metadata [ 'instance' ] [ 'zone' ] . rpartition ( '/' ) facts [ 'zone' ] = zone facts [ 'network' ] [ 'ip' ] = facts [ 'network' ] [ 'interfaces' ] [ 0 ] [ 'ips' ] [ 0 ] pub_ip = facts [ 'network' ] [ 'interfaces' ] [ 0 ] [ 'public_ips' ] [ 0 ] facts [ 'network' ] [ 'public_ip' ] = pub_ip facts [ 'network' ] [ 'hostname' ] = metadata [ 'instance' ] [ 'hostname' ] facts [ 'network' ] [ 'public_hostname' ] = facts [ 'network' ] [ 'public_ip' ] return facts
normalize gce facts args: metadata : provider metadata facts : facts to update returns: dict: the result of adding the normalized metadata to the provided facts dict .