
                         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)z8Command for creating organization firewall policy 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)CreatezCreates a Compute Engine firewall policy packet mirroring rule.

  *{command}* is used to create organization firewall policy packet mirroring
  rules.
  Nc                    t        j                  dd      | _        | j                  j                  |d       t        j                  |       t        j
                  |d       t        j                  |       t        j                  |       t        j                  |d       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |d       |j                  j!                  t         j"                         y )	NTcreate)required	operation)operation_typeinserted)r   )r   F)r   FirewallPolicyRuleArgumentFIREWALL_POLICY_ARGAddArgumentAddPacketMirroringActionAddFirewallPolicyIdAddSrcIpRangesAddDestIpRangesAddLayer4ConfigsAddDirectionAddDisabledAddTargetResources AddMirroringSecurityProfileGroupAddDescriptionAddOrganizationdisplay_infoAddCacheUpdaterFirewallPoliciesCompleter)clsparsers     ?lib/surface/compute/firewall_policies/mirroring_rules/create.pyArgszCreate.Args)   s    #>>C ''x'H	""6*	f
;	 	&!	6D1	v	f	V$	**62	 	&51
''(G(GH    c           
      2   t        j                  | j                               }| j                  j	                  ||j
                  d      }t        j                  ||j                  |j
                  t        j                  | j                               j                               }t        j                  ||j                  |j
                  t        j                  | j                               j                               }g }g }g }g }	d }
d}|j                  d      r|j                  }|j                  d      r|j                  }|j                  d      r|j                  }|j                  d      r|j                   }	|j                  d      r7t#        j$                  |j&                  |j(                  ||j*                  	      }
|j                  d
      r|j,                  }t/        j0                  ||j                  j2                        }|j                  j2                  j5                  |||      }|j                  j2                  j6                  j8                  j:                  }|j                  d      rx|j<                  dk(  r5|j                  j2                  j6                  j8                  j:                  }n4|j                  j2                  j6                  j8                  j>                  }|j                  j2                  j7                  t/        j@                  |jC                               |jD                  |||	|
|jF                  |      }t#        jH                  ||j*                  |j(                        }|jK                  ||      S )NF)with_project)refcompute_client	resourcesversionsrc_ip_rangesdest_ip_rangeslayer4_configstarget_resourcessecurity_profile_group)r4   optional_organizationfirewall_policy_clientfirewall_policy_iddisabled)srcIpRangesdestIpRangeslayer4Configs	directionINGRESS)priorityactionmatchr<   targetResourcessecurityProfileGroupdescriptionr8   )organization)firewall_policyfirewall_policy_rule)&r   ComputeApiHolderReleaseTrackr   ResolveAsResourcer.   r   OrgFirewallPolicysix	text_typelower$OrgFirewallPolicyPacketMirroringRuleIsSpecifiedr0   r1   r2   r3   r
   BuildSecurityProfileGroupUrlr4   rD   rE   r8   
rule_utilsParseLayer4ConfigsmessagesFirewallPolicyRuleMatcherFirewallPolicyRuleDirectionValueValuesEnumr=   r<   EGRESSConvertPriorityToIntNamer?   rC   GetFirewallPolicyId
CreateRule)selfargsholderr,   org_firewall_policyfirewall_policy_rule_clientr0   r1   r2   r3   r4   r8   layer4_config_listmatchertraffic_directrF   r7   s                    r'   Runz
Create.Run<   s"   **4+<+<+>?F

"
"
4
4fU 5 C !22}}""d//1288:	 #)"M"M}}""d//1288:	# MNN!H(((m()**n()**n*+..01
!
>
>%)%@%@$($5$5%8!%!5!5	  
#h#66.. mm$$>>!#( ? G 	11JJRR  $	9	$MM""55NNVV 	
 MM""55NNUU 	 "==11DD00<{{ (3$$ E 	 1DD#&&
 '11*1 2  r)   )__name__
__module____qualname____doc__r   classmethodr(   rd    r)   r'   r   r      s)     I I$Vr)   r   EXAMPLESaS      To create a packet mirroring rule with priority ``10" in an organization firewall policy with ID
    ``123456789", run:

      $ {command} 10 --firewall-policy=123456789 --action=mirror --security-profile-group=organizations/123/locations/global/securityProfileGroups/custom-security-profile-group
      --description=example-rule
    )rh   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   rQ   0googlecloudsdk.api_lib.compute.firewall_policiesr   googlecloudsdk.callioper	   4googlecloudsdk.command_lib.compute.firewall_policiesr
   r   rK   UniverseCompatibleReleaseTracksrH   ALPHABETACreateCommandr   detailed_helprj   r)   r'   <module>rw      s    ? &  ' 7 S C ( X F 
 D%%++T->->-C-CDrT r E rl   r)   