
                         "   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dlmZ ddlmZ ddlZej2                   ej4                  ej6                  j8                         G d dej:                                      Z ej4                  ej6                  j>                         G d de             Z  ej4                  ej6                  jB                         G d de              Z"y)z,Command for creating Compute Engine routers.    )absolute_import)division)unicode_literals)base_classes)poller)waiter)arg_parsers)base)resource_manager_tags_utils)flags)router_utils)log)	resourcesNc                   n    e Zd ZdZdZdZdZed        Zed        Z	ed        Z
ed        Zd Zd	 Zd
 Zy)CreateCreate a Compute Engine router.

  *{command}* is used to create a router to provide dynamic routing to VPN
  tunnels and interconnects.
  NFc                    |j                   j                  t        j                         | j                  s| j                  |       n| j                  |       | j                  r'|j                  dt        j                         dd       t        j                         | _        | j                  j                  |d       t        j                  j!                  |       t        j"                  |       t        j$                  |       t        j&                  |       t        j(                  |       t        j*                  |d       |j                   j-                  t        j.                         y )Nz--resource-manager-tagsz	KEY=VALUEz\            A comma-separated list of Resource Manager tags to apply to the router.
        )typemetavarhelpcreate)operation_typerouter)display_info	AddFormatr   DEFAULT_CREATE_FORMAT_support_ncc_gatewayadd_network_argadd_ncc_gateway_and_network_arg_support_tagging_at_creationadd_argumentr	   ArgDictRouterArgument
ROUTER_ARGAddArgumentr
   
ASYNC_FLAGAddToParserAddCreateRouterArgsAddKeepaliveIntervalArgAddBgpIdentifierRangeArgAddEncryptedInterconnectRouter!AddReplaceCustomAdvertisementArgsAddCacheUpdaterRoutersCompleterclsparsers     %lib/surface/compute/routers/create.py_ArgszCreate._Args0   s   
!!%"="=>##	&!	))&1
''
#""$	   ))+CNNNvh?OO'	f%	!!&)	""6*	((0	++FH=
''(>(>?    c                     |j                  d      }t        j                  |       t        j                  dd      | _        | j
                  j                  |       y )NT)requiredFThe network for this router)r6   
short_help)add_mutually_exclusive_groupr   AddNccGatewayArgnetwork_flagsNetworkArgumentForOtherResourceNETWORK_ARGr%   )r0   r1   link_parsers      r2   r   z&Create.add_ncc_gateway_and_network_argM   sO    55t5DK	;'#CC0CO OO,r4   c                 n    t        j                  d      | _        | j                  j                  |       y )Nr7   )r;   r<   r=   r%   r/   s     r2   r   zCreate.add_network_argW   s+    #CC%CO OO'r4   c                 &    | j                  |       y)zSee base.CreateCommand.N)r3   r/   s     r2   ArgszCreate.Args^   s     IIfr4   c                    t        j                  | j                               }|j                  j                  }|j                  j
                  j                  }| j                  j                  ||j                        }|j                  |j                         |j                        }| j                  r|j                  |j                  |_        | j                   r-|j"                  !| j%                  ||j"                        |_        |j(                  ;| j*                  j                  ||j                        }|j-                         |_        |j.                  |j0                  ,|j3                  |j.                  |j0                        |_        |j7                  d      r|j8                  |_        t=        j>                  |      rt=        j@                  ||j2                  |      \  }}	}
||	|
d}|j.                  |j3                         |_        tC        jD                  |      D ]  \  }}|	tG        |j4                  ||       ! |jH                  FtK        |j4                  d      s|j3                         |_        |jH                  |j4                  _&        |jO                  |jQ                  ||jR                  |jT                              }t        jV                  jY                  |jZ                  d|jT                  |jR                  d	
      }|j\                  rP|j7                  d      sd|_/        ta        jb                  |dj_                  |j                               dd       |S |j                  jY                  |j                         d|jT                  |jR                  d	
      }te        jf                  ||      }ti        jj                  ||dj_                  |j                                     S )N)namedescription)asnkeepaliveIntervalencrypted_interconnect_router)messagesresource_classargs)advertiseModeadvertisedGroupsadvertisedIpRangesidentifierRange)r   regionprojectzcompute.regionOperations)rP   rO   )
collectionparamsformatnonezrouter [{0}]Tz[Run the [gcloud compute operations describe] command to check the status of this operation.)kindis_asyncdetailszcompute.routerszCreating router [{0}])6r   ComputeApiHolderReleaseTrackclientrH   apitools_clientroutersr$   ResolveAsResourcer   RouterNamerD   r   ncc_gateway
nccGatewayr    resource_manager_tags_CreateRouterParamsrR   networkr=   SelfLinkrE   keepalive_interval	RouterBgpbgpIsSpecifiedrG   encryptedInterconnectRouterr   HasReplaceAdvertisementFlagsParseAdvertisementssix	iteritemssetattrbgp_identifier_rangehasattrrN   InsertComputeRoutersInsertRequestrO   rP   REGISTRYParserC   async_rS   r   CreatedResourcer   Pollerr   WaitFor)selfrJ   holderrH   service
router_refrouter_resourcenetwork_refmodegroupsrangesattrsattrvalueresultoperation_reftarget_router_refoperation_pollers                     r2   _RunzCreate._Runc   s   **4+<+<+>?F}}%%Hmm++33G2249I9IJJoo__$$ & O
   				%%)%5%5"((		#	#	/!%!9!9d00"
 ||$$66tV=M=MNk + 4 4 6o xxt66B$..hh$*A*A / o 78

,
, 1 006)==H,>,>TdFF
  $ &e 
	&002u-+$
/%%tU
3 .   ,_((*;<&002,0,E,Eo)^^,,"$$&& 	- 	
F &&,,-!)) ''
 - M {{h'	
$$Z__%677 m((..$!)) ''
 /  }}W.?@>>&&z'89 r4   c                 $    | j                  |      S )zSee base.UpdateCommand.)r   )rz   rJ   s     r2   Runz
Create.Run   s    99T?r4   c                    t        j                  |      }|j                  }t        t	        j
                  |            D cg c]"  \  }}|j                  j                  ||      $ }}} ||j                  |            S c c}}w )N)keyr   )additionalProperties)resourceManagerTags)r   GetResourceManagerTagsRouterParamssortedrm   rn   ResourceManagerTagsValueAdditionalProperty)rz   rH   rb   resource_manager_tags_maprR   r   r   additional_propertiess           r2   rc   zCreate._CreateRouterParams   s    #::!	
 
 ""F !/H!IJJJC 	''::s%:PJ   ";;!6 < 
 	s   'B)__name__
__module____qualname____doc__r$   r   r    classmethodr3   r   r   rA   r   r   rc    r4   r2   r   r   #   s{     *!&@ @8 - - ( (  hTr4   r   c                       e Zd ZdZdZdZy)
CreateBetar   TNr   r   r   r   r   r    r   r4   r2   r   r      s     !%r4   r   c                       e Zd ZdZdZdZy)CreateAlphar   TNr   r   r4   r2   r   r      s    
 !%r4   r   )#r   
__future__r   r   r   googlecloudsdk.api_lib.computer   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   +googlecloudsdk.command_lib.compute.networksr   r;   *googlecloudsdk.command_lib.compute.routersr   googlecloudsdk.corer   r   rm   UniverseCompatibleReleaseTracksrY   GACreateCommandr   BETAr   ALPHAr   r   r4   r2   <module>r      s    3 &  ' 7 < . / ( J N < C # ) 
 D%%((){T { * {| D%%**+& & ,& D%%++,&* & -&r4   