
    ~4                     J   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j0                  ej2                  j4                         G d dej6                                      Z ej0                  ej2                  j:                         G d de             Z ej0                  ej2                  j>                         G d de             Z dddde_!        dddde_!        dddde _!        y)z#Command to update forwarding-rules.    )absolute_import)division)unicode_literals)messages)base_classes)	constants)base)
exceptions)flags)labels_utilc                 p   t        j                         | _        | j                  j                  |       t	        j
                  |       |rt        j                  |d       t        j                  |       t        j                  |       t        j                  |       t        j                  |       y)z*Add the flags to create a forwarding rule.T)
for_updateN)r   ForwardingRuleArgumentFORWARDING_RULE_ARGAddArgumentr   AddUpdateLabelsFlagsAddNetworkTierAddSourceIpRangesAddAllowGlobalAccessAddAllowPscGlobalAccessAddExternalMigration)clsparsersupport_network_tiers      .lib/surface/compute/forwarding_rules/update.py_Argsr       s     "88:#%%f-""6*	D1&!V$'V$    c                       e Zd ZdZdZdZed        Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zdedej"                  fdZd Zy)UpdateGA(Update a Compute Engine forwarding rule.NFc                 4    t        | || j                         y )N)r   )r   _support_network_tier)r   r   s     r   ArgszUpdateGA.Args:   s    	 66r   c                     |j                  |j                  |j                         |j                  |j                  |            S )NlabelFingerprintlabels)projectresourceglobalSetLabelsRequest),ComputeGlobalForwardingRulesSetLabelsRequestr(   NameGlobalSetLabelsRequestr&   selfr   forwarding_rule_refforwarding_rulereplacements        r   _CreateGlobalSetLabelsRequestz&UpdateGA._CreateGlobalSetLabelsRequestB   sO    @@#++$))+'>>,==  ?    A ! !r   c           	          |j                  |j                  |j                         |j                  |j	                  |j
                  |            S )Nr%   )r(   r)   regionregionSetLabelsRequest)&ComputeForwardingRulesSetLabelsRequestr(   r,   r5   RegionSetLabelsRequestr&   r.   s        r   _CreateRegionalSetLabelsRequestz(UpdateGA._CreateRegionalSetLabelsRequestK   sW    ::#++$))+"))'>>,==  ?   	 ; ! !r   c                     |rc|j                         }|t        j                  v r|j                  j	                  |      S t        j                  ddj                  |            y )Nz--network-tierzInvalid network tier [{tier}])tier)upperr   !NETWORK_TIER_CHOICES_FOR_INSTANCEForwardingRuleNetworkTierValueValuesEnumcalliope_exceptionsInvalidArgumentExceptionformat)r/   r   network_tiers      r   ConstructNetworkTierzUpdateGA.ConstructNetworkTierU   sf    !'')l	DD	D&&AA,OO!::+222EG 	G r   c                 :    | j                   xr |j                  d uS )N)r"   rC   r/   argss     r   _HasNextTierChangezUpdateGA._HasNextTierChangea   s    %%G$*;*;4*GGr   c                 $    |j                  d      S )Nsource_ip_rangesIsSpecifiedrF   s     r   _HasSourceIpRangeChangez UpdateGA._HasSourceIpRangeChanged   s    .//r   c                 $    |j                  d      S )Nallow_global_accessrK   rF   s     r   _HasGlobalAccessChangezUpdateGA._HasGlobalAccessChangeg   s    122r   c                 $    |j                  d      S )Nallow_psc_global_accessrK   rF   s     r   _HasPscGlobalAccessChangez"UpdateGA._HasPscGlobalAccessChangej   s    566r   c                     |j                  d      xs7 |j                  d      xs$ |j                  d      xs |j                  d      S )N<external_managed_backend_bucket_migration_testing_percentage/external_managed_backend_bucket_migration_state5clear_external_managed_backend_bucket_migration_stateload_balancing_schemerK   rF   s     r   _HasExternalMigrationChangez$UpdateGA._HasExternalMigrationChangem   s\    J	
 	5 MN	5 C
		5 34	r   r   returnc                 P   d}|j                  |j                        }| j                  |      r#| j                  ||j                        |_        d}| j                  |      r|j                  |_        d}| j                  |      r|j                  |_        d}| j                  |      r$|j                  |_        |j                  |_        d}|j!                  d      r,|j                   j#                  |j$                        |_        d}|j!                  d      r|j(                  |_        d}|j!                  d      r,|j                   j-                  |j.                        |_        d}|j!                  d      r$|j3                  d       |j3                  d	       d}|sy
|S )z?Returns a modified forwarding rule message and included fields.F)nameTrV   rU   rX   rW   *externalManagedBackendBucketMigrationState6externalManagedBackendBucketMigrationTestingPercentageN)r>   r\   rH   rD   rC   networkTierrM   rJ   sourceIpRangesrP   rO   allowGlobalAccessrS   rR   allowPscGlobalAccessfingerprintrL   9ExternalManagedBackendBucketMigrationStateValueValuesEnumrV   r]   rU   r^   "LoadBalancingSchemeValueValuesEnumrX   loadBalancingSchemeappend)r/   r   rG   existingcleared_fields
has_changer1   s          r   ModifyzUpdateGA.Modifyy   s    J--8==-AOt$$($=$=
D%%%'o!j##D)'+'<'<o$j""4(*.*B*Bo'j%%d+-1-I-Io*$,$8$8o!jIJCKCZCZ  DU  DU

>
>Do@ jF 
K
K L j/0

!
!
D
D(( )
 j? HI
B jr   c           
         t        j                  | j                               }|j                  j                  }|j                  j
                  }| j                  j                  ||j                  t        j                  |j                              }t        j                  j                  |      }|j                         }t        || j!                  |      | j#                  |      | j%                  |      | j'                  |      | j)                  |      g      }|st+        j,                  d      |j/                         dk(  rO|j0                  d|j3                  |j5                         |j6                        f}	|j8                  j:                  }
