
    [                     D   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  ej*                  ej,                  j.                        ej0                   G d dej2                                      Zd Zy)zCreate worker pool command.    )absolute_import)division)unicode_literals)cloudbuild_exceptions)workerpool_config)client_util)
input_util)waiter)base)
exceptions)log)
properties)	resourcesc                   &    e Zd ZdZed        Zd Zy)CreateAlphaz-Create a private pool for use by Cloud Build.c                     | j                  ddd       | j                  dd       | j                  dd	t        d
       | j                  j                  d       y)zRegister 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.
    z--fileTz;The YAML file to use as the worker pool configuration file.)requiredhelpz--regionzRegion for Cloud Build.)r   --generation   zGeneration of the worker pool.)defaulttyper   z
          table(
            name.segment(-1),
            createTime.date('%Y-%m-%dT%H:%M:%S%Oz', undefined='-'),
            state
          )
        N)add_argumentintdisplay_info	AddFormat)parsers    (lib/surface/builds/worker_pools/apply.pyArgszCreateAlpha.Args&   sx     J  L &  ( .	   !! #     c                     |j                   dk(  rt        j                  dd      |j                   dk(  rt        |      S t        j                  dd      )zThis 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.
       r   zzfor generation=1 please use the gcloud commands "gcloud builds worker-pools create" or "gcloud builds worker-pools update"r   z=please use one of the following valid generation values: 1, 2)
generationr   InvalidArgumentException_CreateWorkerPoolSecondGen)selfargss     r   RunzCreateAlpha.RunC   s^     !//
I 
 !'--

-
-G r    N)__name__
__module____qualname____doc__staticmethodr   r(    r    r   r   r   !   s     6 8r    r   c           	      f   | j                   }|s2t        j                  j                  j                   j	                         }t        j                         }|j                  }	 t        j                  | j                  |j                        }|j                  ]|j                  j                  G|j                  j                  j                  r'|j                  j                  d|j                  _        t+        j,                  | j                        }|d   }t.        j0                  j3                  ddt
        j4                  t        j                  j6                  j8                  j;                  d      ||d      }t        j<                  |      }	|j?                  |jA                         |d	jC                  |	      d
      }
|jD                  jG                  |
      }t.        j0                  jI                  |jJ                  d      }tM        jN                  tM        jP                  |jD                  |jR                        |djU                  | j                  |jA                                     }|S # t         j"                  $ r&}t$        j&                  j)                  d       |d}~ww xY w)zCreates a worker pool second generation.

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

  Returns:
    A worker pool second 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.
namez1cloudbuild.projects.locations.workerPoolSecondGen)r   )
projectsIdlocationsIdworkerPoolSecondGenId)
collectionapi_versionparams,)r0   workerPoolSecondGen
updateMaskallowMissingz(cloudbuild.projects.locations.operations)r4   z0Applying {file} as worker pool second gen {name})filer0   )+regionr   VALUESbuilds	GetOrFailcloudbuild_v2_utilGetClientInstanceMESSAGES_MODULEr   LoadWorkerpoolConfigFromPathr;   WorkerPoolSecondGennetworkprivateServiceConnectrouteAllTrafficpublicIpAddressDisabledr   ParseProtoExceptionr   errPrintr	   LoadYamlFromPathr   REGISTRYParseGA_API_VERSIONcoreprojectGetMessageToFieldPaths:CloudbuildProjectsLocationsWorkerPoolSecondGenPatchRequestRelativeNamejoin&projects_locations_workerPoolSecondGenPatchParseRelativeNamer0   r
   WaitForCloudOperationPollerprojects_locations_operationsformat)r'   	wp_regionclientmessageswpsgrJ   	yaml_dataworkerpoolsecondgen_idwp_resourceupdate_maskreq
updated_opop_resource
updated_wps                 r   r%   r%   ]   sL    kk)	!!((//99;I//1&##(99		8//D 	 LL..:LL..>>LL008-1dll* ))$))4)$V,""((
D$33"))..66::D:I"#9	 ) 	+ #66t<+KK##%+&	 	L 	# <<BB3G*""44oo"L 5 + ~~!!

7
7

.
. 8??yy{779 @ 	* 
] 
	2	2 GGMM	/0 Is   "BI7 7J0
!J++J0N)r,   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   $googlecloudsdk.api_lib.cloudbuild.v2r   r@   r	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   r   googlecloudsdk.corer   r   r   ReleaseTracksReleaseTrackALPHAUniverseCompatibleCreateCommandr   r%   r.   r    r   <module>ru      s    " &  ' C ? R ; . ( . # * ) D%%++,7$$$ 7  -7tLr    