original_docstring: 
      Flatten the policy VPN
      
      :param policy_vpn PolicyVPN
      :return dict
      
docstring: Flatten the policy VPN
  :param policy_vpn PolicyVPN
  :return dict
docstring_tokens: Flatten the policy VPN : param policy_vpn PolicyVPN : return dict
code: def to_dict(vpn, expand=None):
      """
      Flatten the policy VPN
      
      :param policy_vpn PolicyVPN
      :return dict
      """
      expand = expand if expand else []
      
      gateway_cache = {} # Cache gateways to reduce repetitive queries
      vpn.open()
      if 'vpn_profile' in expand:
          vpn.data['vpn_profile'] = format_element(vpn.vpn_profile)
  
      central = []
      for cgw in vpn.central_gateway_node:
          gateway_cache[cgw.href] = cgw
          gateway_cache[cgw.gateway.href] = cgw.gateway
          
          vpn_site = []
          for site in cgw.enabled_sites:
              if cgw.gateway.name in expand:
                  site.data['site_element'] = [format_element(s) for s in site.vpn_site.site_element]
                  vpn_site.append(format_element(site))
              else:
                  vpn_site.append(format_element(site.vpn_site))
  
          central.append({'name': cgw.gateway.name, 'type': cgw.gateway.typeof, 'vpn_site': vpn_site})
      
      satellite = []
      for sgw in vpn.satellite_gateway_node:
          gateway_cache[sgw.href] = sgw
          gateway_cache[sgw.gateway.href] = sgw.gateway
          
          vpn_site = []
          for site in sgw.enabled_sites:
              if sgw.gateway.name in expand:
                  site.data['site_element'] = [format_element(s) for s in site.vpn_site.site_element]
                  vpn_site.append(format_element(site))
              else:
                  vpn_site.append(format_element(site.vpn_site))
  
          satellite.append({'name': sgw.gateway.name, 'type': sgw.gateway.typeof, 'vpn_site': vpn_site})
      
      mobile_vpn = [mobile.name for mobile in vpn.mobile_gateway_node]
          
      gateway_tunnel = []
      
      for tunnel in vpn.tunnels:
          tunnel_map = {}
          
          tunnela = gateway_cache.get(tunnel.data.get('gateway_node_1')).gateway
          tunnelb = gateway_cache.get(tunnel.data.get('gateway_node_2')).gateway
         
          tunnel_map.update(
              tunnel_side_a=tunnela.name,
              tunnel_side_a_type=tunnela.typeof,
              tunnel_side_b=tunnelb.name,
              tunnel_side_b_type=tunnelb.typeof,
              enabled=tunnel.enabled)
      
          gateway_tunnel.append(tunnel_map)
  
      vpn.data.update(central_gateway=central, satellite_gateway=satellite,
                      gateway_tunnel=gateway_tunnel,
                      mobile_vpn_gateway=mobile_vpn)
      vpn.close()
      return format_element(vpn)
code_tokens: def to_dict ( vpn , expand = None ) : expand = expand if expand else [ ] gateway_cache = { } vpn . open ( ) if 'vpn_profile' in expand : vpn . data [ 'vpn_profile' ] = format_element ( vpn . vpn_profile ) central = [ ] for cgw in vpn . central_gateway_node : gateway_cache [ cgw . href ] = cgw gateway_cache [ cgw . gateway . href ] = cgw . gateway vpn_site = [ ] for site in cgw . enabled_sites : if cgw . gateway . name in expand : site . data [ 'site_element' ] = [ format_element ( s ) for s in site . vpn_site . site_element ] vpn_site . append ( format_element ( site ) ) else : vpn_site . append ( format_element ( site . vpn_site ) ) central . append ( { 'name' : cgw . gateway . name , 'type' : cgw . gateway . typeof , 'vpn_site' : vpn_site } ) satellite = [ ] for sgw in vpn . satellite_gateway_node : gateway_cache [ sgw . href ] = sgw gateway_cache [ sgw . gateway . href ] = sgw . gateway vpn_site = [ ] for site in sgw . enabled_sites : if sgw . gateway . name in expand : site . data [ 'site_element' ] = [ format_element ( s ) for s in site . vpn_site . site_element ] vpn_site . append ( format_element ( site ) ) else : vpn_site . append ( format_element ( site . vpn_site ) ) satellite . append ( { 'name' : sgw . gateway . name , 'type' : sgw . gateway . typeof , 'vpn_site' : vpn_site } ) mobile_vpn = [ mobile . name for mobile in vpn . mobile_gateway_node ] gateway_tunnel = [ ] for tunnel in vpn . tunnels : tunnel_map = { } tunnela = gateway_cache . get ( tunnel . data . get ( 'gateway_node_1' ) ) . gateway tunnelb = gateway_cache . get ( tunnel . data . get ( 'gateway_node_2' ) ) . gateway tunnel_map . update ( tunnel_side_a = tunnela . name , tunnel_side_a_type = tunnela . typeof , tunnel_side_b = tunnelb . name , tunnel_side_b_type = tunnelb . typeof , enabled = tunnel . enabled ) gateway_tunnel . append ( tunnel_map ) vpn . data . update ( central_gateway = central , satellite_gateway = satellite , gateway_tunnel = gateway_tunnel , mobile_vpn_gateway = mobile_vpn ) vpn . close ( ) return format_element ( vpn )
short_docstring: Flatten the policy VPN
  :param policy_vpn PolicyVPN
  :return dict
short_docstring_tokens: Flatten the policy VPN : param policy_vpn PolicyVPN : return dict
comment: """
      Flatten the policy VPN
      
      :param policy_vpn PolicyVPN
      :return dict
      """$SEP$# Cache gateways to reduce repetitive queries