
                         L   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  ej                  ej                  j                  ej                  j                   ej                  j"                         G d
 dej$                               Zddde_        y)z0Command for creating packet mirroring resources.    )absolute_import)division)unicode_literals)base_classes)base)client)flags)utilsc                   0    e Zd ZdZdZed        Zd Zd Zy)Create0Create a Compute Engine packet mirroring policy.Nc                     t         j                  j                  |       t        j                         | _        | j
                  j                  |d       t        j                  |       y )Ncreate)operation_type)r   
ASYNC_FLAGAddToParserr	   PacketMirroringArgumentPACKET_MIRRORING_ARGAddArgumentAddCreateArgs)clsparsers     /lib/surface/compute/packet_mirrorings/create.pyArgszCreate.Args#   sL    OO'$<<>C(((I	    c                      y)Nzcompute.packetMirrorings )selfs    r   
CollectionzCreate.Collection,   s    %r   c                 >   t        j                  | j                               j                  j                  | j
                  j                  |j                        fd}fd}|j                  r |j                  D cg c]
  } ||       c}ng }|j                  r |j                  D cg c]
  } ||       c}ng }j                         }|j                  s|j                  rb|j                  r%|j                  j                  |j                         |j                  r%|j                  j                  |j                         |j                   r8j                  j#                  |j                   j%                               |_        j)                  |||j*                  xs g       }	j-                  j/                         |j0                  j3                  t5        j6                  j8                  |j:                  j                              j=                  t5        j>                  j8                  j@                  |jB                  j                              |	||jD                  r j,                  jF                  jH                  nj,                  jF                  jJ                        }
t        j,                  j                  j                        }|jM                  |
|jN                  xs d      S c c}w c c}w )	Nc                 z    j                  t        j                  j                  | j                              S Nurl)/PacketMirroringMirroredResourceInfoInstanceInfor
   ResolveInstanceURIproject	resources)instanceholdermessagespm_refs    r   _MakeInstanceInfoz%Create.Run.<locals>._MakeInstanceInfo5   s;    EE&&v~~x'-'7'79 F : :r   c                     j                  t        j                  j                  j                  | j
                              S r"   )-PacketMirroringMirroredResourceInfoSubnetInfor
   ResolveSubnetURIr'   regionr(   )subnetr*   r+   r,   s    r   _MakeMirroredSubnetInfoz+Create.Run.<locals>._MakeMirroredSubnetInfo:   sA    CC$$V^^V]]F%+%5%57 D 8 8r   )subnetworks	instancestagsr#   )namedescriptionnetworkcollectorIlbmirroredResourcesfilterenable)compute_clientregistryF)is_async)(r   ComputeApiHolderReleaseTrackr   r+   r   ResolveAsResourcer(   mirrored_instancesmirrored_subnetsPacketMirroringFilterfilter_cidr_rangesfilter_protocols
cidrRangesextendIPProtocolsfilter_directionDirectionValueValuesEnumupper	direction#PacketMirroringMirroredResourceInfomirrored_tagsPacketMirroringNamer8   PacketMirroringNetworkInfor
   ResolveNetworkURIr'   r9   !PacketMirroringForwardingRuleInfoResolveForwardingRuleURIr1   collector_ilbr=   EnableValueValuesEnumTRUEFALSEr   async_)r   argsr-   r3   r)   mirrored_instance_infosr2   mirrored_subnet_infos	pm_filtermirrored_resources_infotemplatepacket_mirroringr*   r+   r,   s               @@@r   Runz
Create.Run/   s   **4+<+<+>?F}}%%H&&88v?O?OPF:
8 
	 	  594K4K4K(#4K&(  
		 7;6K6K6KF'6K$&  ..0I$"7"7		 	 ##D$;$;<			$$T%:%:;$::SS



%
%
')i 'JJ))%2 K ' ''[[]$$33''(.(8(8: 4 ; ??..v~~v}}/3/A/A/5/?/?A @ B 2 ''==BB!11GGMM ( OH --v}}v7G7GI ""8dkk6JU"KKSs   L9L)	__name__
__module____qualname____doc__r   classmethodr   r   rd   r   r   r   r   r      s*     9   &9Lr   r   r   a      Mirror all tcp traffic to/from all instances in subnet my-subnet in
    us-central1, and send the mirrored traffic to the collector-fr
    Forwarding Rule.

      $ {command} my-pm
        --network my-network --region us-central1
        --mirrored-subnets my-subnet --collector-ilb collector-fr
        --filter-protocols tcp

    Mirror all traffic between instances with tag t1 and external server with IP
    11.22.33.44 in us-central1, and send the mirrored traffic to the
    collector-fr Forwarding Rule.

      $ {command} my-pm
        --network my-network --region us-central1
        --mirrored-tags t1 --collector-ilb collector-fr
        --filter-cidr-ranges 11.22.33.44/32
    )DESCRIPTIONEXAMPLESN)rh   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   4googlecloudsdk.command_lib.compute.packet_mirroringsr   r	   r
   ReleaseTracksrB   ALPHABETAGACreateCommandr   detailed_helpr   r   r   <module>rv      s    7 &  ' 7 ( G F F D%%++T->->-C-C%%((*JLT JL*JLZ F r   