
    R                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	l	mZ dd
lmZ ddlmZ ddlmZ ddlmZ d Zej&                   ej(                  ej*                  j,                  ej*                  j.                  ej*                  j0                         G d dej2                                      Zy)z&Command for creating network peerings.    )absolute_import)division)unicode_literals)base_classes)batch_helper)utils)actions)base)flags)log)
properties)	resourcesc                    |rt        j                  || j                  j                  | j                        \  }}|sy|D ]r  }t
        j                  j                  dj                  |j                               t
        j                  j                  dj                  |j                               t |S t        j                  |       |S | j                  |      }|S )zHHelper for making asynchronous or synchronous peering creation requests.)requestshttp	batch_urlz#Creating network peering for [{0}]
zMonitor its progress at [{0}]
)r   MakeRequestsapitools_clientr   r   r   statuswriteformat
targetLinkselfLinkr   RaiseToolException)clientr   is_async	responseserrors	operations         /lib/surface/compute/networks/peerings/create.py_MakeRequestsr!       s    $11##((""$Iv  )

?FF  " 	#

:AA  	! ! 
 v& 
 ##H-I	    c                   @    e Zd ZdZdZed        Zed        Zd Zd Z	y)Createa  Create a Compute Engine network peering.

  *{command}* is used to create peerings between virtual networks. Each side of
  a peering association is set up independently. Peering will be active only
  when the configuration from both sides matches.

  ## EXAMPLES

  To create a network peering with the name 'peering-name' between the network
  'local-network' and the network 'peer-network' which exports and imports
  custom routes and subnet routes with public IPs, run:

    $ {command} peering-name \
      --network=local-network \
      --peer-network=peer-network \
      --export-custom-routes \
      --import-custom-routes \
      --export-subnet-routes-with-public-ip \
      --import-subnet-routes-with-public-ip
  Fc                    |j                  dd       |j                  ddd       |j                  ddd	       |j                  d
dd       t        j                  j                  |       t	        j
                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |       y )NnamezThe name of the peering.)helpz	--networkTzRThe name of the network in the current project to be peered with the peer network.)requiredr'   z--peer-networkz>The name of the network to be peered with the current network.z--peer-projectFz]The name of the project for the peer network.  If not specified, defaults to current project.)add_argumentr
   
ASYNC_FLAGAddToParserr   AddImportCustomRoutesFlagAddExportCustomRoutesFlag%AddImportSubnetRoutesWithPublicIpFlag%AddExportSubnetRoutesWithPublicIpFlagAddStackTypeAddUpdateStrategy)clsparsers     r    
ArgsCommonzCreate.ArgsCommonS   s     %?@
!  " M  O
 '  ( 	OO'	##F+	##F+	//7	//7	v	F#r"   c                     | j                  |       t        j                  ddd      }|j                  d|ddd       y )	Nzauto-create-routeszPFlag --auto-create-routes is deprecated and will be removed in a future release.
store_true)warnactionz--auto-create-routesFzIf set, will automatically create routes for the network peering. Flag auto-create-routes is deprecated. Peer network subnet routes are always created in a network when peered.)r8   defaultr(   r'   )r4   r	   DeprecationActionr)   )r2   r3   r8   s      r    ArgszCreate.Argsu   sQ    NN6&&. F <  
r"   c                    t         j                  j                  |j                  d|j                  xs. t
        j                  j                  j                  j                  id      }|j                  j                  |j                  |j                         d      }|j                  |_        |j                   |_        |j$                  |_        |j(                  |_        t-        |d      r4|j                  j                  j/                  |j0                        |_        t-        |d      r4|j                  j                  j5                  |j6                        |_        |S )Nprojectzcompute.networks)params
collectionT)r&   networkexchangeSubnetRoutes
stack_typeupdate_strategy)r   REGISTRYParsepeer_networkpeer_projectr   VALUEScorer=   	GetOrFailmessagesNetworkPeeringr&   RelativeNameexport_custom_routesexportCustomRoutesimport_custom_routesimportCustomRoutes#export_subnet_routes_with_public_ipexportSubnetRoutesWithPublicIp#import_subnet_routes_with_public_ipimportSubnetRoutesWithPublicIpgetattrStackTypeValueValuesEnumrB   	stackTypeUpdateStrategyValueValuesEnumrC   updateStrategy)selfr   argspeer_network_refnetwork_peerings        r    _CreateNetworkPeeringForRequestz&Create._CreateNetworkPeeringForRequest   s>    ))//!!MZ%6%6%;%;%C%C%M%M

 & 0  oo44YY --/! 5 O
 *.)B)BO&)-)B)BO&00 2 	00 2 t\"
//
(
(
A
Aoo  t&'
//
(
(
F
F"" $ r"   c           	         t        j                  | j                               }|j                  }|j                  j                  |j                  |j                  j                  | j                  ||            t        j                  j                  j                  j                               }|j                  j                  d|fg}t!        |||j"                        S )z4Issues the request necessary for adding the peering.)networkPeering)r@   networksAddPeeringRequestr=   
AddPeering)r   ComputeApiHolderReleaseTrackr   rK    ComputeNetworksAddPeeringRequestr@   NetworksAddPeeringRequestr_   r   rH   rI   r=   rJ   r   networksr!   async_)r[   r\   holderr   requestr   s         r    Runz
Create.Run   s    **4+<+<+>?F]]Foo>>"(//"K"K??M #L #O!!&&..88:	 ? <G ''00,HIH4;;77r"   N)
__name__
__module____qualname____doc___support_stack_typeclassmethodr4   r;   r_   rl    r"   r    r$   r$   7   sA    
* $ $B  ,&P8r"   r$   N)rp   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   r
   4googlecloudsdk.command_lib.compute.networks.peeringsr   googlecloudsdk.corer   r   r   r!   DefaultUniverseOnlyReleaseTracksre   GAALPHABETACommandr$   rs   r"   r    <module>r      s    - &  ' 7 7 0 + ( F # * ). $++1143D3D3I3IE8T\\ E8 E8r"   