
    o2                         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j.                  ej0                  j2                        ej4                   G d dej6                                      Z ej.                  ej0                  j:                         G d de             Z ej.                  ej0                  j>                         G d de             Z d Z!y)zCreate worker pool command.    )absolute_import)division)unicode_literals)cloudbuild_exceptions)cloudbuild_util)workerpool_config)utils)waiter)base)
exceptions)workerpool_flags)log)
properties)	resourcesc                   0    e Zd ZdZdddZed        Zd Zy)Createz3Create a worker pool for use by Google Cloud Build.{description}a            To create a worker pool named `wp1` in region `us-central1`, run:

            $ {command} wp1 --region=us-central1

          To create a worker pool in project `p1` in region `us-central1` where workers are of machine type
          `e2-standard-2` and are peered to the VPC network `projects/123/global/networks/default` within the IP range `192.168.0.0/28`
          and have a disk size of 64GB, run:

            $ {command} wp1 --project=p1 --region=us-central1                 --peered-network=projects/123/global/networks/default                 --peered-network-ip-range=192.168.0.0/28
                --worker-machine-type=e2-standard-2                 --worker-disk-size=64GB
          DESCRIPTIONEXAMPLESc                     t        j                  | t        j                  j                        } | j
                  j                  d       y)Register flags for this command.

    Args:
      parser: An argparse.ArgumentParser-like object. It is mocked out in order
        to capture some information, but behaves like an ArgumentParser.
    
          table(
            name.segment(-1),
            createTime.date('%Y-%m-%dT%H:%M:%S%Oz', undefined='-'),
            state
          )
        N)r   AddWorkerpoolCreateArgsr   ReleaseTrackGAdisplay_info	AddFormatparsers    )lib/surface/builds/worker_pools/create.pyArgszCreate.Args:   s?     55f6:6G6G6J6JLF
!! #     c                 6    t        || j                               S )This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    )_CreateWorkerPoolFirstGenr   selfargss     r!   Runz
Create.RunL   s     %T4+<+<+>??r#   N__name__
__module____qualname____doc__detailed_helpstaticmethodr"   r*    r#   r!   r   r   "   s2     < %-&  "@r#   r   c                   &    e Zd ZdZed        Zd Zy)
CreateBetaz,Create a worker pool for use by Cloud Build.c                     t        j                  | t        j                  j                        } | j                  ddt        d       | j                  j                  d       yr   --generation   zGeneration of the worker pool.)defaulttypehelpr   N)	r   r   r   r   BETAadd_argumentintr   r   r   s    r!   r"   zCreateBeta.Args^   s`     55f6:6G6G6L6LNF
.	   !! # r#   c                     |j                   dk(  rt        || j                               S |j                   dk(  rt        j                  dd      t        j                  dd      r%   r8      r7   zifor generation=2 please use the gcloud command "gcloud builds worker-pools apply" to create a worker poolz=please use one of the following valid generation values: 1, 2
generationr&   r   r   InvalidArgumentExceptionr'   s     r!   r*   zCreateBeta.Runv   h     !&tT->->-@AA!//
9  
-
-G r#   N)r,   r-   r.   r/   r1   r"   r*   r2   r#   r!   r4   r4   Z   s    4 .r#   r4   c                   0    e Zd ZdZdddZed        Zd Zy)CreateAlphaz-Create a private pool for use by Cloud Build.r   a  
        * Private pools

        To create a private pool named `pwp1` in region `us-central1`, run:

          $ {command} pwp1 --region=us-central1

        To create a private pool in project `p1` in region `us-central1` where workers are of machine type
        `e2-standard-2` and are peered to the VPC network `projects/123/global/networks/default` within the IP range `192.168.0.0/28`
        and have a disk size of 64GB, run:

          $ {command} pwp1 --project=p1 --region=us-central1 --peered-network=projects/123/global/networks/default --peered-network-ip-range=192.168.0.0/28 --worker-machine-type=e2-standard-2 --worker-disk-size=64GB

        To create a private pool in project `p1` in region `us-central1` where workers are of machine type
        `e2-standard-2` and are peered to the network attachment
        `projects/p1/regions/us-central1/networkAttachments/na`. The workers don't
        have public IP address and all the traffic is routed to the network attachment.

          $ {command} pwp1 --project=p1 --region=us-central1               --network-attachment=projects/p1/regions/us-central1/networkAttachments/na               --route-all-traffic               --disable-public-ip-address               --worker-machine-type=e2-standard-2
        r   c                     t        j                  | t        j                  j                        } | j                  ddt        d       | j                  j                  d       yr6   )	r   r   r   r   ALPHAr=   r>   r   r   r   s    r!   r"   zCreateAlpha.Args   s`     55f6:6G6G6M6MOF
