
    E                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	K	Jr  SS
KJr  SS
KJr  SSKrSSKJr  S r\
R(                  \
R*                  " \
R,                  R.                  5       " S S\
R0                  5      5       5       r\
R*                  " \
R,                  R4                  5       " S S\5      5       r\
R*                  " \
R,                  R8                  5       " S S\5      5       rg)z#Command for reserving IP addresses.    )absolute_import)division)unicode_literals)base_classes)	constants)name_generator)base)
exceptions)flagsN)zipc                    [         R                  " SS9U l        U R                  R                  USS9  [         R                  " U5        UR
                  R                  [         R                  5        [         R                  " USS9  [         R                  " U5        [         R                  " U5        [         R                  " X5        [         R                  " U5        [         R                  " 5       U l        U R                  R                  U5        [         R                  " 5       U l        U R                   R                  U5        U(       a%  [         R"                  " 5       R                  U5        gg)zArgument parsing.F)requiredcreate)operation_typeN)r   AddressArgumentADDRESSES_ARGAddArgumentAddDescriptiondisplay_infoAddCacheUpdaterAddressesCompleterAddAddressesAndIPVersionsAddNetworkTierAddPrefixLength
AddPurposeAddIPv6EndPointTypeSubnetworkArgumentSUBNETWORK_ARGNetworkArgumentNETWORK_ARGIpCollectionArgument)clsparsersupport_psc_google_apisinclude_ip_collections       'lib/surface/compute/addresses/create.py_Argsr'       s    ++U;#x@v%%e&>&>?!!&59v63F#//1#  ())+#///f%	 ,,V4     c                   Z    \ rS rSrSrSrSrSrSrSr	\
S 5       rS rS rS	 rS
 rS rSrg)Create7   a3  Reserve IP addresses.

*{command}* is used to reserve one or more IP addresses. Once an IP address
is reserved, it will be associated with the project until it is released
using 'gcloud compute addresses delete'. Ephemeral IP addresses that are in
use by resources in the project can be reserved using the '--addresses' flag.

## EXAMPLES
To reserve three IP addresses in the 'us-central1' region, run:

  $ {command} address-1 address-2 address-3 --region=us-central1

To reserve ephemeral IP addresses '162.222.181.198' and '23.251.146.189' which
are being used by virtual machine instances in the 'us-central1' region, run:

  $ {command} --addresses=162.222.181.198,23.251.146.189 --region=us-central1

In the above invocation, the two addresses will be assigned random names.

To reserve an IP address named subnet-address-1 from the subnet 'default' in
the 'us-central1' region, run:

  $ {command} subnet-address-1 \
    --region=us-central1 \
    --subnet=default

To reserve an IP range '10.110.0.0/16' from the network 'default' for
'VPC_PEERING', run:

  $ {command} ip-range-1 --global --addresses=10.110.0.0 --prefix-length=16 \
    --purpose=VPC_PEERING --network=default

To reserve any IP range with prefix length '16' from the network 'default' for
'VPC_PEERING', run:

  $ {command} ip-range-1 --global --prefix-length=16 --purpose=VPC_PEERING \
    --network=default

To reserve an address from network 'default' for PRIVATE_SERVICE_CONNECT, run:

  $ {command} psc-address-1 --global --addresses=10.110.0.10 \
    --purpose=PRIVATE_SERVICE_CONNECT --network=default

NTFc                 D    [        U UU R                  U R                  S9  g )N)r$   r%   )r'   _support_psc_google_apis_include_ip_collection)r"   r#   s     r&   ArgsCreate.Argsn   s"    	 # < <!88	:r(   c                    UR                   (       aw  UR                   R                  5       nU[        R                  ;   a%  UR                  R                  UR                   5      $ [        R                  " SSR                  US95      eg )Nz--network-tierzInvalid network tier [{tier}])tier)	network_tierupperr   !NETWORK_TIER_CHOICES_FOR_INSTANCEAddressNetworkTierValueValuesEnumr
   InvalidArgumentExceptionformat)selfmessagesargsr3   s       r&   ConstructNetworkTierCreate.ConstructNetworkTierv   sx    &&,,.l	DD	D::4;L;LMM11+222EG 	G r(   c                 Z   [         R                  " U R                  5       5      nUR                  nU R	                  U5      u  pEUR
                  (       d  XAl        U R                  R                  UUR                  [        R                  " U5      S9n/ n[        XV5       H  u  pU R                  UR                  XU	UR                  5      n
U	R                  5       S:X  aK  UR                  UR                   R"                  SUR                  R%                  XR&                  S945        M  U	R                  5       S:X  d  M  UR                  UR                   R(                  SUR                  R+                  U
U	R,                  U	R&                  S945        M     UR/                  U5      $ )z.Issues requests necessary to create Addresses.)scope_listercompute.globalAddressesInsert)addressprojectcompute.addresses)rC   regionrD   )r   ComputeApiHolderReleaseTrackclient_GetNamesAndAddressesnamer   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerr   
GetAddressr;   
Collectionappendapitools_clientglobalAddresses#ComputeGlobalAddressesInsertRequestrD   	addressesComputeAddressesInsertRequestrF   MakeRequests)r:   r<   holderrI   namesrV   address_refsrequestsrC   address_refaddress_msgs              r&   Run
Create.Run   s   **4+<+<+>?F]]F11$7E99i%%77"88@ 8 BL
 H #I <OOFOOTK$*$4$46k 
			!%>	>//??LL%0:M:M M OP 	Q !!#':://998FF%0$/$6$6%0%8%8 G :; 	< != x((r(   c                    UR                   (       d*  UR                  (       d  [        R                  " SS/S5      eUR                  (       a  UR                  nO/UR                    Vs/ s H  n[        R
                  " 5       PM     nnUR                   (       a  UR                   nOS/[        UR                  5      -  n[        U5      [        U5      :w  a  [        R                  " SS5      eX$4$ s  snf )z-Returns names and addresses provided in args.NAMEz	--addressz.At least one name or address must be provided.N--addresseszJIf providing both, you must specify the same number of names as addresses.)rV   rK   r
   MinimumArgumentExceptionr   GenerateRandomNamelenBadArgumentException)r:   r<   rZ   _rV   s        r&   rJ   Create._GetNamesAndAddresses   s    >>$))//;