nY|j<                  d|j?                  |j5                         |j6                  |j@                        f}	|jB                  j:                  }
|j                  jE                  |	g      }|d   }g }| jG                  ||||      }|jI                  |
|jJ                        }g }|j/                         dk(  r|rJ|jM                  |j5                         ||j6                        }|jO                  |j0                  d	|f       |jP                  r| jS                  ||||jJ                        }|jO                  |j0                  d
|f       n|rU|jU                  |j5                         ||j6                  |j@                        }|jO                  |j<                  d	|f       |jP                  r<| jW                  ||||jJ                        }|jO                  |j<                  d
|f       |jY                  |      5  |j                  jE                  |      cddd       S # 1 sw Y   yxY w)zCReturns a list of requests necessary for updating forwarding rules.)scope_listerz(At least one property must be specified.zcompute.globalForwardingRulesGet)forwardingRuler(   )ro   r(   r5   r   )ro   forwardingRuleResourcer(   Patch	SetLabels)ro   rp   r(   r5   N)-r   ComputeApiHolderReleaseTrackclientapitools_clientr   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerr   DiffFromUpdateArgsMayHaveUpdatesanyrH   rP   rS   rM   rY   fw_exceptionsArgumentError
CollectionglobalForwardingRules&ComputeGlobalForwardingRulesGetRequestr,   r(   r-   LabelsValueforwardingRules ComputeForwardingRulesGetRequestr5   r8   MakeRequestsrk   Applyr'   (ComputeGlobalForwardingRulesPatchRequestrg   needs_updater3   "ComputeForwardingRulesPatchRequestr9   IncludeFields)r/   rG   holderru   r   r0   labels_diffhas_labels_updatesrj   get_requestlabels_valueobjectsr1   ri   forwarding_rule_replacementlabel_updaterequestsrequests                     r   RunzUpdateGA.Run   s   **4+<+<+>?F]]**F}}%%H22DD"88G E I
 ""11$7K$335%##D)&&t,$$T*((. J ''
46 6 %%'+JJ115DD(;(@(@(B!4!<!< E >?k 44@@l++U>>(;(@(@(B!4!<!< 3 : : ? <=k
 44@@lmm((+7GajON"&++$# $$\?3I3IJL H%%'+JJ	$CC.335#>'// D 1 	55wHI		"	"44X5H5D5A5H5HJ 	55{GLM	$==.335#>'//&--	 > /
 	//'BC		"	"66x7J7F7C7J7JL 	//gFG			n	-]]''1 
.	-	-s   OO)__name__
__module____qualname____doc__r   r"   classmethodr#   r3   r9   rD   rH   rM   rP   rS   rY   message_protoMessagerk   r    r   r   r   r   1   sp     1 !!
H037
;#;;zS2r   r   c                       e Zd ZdZdZy)
UpdateBetar    FNr   r   r   r   r"   r   r   r   r   r     s    0r   r   c                       e Zd ZdZdZy)UpdateAlphar    TNr   r   r   r   r   r     s    0r   r   r    zX        *{command}* updates global access for a Compute Engine forwarding rule.
        a          To update the forwarding rule to allow global access, run:

          $ {command} example-fr --allow-global-access --region=us-central1

        To add/update labels ``k0'' and ``k1'' and remove labels with key ``k3'',
        run:

          $ {command} example-fr --region=us-central1           --update-labels=k0=value1,k1=value2 --remove-labels=k3

        Labels can be used to identify the forwarding rule and to filter them as
        in

          $ {parent_command} list --filter='labels.k1:value2'

        To list existing labels, run:

          $ {parent_command} describe example-fr --format="default(labels)"
        )briefDESCRIPTIONEXAMPLESzk        *{command}* updates labels and global access for a Compute
        Engine forwarding rule.
        zy        *{command}* updates labels, global access and network tier for a Compute
        Engine forwarding rule.
        a          To update the forwarding rule to allow global access, run:

          $ {command} example-fr --allow-global-access --region=us-central1

        To add/update labels ``k0'' and ``k1'' and remove labels with key ``k3''
        , run:

          $ {command} example-fr --region=us-central1             --update-labels=k0=value1,k1=value2 --remove-labels=k3

        Labels can be used to identify the forwarding rule and to filter them as
        in

          $ {parent_command} list --filter='labels.k1:value2'

        To list existing labels, run:

          $ {parent_command} describe example-fr --format="default(labels)"
        N)"r   
__future__r   r   r   apitools.base.protorpcliter   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper	   r
   r@   "googlecloudsdk.command_lib.computer   ry   3googlecloudsdk.command_lib.compute.forwarding_rulesr   $googlecloudsdk.command_lib.util.argsr   r   UniverseCompatibleReleaseTracksrt   GAUpdateCommandr   BETAr   ALPHAr   detailed_helpr   r   r   <module>r      s4   * &  ' @ 7 4 ( E E [ E <%" D%%(()V2t!! V2 * V2r D%%**+    ,  D%%++,*  - 	3		 @ 	3	
	
 B 	3	
	 r   