.	   !! # r#   c                     |j                   dk(  rt        || j                               S |j                   dk(  rt        j                  dd      t        j                  dd      r@   rB   r'   s     r!   r*   zCreateAlpha.Run   rE   r#   Nr+   r2   r#   r!   rG   rG      s/    5 %-:  .r#   rG   c           	      ^	   | j                   }| j                  }|s2t        j                  j                  j                  j                         }t        j                  |      }t        j                  |      }|j                         }| j                  	 t        j                  | j                  |j                        }|j                  }|t        j                  j                   k(  rI|j"                  =|j"                  j$                  r'|j"                  j&                  d|j"                  _        n|j3                         |_        |j5                         }	| j6                  .| j6                  |	_        | j:                  | j:                  |	_        | j>                  s)|t        j                  j@                  k(  r1| jB                  r%|j4                  jD                  jF                  |	_$        |	|j                  _%        |jM                         }
| jN                  | jN                  |
_(        | jR                  $tU        jV                  | jR                        |
_,        |
|j                  _-        |t        j                  j                   k(  r|j]                         }| j^                  r| j^                  |_0        | jb                  rd|_        | jd                  rd|_        d|_        | j^                  s| jb                  s| jd                  r"d|j                  _%        ||j                  _        t        j                  jf                  jh                  jk                  d      }tl        jn                  jq                  d||      }|jr                  jq                  |ju                  ||jw                         |            }tl        jn                  jy                  |jz                  d	      }t}        j~                  t}        j                  |jr                  |j                        |d
d      }tl        jn                  j                  ddt        j                  |   |||d      }t-        j                  |       |S # t(        j*                  $ r&}t,        j.                  j1                  d       |d}~ww xY w)a>  Creates a Worker Pool First Generation.

  Args:
    args: an argparse namespace. All the arguments that were provided to the
        create command invocation.
    release_track: The desired value of the enum
      googlecloudsdk.calliope.base.ReleaseTrack.

  Returns:
    A Worker Pool First Generation resource.
  NTz
Failed to parse configuration from file. If you were a Private Preview user, note that the format for this file has changed slightly for GA.
)requiredzcloudbuild.projects.locations)
collection
projectsIdlocationsId)
workerPoolparentworkerPoolIdz(cloudbuild.projects.locations.operations)rM   zCreating worker pooli6 )max_wait_msz)cloudbuild.projects.locations.workerPools)rN   rO   workerPoolsId)rM   api_versionparams)EWORKER_POOLregionr   VALUESbuilds	GetOrFailr   GetClientInstanceGetMessagesModule
WorkerPoolconfig_from_filer   LoadWorkerpoolConfigFromPathprivatePoolV1Configr   r   rI   privateServiceConnectrouteAllTrafficpublicIpAddressDisabledr   ParseProtoExceptionr   errPrintPrivatePoolV1ConfigNetworkConfigpeered_networkpeeredNetworkpeered_network_ip_rangepeeredNetworkIpRangeno_public_egressr   no_external_ipEgressOptionValueValuesEnumNO_PUBLIC_EGRESSegressOptionnetworkConfigWorkerConfigworker_machine_typemachineTypeworker_disk_sizecompute_utils	BytesToGb
diskSizeGbworkerConfigPrivateServiceConnectnetwork_attachmentnetworkAttachmentdisable_public_ip_addressroute_all_trafficcoreprojectGetr   REGISTRYr   projects_locations_workerPools3CloudbuildProjectsLocationsWorkerPoolsCreateRequestRelativeNameParseRelativeNamenamer
   WaitForCloudOperationPollerprojects_locations_operationsParseRELEASE_TRACK_TO_API_VERSIONCreatedResource)r)   release_trackwp_name	wp_regionclientmessageswpconfigrf   network_configworker_configprivate_service_connectrQ   parent_resource
created_opop_resource
created_wpwp_resources                     r!   r&   r&      s    'kk)	!!((//99;I,,];&..}=( "	&99


!4!4b
 %%f
4,,22
2**6**::**BBJ?C$$< &99;B++-N&%)%8%8n"		%	%	1.2.J.J+**---$2E2E 
 
 
<
<
M
M ! ,:B())+M+"&":":m(!.!8!8


"!m*7B'))/// ( > > @		 	 484K4K1		'	':>7			 ;?726/

!
!++## 04,7N4!!))--t-<& &&--0 . / 44;;BB --/ C  !* ""44oo"L 5 N+~~!!&"G"G"("F"FH)	* ""((
<!>>}M""	 ) 	+ k"	q !44 	ggmm12 is   BQ3 3R,!R''R,N)"r/   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.api_lib.computer	   rx   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   r   %googlecloudsdk.command_lib.cloudbuildr   googlecloudsdk.corer   r   r   ReleaseTracksr   r   UniverseCompatibleCreateCommandr   r<   r4   rI   rG   r&   r2   r#   r!   <module>r      s    " &  ' C = ? A . ( . B # * ) D%%(()3@T 3@  *3@l D%%**+2 2 ,2j D%%++,O& O -Od}r#   