:< < yyiie =ANNKNq~002NeK~~..i &3tyy>)i
9~U#++
 
  Ls   (C2c                     X!R                   R                  R                  :w  a<  UUR                   R                  R                  :w  a  [        R
                  " SS5      eg g )N	--purposezPmust be GCE_ENDPOINT or SHARED_LOADBALANCER_VIP for regional internal addresses.)r6   PurposeValueValuesEnumGCE_ENDPOINTSHARED_LOADBALANCER_VIPr
   r8   )r:   r;   purposes      r&   CheckPurposeInSubnetworkCreate.CheckPurposeInSubnetwork   s_    ##::GGG//GG	H//
 ! !	H 	Hr(   c                    U R                  X5      nUR                  (       d  UcC  UR                  5       S:X  a/  UR                  R	                  UR                  =(       d    S5      nOSnUR
                  (       a(  UR                  (       a  [        R                  " SS5      eSnUR                  (       a;  UR                  (       d*  UR
                  (       d  [        R                  " SS/S5      eUR
                  (       a  UR                  5       S:X  a  [        R                  " SS5      eUR                  (       d  UR                  Ul        [        R                  " 5       R!                  X%5      R#                  5       n	UR$                  (       d?  UR                  R'                  UR                  =(       d    S5      nU R)                  X5        OSn	Sn
UR                  (       GaZ  UR                  R'                  UR                  =(       d    S	5      n[        R*                  " 5       R!                  X%5      R#                  5       n
XR                  R&                  R,                  :w  a  UR                  5       S
:X  a  [        R.                  " SS5      eS	UR                  R&                  R0                  0nU R2                  (       a#  UR                  R&                  R4                  US'   XR7                  5       ;  aC  [        R.                  " SSR9                  SR;                  UR=                  5       5      5      5      eSnUR$                  (       a%  UR                  R?                  UR$                  5      nSnUR$                  (       a!  UR                  R@                  RB                  nO.U	(       d  U
(       a   UR                  R@                  RD                  nUb   [F        RH                  " U5      nURL                  (       a  U(       a(  U(       d!  UR                  R@                  RB                  nO~Ub  WRN                  S:w  ak  XR                  R&                  R0                  :w  aH  UUR                  R&                  R,                  :w  a$  [        R.                  " SSR9                  US95      eURL                  (       dt  XR                  R&                  R0                  :X  a  [        RP                  " SS5      eXR                  R&                  R,                  :X  a  [        RP                  " SS5      eUR                  UURL                  URR                  UUURU                  5       UUU	U
US9nU RV                  (       aH  URX                  (       a7  [        RZ                  " 5       R!                  X%5      R#                  5       Ul.        U$ ! [J         a%    [        R.                  " SSR9                  US95      ef = f)a  Get and validate address setting.

Retrieve address resource from input arguments and validate the address
configuration for both external/internal IP address reservation/promotion.

Args:
  messages: The client message proto includes all required GCE API fields.
  args: argparse.Namespace, An object that contains the values for the
    arguments specified in the .Args() method.
  address: Address object.
  address_ref: Reference of the address.
  resource_parser: A resource parser used to parse resource name into url.

Returns:
  An address resource proto message.

Raises:
  ConflictingArgumentsException: If both network and subnetwork fields are
  set.
  MinimumArgumentException: Missing network or subnetwork with purpose
  field.
  InvalidArgumentException: The input argument is not set correctly or
  unable to be parsed.
  RequiredArgumentException: The required argument is missing from user
  input.
NrA   IPV4z	--networkz--subnetz if --purpose is specifiedz5[--subnet] may not be specified for global addresses.rm   VPC_PEERINGrE   z4network may not be specified for regional addresses.PRIVATE_SERVICE_CONNECTrk   z)must be {} for global internal addresses.z or rc   zInvalid IP address {e})e   z--prefix-lengthzqcan only be used with [--purpose VPC_PEERING/IPSEC_INTERCONNECT] or Internal/External IPv6 reservation. Found {e}z<prefix length is needed for reserving VPC peering IP ranges.zSprefix length is needed for reserving IP ranges for HA VPN over Cloud Interconnect.)rC   prefixLengthdescriptionnetworkTier	ipVersionrK   addressTypero   
subnetworknetworkipv6EndpointType)/r=   
ip_versionrQ   r6   IpVersionValueValuesEnumsubnetr~   r
   ConflictingArgumentsExceptionro   rd   rg   subnet_regionrF   r   r   rL   SelfLinkendpoint_typerl   rp   r   IPSEC_INTERCONNECTr8   rt   r-   ru   valuesr9   joinkeysIpv6EndpointTypeValueValuesEnumAddressTypeValueValuesEnumEXTERNALINTERNALipaddr	IPAddress
ValueErrorprefix_lengthversionRequiredArgumentExceptionry   Namer.   ip_collectionr!   ipCollection)r:   r;   r<   rC   r]   resource_parserr3   r   ro   subnetwork_urlnetwork_urlsupported_purposesipv6_endpoint_typeaddress_type
ip_addressr^   s                   r&   rP   Create.GetAddress   s   6 ,,X<L7?{/E/E/G708##<<T__ >D=CEj j{{t||44[*MMG||DLL//j0I0LN N {{				!%>	>--OQ 	Q(////1CC
!!) ""99$,, ;I:HJ%%h8nK|||  77 9F8EGg))+==
!!) 	$$;;NN	N!!#'::33DF F 8++BBNN
 ((55MM 6
7 335533 ++16&++$))+3- ,./ /
 #++KK


 L%%@@IIl	;%%@@IIl
%%g.
 	''BBKK?j00A5))@@LLL44GGH 11@@F AG A
 	
 	$$;;GG	G22JL 	L 
$$;;NN	N22  34 	4 ""''$$  !+ # -K ""t'9'9!&!;!;!=!O!O
"!!)  e  
113::W:E
 	

s   !W /W? )__name__
__module____qualname____firstlineno____doc__r   r   r    r-   r.   classmethodr/   r=   r_   rJ   rp   rP   __static_attributes__r   r(   r&   r*   r*   7   sR    +Z -.+! : :
)@6!Yr(   r*   c                        \ rS rSrSrSrSrSrg)
CreateBetaic  a   Reserve IP addresses.

*{command}* is used to reserve one or more IP addresses. Once an IP address
is reserved, it will be associated with the project until it is released
using 'gcloud compute addresses delete'. Ephemeral IP addresses that are in
use by resources in the project can be reserved using the '--addresses' flag.

## EXAMPLES
To reserve three IP addresses in the 'us-central1' region, run:

  $ {command} address-1 address-2 address-3 --region=us-central1

To reserve ephemeral IP addresses '162.222.181.198' and '23.251.146.189' which
are being used by virtual machine instances in the 'us-central1' region, run:

  $ {command} --addresses=162.222.181.198,23.251.146.189 --region=us-central1

In the above invocation, the two addresses will be assigned random names.

To reserve an IP address named subnet-address-1 from the subnet 'default' in
the 'us-central1' region, run:

  $ {command} subnet-address-1 --region=us-central1 --subnet=default

To reserve an IP address that can be used by multiple internal load balancers
from the subnet 'default' in the 'us-central1' region, run:

  $ {command} shared-address-1 --region=us-central1 --subnet=default \
    --purpose=SHARED_LOADBALANCER_VIP

To reserve an IP range '10.110.0.0/16' from the network 'default' for
'VPC_PEERING', run:

  $ {command} ip-range-1 --global --addresses=10.110.0.0 --prefix-length=16 \
    --purpose=VPC_PEERING --network=default

To reserve any IP range with prefix length '16' from the network 'default' for
'VPC_PEERING', run:

  $ {command} ip-range-1 --global --prefix-length=16 --purpose=VPC_PEERING \
    --network=default

To reserve an address from network 'default' for PRIVATE_SERVICE_CONNECT, run:

  $ {command} psc-address-1 --global --addresses=10.110.0.10 \
    --purpose=PRIVATE_SERVICE_CONNECT --network=default

Tr   N)r   r   r   r   r   r-   r.   r   r   r(   r&   r   r   c  s    /b "r(   r   c                       \ rS rSrSrSrSrg)CreateAlphai  a  Reserve IP addresses.

*{command}* is used to reserve one or more IP addresses. Once an IP address
is reserved, it will be associated with the project until it is released
using 'gcloud compute addresses delete'. Ephemeral IP addresses that are in
use by resources in the project can be reserved using the '--addresses' flag.

## EXAMPLES
To reserve three IP addresses in the 'us-central1' region, run:

  $ {command} address-1 address-2 address-3 --region=us-central1

To reserve ephemeral IP addresses '162.222.181.198' and '23.251.146.189' which
are being used by virtual machine instances in the 'us-central1' region, run:

  $ {command} --addresses=162.222.181.198,23.251.146.189 --region=us-central1

In the above invocation, the two addresses will be assigned random names.

To reserve an IP address named subnet-address-1 from the subnet 'default' in
the 'us-central1' region, run:

  $ {command} subnet-address-1 --region=us-central1 --subnet=default

To reserve an IP address that can be used by multiple internal load balancers
from the subnet 'default' in the 'us-central1' region, run:

  $ {command} shared-address-1 --region=us-central1 --subnet=default \
    --purpose=SHARED_LOADBALANCER_VIP

To reserve an IP range '10.110.0.0/16' from the network 'default' for
'VPC_PEERING', run:

  $ {command} ip-range-1 --global --addresses=10.110.0.0 --prefix-length=16 \
    --purpose=VPC_PEERING --network=default

To reserve any IP range with prefix length '16' from the network 'default' for
'VPC_PEERING', run:

  $ {command} ip-range-1 --global --prefix-length=16 --purpose=VPC_PEERING \
    --network=default

To reserve an address from network 'default' for PRIVATE_SERVICE_CONNECT, run:

  $ {command} psc-address-1 --global --addresses=10.110.0.10 \
    --purpose=PRIVATE_SERVICE_CONNECT --network=default
Tr   N)r   r   r   r   r   r-   r   r   r(   r&   r   r     s    .` "r(   r   )r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   rN   ,googlecloudsdk.command_lib.compute.addressesr   	six.movesr   r'   UniverseCompatibleReleaseTracksrH   GACreateCommandr*   BETAr   ALPHAr   r   r(   r&   <module>r      s    * &  ' 7 4 9 ( . E >  5. D%%(()gT g * gT	 D%%**+4  4  ,4 n D%%++,2"* 2" -2"r(   