
    7                     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Zej"                   ej$                  ej&                  j(                  ej&                  j*                         G d dej,                                      Zddie_        y)zICommand for updating organization firewall policy packet mirroring rules.    )absolute_import)division)unicode_literals)base_classes)firewall_policy_rule_utils)client)base)firewall_policies_utils)flagsNc                   *    e Zd ZdZdZed        Zd Zy)UpdatezUpdates a Compute Engine firewall policy packet mirroring rule.

  *{command}* is used to update organization firewall policy packet mirroring
  rules.
  Nc                 z   t        j                  dd      | _        | j                  j                  |       t        j                  |d       t        j
                  |d       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |d       t        j                  |d       y )NTupdate)required	operationF)r   updated)r   )r   FirewallPolicyRuleArgumentFIREWALL_POLICY_ARGAddArgumentAddPacketMirroringActionAddFirewallPolicyIdAddSrcIpRangesAddDestIpRangesAddLayer4ConfigsAddDirectionAddDisabledAddTargetResources AddMirroringSecurityProfileGroupAddDescriptionAddNewPriorityAddOrganization)clsparsers     ?lib/surface/compute/firewall_policies/mirroring_rules/update.pyArgszUpdate.Args)   s    #>>C ''/	""6E:	f	:	 	&!	6"	v	f	V$	**62	 	84	&51    c           
         ddddd}t        j                  | j                               }| j                  j	                  ||j
                  d      }t        j                  ||j                  |j
                  t        j                  | j                               j                               }t        j                  ||j                  |j
                  t        j                  | j                               j                               }g }t        j                  |j                               }g }	g }
g }g }d }d}d }d }d }|D ]:  }|j                  |      s|j!                  |      r'|j#                  ||          < |j%                  d	      r|j&                  }	d
}|j%                  d      r|j(                  }
d
}|j%                  d      r6d
}t        j*                  |j,                  |j                  j.                        }|j%                  d      r|j0                  }|j%                  d      r8t3        j4                  |j6                  |j8                  ||j:                        }n1|j%                  d      r |j<                  dk7  r|j#                  d       |j%                  d      r|j>                  }|j%                  d      r t        j                  |j@                        }n|}|r(|j                  j.                  jC                  |	|
|      }|j%                  d      rx|jD                  dk(  r5|j                  j.                  jF                  jH                  jJ                  }n4|j                  j.                  jF                  jH                  jL                  }|j                  j.                  jG                  ||j<                  ||||jN                  ||      }t3        jP                  ||j:                  |j8                        }|j                  jR                  jU                  |      5  |jW                  |||      cd d d        S # 1 sw Y   y xY w)Nzmatch.srcIpRangeszmatch.destIpRangessecurityProfileGrouptargetResources)src_ip_rangesdest_ip_rangessecurity_profile_grouptarget_resourcesF)with_project)refcompute_client	resourcesversionr*   Tr+   layer4_configsr-   r,   )r,   optional_organizationfirewall_policy_clientfirewall_policy_idactionapply_security_profile_groupdisablednew_priority)srcIpRangesdestIpRangeslayer4Configs	directionINGRESS)priorityr7   matchr>   r)   descriptionr9   r(   )organization)r@   firewall_policyfirewall_policy_rule),r   ComputeApiHolderReleaseTrackr   ResolveAsResourcer1   r   OrgFirewallPolicysix	text_typelower$OrgFirewallPolicyPacketMirroringRule
rule_utilsConvertPriorityToIntNameIsKnownAndSpecifiedGetValueappendIsSpecifiedr*   r+   ParseLayer4Configsr3   messagesr-   r
   BuildSecurityProfileGroupUrlr,   rC   rD   r7   r9   r:   FirewallPolicyRuleMatcherr>   FirewallPolicyRuleDirectionValueValuesEnumr?   EGRESSrB   GetFirewallPolicyIdapitools_clientIncludeFields
UpdateRule)selfargs clearable_arg_name_to_field_nameholderr/   org_firewall_policyfirewall_policy_rule_clientcleared_fieldsr@   r*   r+   layer4_config_listr-   r9   should_setup_matchtraffic_directmatcherr,   argr:   rE   r6   s                         r$   Runz
Update.Run=   s   ,."8-	($ **4+<+<+>?F

"
"
4
4fU 5 C !22}}""d//1288:	 #)"M"M}}""d//1288:	# N..sxxz:HMNHNG!/		!	!#	&t}}S/A>sCD 0 (((m()**n()%88


v}}55 *+..01
!
>
>%)%@%@$($5$5%8!%!5!5	  	"KK9923
#h'44T5F5FGll &&@@#%* A g $	9	$MM""55NNVV 	
 MM""55NNUU 	 "==11DD{{ ($$3 E 	 1DD#&& 
	&	&	4	4^	D(33,3 4  
E	D	Ds   2QQ)__name__
__module____qualname____doc__r   classmethodr%   rl    r&   r$   r   r      s'     2 2&qr&   r   EXAMPLESa)      To update a rule with priority ``10" in an organization firewall policy
    with ID ``123456789" to change the action to ``allow" and description to
    ``new-example-rule", run:

      $ {command} 10 --firewall-policy=123456789 --action=do_not_mirror
      --description=new-example-rule
    )rp   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   rN   0googlecloudsdk.api_lib.compute.firewall_policiesr   googlecloudsdk.callioper	   4googlecloudsdk.command_lib.compute.firewall_policiesr
   r   rJ   UniverseCompatibleReleaseTracksrG   ALPHABETAUpdateCommandr   detailed_helprr   r&   r$   <module>r      s    P &  ' 7 S C ( X F 
 D%%++T->->-C-CDNT N E Nd  	 r&   