
    2                        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lmZ  ej4                  ej6                  j8                  ej6                  j:                  ej6                  j<                         G d dej>                               Z ddde _!        y)z2Command for adding a Rule to a Compute Engine NAT.    )absolute_import)division)unicode_literals)base_classes)poller)waiter)base)flags)
nats_utils)rules_utils)log)	resourcesc                   &    e Zd ZdZed        Zd Zy)Createz#Add a Rule to a Compute Engine NAT.c                    t        j                         | _        | j                  j                  |       t	        j
                  |dd       t	        j                  |       t        j                  |dd       t	        j                  |d       t	        j                  |       t        j                  j                  |       y )NcreateF)operation_typepluralNAT)r   T)required)routers_flagsRouterArgumentForNat
ROUTER_ARGAddArgumentrules_flagsAddRuleNumberArgAddNatNameArgcompute_flagsAddRegionFlagAddMatchArgAddIpAndRangeArgsForCreater	   
ASYNC_FLAGAddToParser)clsparsers     0lib/surface/compute/routers/nats/rules/create.pyArgszCreate.Args'   s    "779CNNNv&  Of%hGFT2**62OO'    c                    t        j                  | j                               }|j                  j                  }|j                  j
                  j                  }| j                  j                  ||j                        }|j                  }|j                   |di |j                               }|j                  }|j                  }	t        j                   ||	      }
t#        j$                  |||
      }|
j&                  j)                  |       |j+                  |j-                  |j.                  |j0                  |j3                         |            }t        j4                  j7                  |j8                  d|j.                  |j0                  d      }|j:                  r+t=        j>                  |djA                  ||	      dd       |S |j                  j7                  |j3                         d	|j.                  |j0                  d      }tC        jD                  ||      }tG        jH                  ||d
jA                  ||	            S )N)projectregionrouterrouterResourcezcompute.regionOperations)r*   r+   )
collectionparamszRule [{0}] in NAT [{1}]Tz[Run the [gcloud compute operations describe] command to check the status of this operation.)kindis_asyncdetailszcompute.routersz Creating Rule [{0}] in NAT [{1}] )%r   ComputeApiHolderReleaseTrackclientmessagesapitools_clientroutersr   ResolveAsResourcer   ComputeRoutersGetRequestGetAsDictrule_numbernatr   FindNatOrRaiser   CreateRuleMessagerulesappendPatchComputeRoutersPatchRequestr*   r+   NameREGISTRYParsenameasync_r   CreatedResourceformatr   Pollerr   WaitFor)selfargsholderr7   service
router_refrequest_typer,   r>   nat_nameexisting_natruleresultoperation_reftarget_router_refoperation_pollers                   r&   Runz
Create.Run5   s   **4+<+<+>?F}}%%Hmm++33G2249I9IJJ44L[[<
(9(9(;<=F""KxxH,,VX>L((v|DDd#]]++&&$$??$!	 	, 	#$F &&,,-!)) ''
 - M {{	
(//XF3	4 m((..$!)) ''
 /  }}W.?@>>-*11+xHJ Jr(   N)__name__
__module____qualname____doc__classmethodr'   r\   r3   r(   r&   r   r   !   s     ,( (5Jr(   r   zO
        *{command}* is used to create a Rule on a Compute Engine NAT.
        a<          Create a rule to use the IP Address address-1 to talk to destination IPs
        in the CIDR Range "203.0.113.0/24".

          $ {command} 1 --nat=my-nat --router=my-router --region=us-central1
            --match='inIpRange(destination.ip, "203.0.113.0/24")'
            --source-nat-active-ips=a1
        )DESCRIPTIONEXAMPLESN)"r`   
__future__r   r   r   googlecloudsdk.api_lib.computer   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   r   *googlecloudsdk.command_lib.compute.routersr   /googlecloudsdk.command_lib.compute.routers.natsr   5googlecloudsdk.command_lib.compute.routers.nats.rulesr   r   googlecloudsdk.corer   r   ReleaseTracksr5   ALPHABETAGACreateCommandr   detailed_helpr3   r(   r&   <module>rt      s    9 &  ' 7 < . ( E M F V M # ) T..33T5F5F5I5IFJT FJFJV		 r(   