
                         j   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rSS
Kr\R$                  " \R&                  R(                  \R&                  R*                  \R&                  R,                  5       " S S\R.                  5      5       rSSSS.\l        g
)z/Command for expanding IP range of a subnetwork.    )absolute_import)division)unicode_literals)base_classes)base)
exceptions)flags)
console_ioNc                   V    \ rS rSrSrSr\S 5       rS rS r	S r
S rS	 rS
 rS rSrg)ExpandIpRange   z Expand IP range of a subnetwork.Nc                     [         R                  " 5       U l        U R                  R                  U5        UR	                  S[
        SSS9  g )N--prefix-lengthzThe new prefix length of the subnet. It must be smaller than the original and in the private address space 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16 defined in RFC 1918.T)typehelprequired)r	   SubnetworkArgumentSUBNETWORK_ARGAddArgumentadd_argumentint)clsparsers     7lib/surface/compute/networks/subnets/expand_ip_range.pyArgsExpandIpRange.Args&   sK    113C""6*
C       c                    [         R                  " U R                  5       5      nUR                  nU R	                  UR
                  5      nU R                  R                  XR                  5      nU R                  X55      nU R                  UR                  5       Xd5      nU R                  UR                  5       Xg5        U R                  X5U5      nUR                  UR                  R                   SU4/5      $ )z,Issues requests for expanding IP CIDR range.ExpandIpCidrRange)r   ComputeApiHolderReleaseTrackclient_ValidatePrefixLengthprefix_lengthr   ResolveAsResource	resources_GetOriginalIpCidrRange_InferNewIpCidrRangeName_PromptToConfirm_CreateExpandIpCidrRangeRequestMakeRequestsapitools_clientsubnetworks)	selfargsholderr"   new_prefix_lengthsubnetwork_reforiginal_ip_cidr_rangenew_ip_cidr_rangerequests	            r   RunExpandIpRange.Run4   s    **4+<+<+>?F]]F2243E3EF((:: N!99 115J5J2263DFG!7!7!C!C!4g!?  @ A Ar   c                 R    SUs=::  a  S::  d  O  [         R                  " SS5      eU$ )Nr      r   z+Prefix length must be in the range [0, 29].)r   InvalidArgumentException)r/   r2   s     r   r#   #ExpandIpRange._ValidatePrefixLengthG   s1    !'R'//

79 9 r   c                     U R                  X5      nU(       d<  [        R                  " SR                  UR	                  5       UR
                  S95      eUR                  $ )Nz3Subnet [{subnet}] was not found in region {region}.)subnetregion)_GetSubnetworkcompute_exceptionsArgumentErrorformatr)   r?   ipCidrRange)r/   r"   r3   
subnetworks       r   r'   %ExpandIpRange._GetOriginalIpCidrRangeN   sa    $$V<J,,
?
F
F#((*>3H3H G JK K !!!r   c                     SR                  UR                  S5      S   U5      n[        R                  " [        R
                  " U5      SS9n[        R
                  " U5      $ )Nz{0}/{1}/r   F)strict)rC   split	ipaddressIPv4Networksix	text_type)r/   subnet_namer4   r2   unmasked_new_ip_rangenetworks         r   r(   "ExpandIpRange._InferNewIpCidrRangeW   sY    %,,$$S)!, ##CMM2G$H+02G==!!r   c                     SnUR                  XU5      n[        R                  " USS9(       d  [        R                  " S5      eg )NzThe IP range of subnetwork [{0}] will be expanded from {1} to {2}. This operation may take several minutes to complete and cannot be undone.T)messagedefaultzOperation aborted by user.)rC   r
   PromptContinuerA   AbortedError)r/   subnetwork_namer4   r5   prompt_message_templateprompt_messages         r   r*   ExpandIpRange._PromptToConfirma   sM    	   -331BDN$$^TJ++,HII Kr   c                     UR                   R                  US9nUR                   R                  UR                  5       UUR                  UR
                  S9$ )N)rD   )rE   #subnetworksExpandIpCidrRangeRequestprojectr?   )messages#SubnetworksExpandIpCidrRangeRequest*ComputeSubnetworksExpandIpCidrRangeRequestr)   r^   r?   )r/   r"   r3   r5   request_bodys        r   r+   -ExpandIpRange._CreateExpandIpCidrRangeRequestl   s]    ??FF% G 'L??EE!&&(,8&&$$	 F & &r   c                     UR                   R                  SUR                  R                  UR                  UR
                  UR                  5       S94nUR                  U/5      nU(       a  US   $ S $ )NGet)r^   r?   rE   r   )r-   r.   r_   ComputeSubnetworksGetRequestr^   r?   r)   r,   )r/   r"   r3   get_requestobjectss        r   r@   ExpandIpRange._GetSubnetworkv   su    **44"**!((%**, 	5 	./K !!;-0G 71:*d*r    )__name__
__module____qualname____firstlineno____doc__r   classmethodr   r7   r#   r'   r(   r*   r+   r@   __static_attributes__rj   r   r   r   r      sC     ). A&""	J&+r   r   z2Expand the IP range of a Compute Engine subnetworka  
*{command}* expands the IP range of a VPC subnetwork.

For more information about expanding a subnet, see [Expanding a primary IP
range](https://cloud.google.com/vpc/docs/using-vpc#expand-subnet).

This command doesn't work for secondary subnets or for subnets that are used
exclusively for load balancer proxies. For more information, see [Proxy-only
subnets for load balancers](https://cloud.google.com/load-balancing/docs/l7-internal/proxy-only-subnets).
zq
To expand the IP range of ``SUBNET'' to /16, run:

  $ {command} SUBNET --region=us-central1 --prefix-length=16
)briefDESCRIPTIONEXAMPLES)ro   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computerA   3googlecloudsdk.command_lib.compute.networks.subnetsr	   googlecloudsdk.core.consoler
   rK   rM   ReleaseTracksr!   GABETAALPHASilentCommandr   detailed_helprj   r   r   <module>r      s    6 &  ' 7 ( < O E 2  
 D%%(($*;*;*@*@%%++-`+D&& `+-`+H B	 r   