
                            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dZ 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 Import forwarding rules command.    )absolute_import)division)unicode_literals)
exceptions)base_classes)forwarding_rules_utils)base)flags)util)yaml_validator)
console_iozK          Imports a forwarding rule's configuration from a file.
          zo          Import a forwarding rule by running:

            $ {command} NAME --source=<path-to-file>
          )DESCRIPTIONEXAMPLESc                   `    e Zd ZdZdZeZdZed        Z	ed
d       Z
ed        Zd Zd Zd	 Zy)ImportImport a forwarding rule.NFc                     | j                         t        j                   j                  k(  ry| j                         t        j                   j                  k(  ryy)z3Returns the API version based on the release track.alphabetav1)ReleaseTrackr	   ALPHABETA)clss    .lib/surface/compute/forwarding_rules/import.pyGetApiVersionzImport.GetApiVersion7   sG     T..444				t0055	5    c                 P    t        j                  d| j                         d|      S )z!Returns the resource schema path.computeForwardingRulefor_help)export_utilGetSchemaPathr   )r   r"   s     r   r$   zImport.GetSchemaPath@   s,     $$3$$&(88M Mr   c                     t        j                         | _        | j                  j                  |d       t	        j
                  || j                  d             y )Nimport)operation_typeTr!   )r
   ForwardingRuleArgumentFORWARDING_RULE_ARGAddArgumentr#   AddImportFlagsr$   )r   parsers     r   ArgszImport.ArgsF   sJ    #::<C''x'Hvs'8'8$'8'GHr   c                 V    dj                  |j                               }t        |      )%Create forwarding rule patch request.z5Forwarding Rule [{0}] cannot be updated in version v1)formatNameNotImplementedError)selfclientforwarding_rule_refreplacementconsole_messages        r   SendPatchRequestzImport.SendPatchRequestL   s1     	@FF$$&	(  o
..r   c                 f   |j                         dk(  rU|j                  j                  j                  |j                  j                  ||j                  |j                              S |j                  j                  j                  |j                  j                  ||j                              S )z$Send forwarding rule insert request.compute.forwardingRules)forwardingRuleprojectregion)r;   r<   )

Collectionapitools_clientforwardingRulesInsertmessages#ComputeForwardingRulesInsertRequestr<   r=   globalForwardingRules)ComputeGlobalForwardingRulesInsertRequest)r3   r4   r5   forwarding_rules       r   SendInsertRequestzImport.SendInsertRequestS   s    %%'+DD##33::
//
=
=,)11(// > 12 2 !!77>>AA*'// 	B 	12 2r   c                    t        j                  | j                               }|j                  }| j                  j                  ||j                  t        j                  |j                              }t        j                  |j                  xs dd      }	 t        j                  |j                  j                  || j!                               }	 t+        j,                  ||      }||k(  ry t        j6                  dj9                  |j;                               d	       |j<                  |_        |j>                  |_        g }
|j@                  s|
jC                  d
       |jD                  s|
jC                  d       | jF                  r|jH                  s|
jC                  d       |jJ                  s|
jC                  d       |jL                  jO                  |
      5  | jQ                  |||      cd d d        S # t"        j$                  $ r#}t'        j$                  t)        |            d }~ww xY w# t.        j0                  $ r.}	|	j2                  dk7  r|	| j5                  |||      cY d }	~	S d }	~	ww xY w# 1 sw Y   y xY w)N)scope_lister-F)binary)message_typestreamschema_pathi  z*Forwarding Rule [{0}] will be overwritten.T)messagecancel_on_nonetworkTierallowGlobalAccesssourceIpRangesmetadataFilters))r   ComputeApiHolderr   r4   r)   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerr   ReadFromFileOrStdinsourcer#   r   rB   r    r$   r   ValidationErrorr   strutilsSendGetRequestapitools_exceptions	HttpErrorstatus_coderG   PromptContinuer0   r1   idfingerprintrQ   appendrR   _support_source_ip_rangerS   rT   r?   IncludeFieldsr8   )r3   argsholderr4   r5   datarF   eforwarding_rule_olderrorcleared_fieldss              r   Runz
Import.Runa   s7   **4+<+<+>?F]]F22DD"88G E I
 ))$++*<UKD/#**55((*,o5!009LM o-=EE$$&( -//O"5"A"AO N&&M*,,/0$$_-K-K,-**-.				-	-n	=""6+>P 
>	=M )) /&&s1v../ (( 5			c	!##F,?$35 5	5@ 
>	=sB   :H H; %I?H8H33H8;I<#I71I<7I<?J)F)__name__
__module____qualname____doc__r)   DETAILED_HELPdetailed_helprg   classmethodr   r$   r-   r8   rG   rp    r   r   r   r   /   sd    !-"  M M
 I I
/27Qr   r   c                       e Zd ZdZd Zy)
ImportBetar   c                    |j                         dk(  rd|j                  j                  j                  |j                  j                  |j                  |j                  |j                         |            S |j                  j                  j                  |j                  j                  |j                  |j                         |            S )r/   r:   )r<   r=   r;   forwardingRuleResource)r<   r;   r|   )r>   r?   r@   PatchrB   "ComputeForwardingRulesPatchRequestr<   r=   r1   rD   (ComputeGlobalForwardingRulesPatchRequest)r3   r4   r5   r6   s       r   r8   zImportBeta.SendPatchRequest   s     %%'+DD##3399
//
<
<)11(//0557%0	 = 23 3 !!77==@@'//.335#. 	A 	01 1r   N)rq   rr   rs   rt   r8   rx   r   r   rz   rz      s
    !1r   rz   c                       e Zd ZdZdZy)ImportAlphar   TN)rq   rr   rs   rt   rg   rx   r   r   r   r      s    !!r   r   N)#rt   
__future__r   r   r   apitools.base.pyr   r`   googlecloudsdk.api_lib.computer   r   r^   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   rX   3googlecloudsdk.command_lib.compute.forwarding_rules!googlecloudsdk.command_lib.exportr   r#   googlecloudsdk.corer   googlecloudsdk.core.consoler   ru   ReleaseTracksr   GAUpdateCommandr   r   rz   r   r   rx   r   r   <module>r      s    ' &  ' > 7 J ( E J E A . 2
		 D%%(()hQT hQ *hQV D%%**+1 1 ,1* D%%++,*  -r   