
    $                         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Update 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)Update)Update a worker pool used by Cloud Build.z{description}z          To change the machine type and disk size of workers in a worker pool named wp1, run:

            $ {command} wp1 --region=us-central1                 --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   AddWorkerpoolUpdateArgsr   ReleaseTrackGAdisplay_info	AddFormatparsers    )lib/surface/builds/worker_pools/update.pyArgszUpdate.Args4   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.
    )_UpdateWorkerPoolFirstGenr   selfargss     r    Runz
Update.RunF   s     %T4+<+<+>??r"   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr!   r)    r"   r    r   r   "   s2     2 	-  "@r"   r   c                   &    e Zd ZdZed        Zd Zy)
UpdateBetar   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UpdateBeta.ArgsX   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$   r6      r5   zifor generation=2 please use the gcloud command "gcloud builds worker-pools apply" to update a worker poolz=please use one of the following valid generation values: 1, 2
generationr%   r   r   InvalidArgumentExceptionr&   s     r    r)   zUpdateBeta.Runp   h     !&tT->->-@AA!//
9  
-
-G r"   Nr*   r+   r,   r-   r/   r!   r)   r0   r"   r    r2   r2   T   s    1 .r"   r2   c                   &    e Zd ZdZed        Zd Zy)UpdateAlphaz*Update a private pool used by Cloud Build.c                     t        j                  | t        j                  j                        } | j                  ddt        d       | j                  j                  d       yr4   )	r   r   r   r   ALPHAr;   r<   r   r   r   s    r    r!   zUpdateAlpha.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>   r@   r&   s     r    r)   zUpdateAlpha.Run   rC   r"   NrD   r0   r"   r    rF   rF      s    2 .r"   rF   c           	      ,   | j                   }| j                  }|s2t        j                  j                  j                  j                         }t        j                  |      }t        j                  |      }t        j                  j                  j                  j                  d      }|j                         }| j                  -	 t        j                  | j                  |j                        }nL|j+                         |_        |j/                         }	| j0                  | j0                  |	_        | j4                  $t7        j8                  | j4                        |	_        |	|j,                  _        |j?                         }
| j@                  | j@                  r)|tB        jD                  jF                  k(  rB| jH                  r6|j>                  jJ                  jL                  |
_'        |
|j,                  _(        | j@                  r6|j>                  jJ                  jR                  |
_'        |
|j,                  _(        tT        jV                  jY                  ddt        jZ                  |   |||d      }t        j\                  |      }|j_                  |ja                         |djc                  |      	      }|jd                  jg                  |      }tT        jV                  ji                  |jj                  d
      }tm        jn                  tm        jp                  |jd                  |jr                        |d      }t%        jt                  |       |S # t         j"                  $ r&}t$        j&                  j)                  d       |d}~ww xY w)a>  Updates a Worker Pool First Generation.

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

  Returns:
    A Worker Pool First Generation resource.
  T)requiredNz*
Failed to parse configuration from file.
z)cloudbuild.projects.locations.workerPools)
projectsIdlocationsIdworkerPoolsId)
collectionapi_versionparams,)name
workerPool
updateMaskz(cloudbuild.projects.locations.operations)rO   zUpdating worker pool);WORKER_POOLregionr   VALUESbuilds	GetOrFailr   GetClientInstanceGetMessagesModulecoreprojectGet
WorkerPoolconfig_from_filer   LoadWorkerpoolConfigFromPathr   ParseProtoExceptionr   errPrintPrivatePoolV1ConfigprivatePoolV1ConfigWorkerConfigworker_machine_typemachineTypeworker_disk_sizecompute_utils	BytesToGb
diskSizeGbworkerConfigNetworkConfigpublic_egressr   r   r   no_external_ipEgressOptionValueValuesEnumNO_PUBLIC_EGRESSegressOptionnetworkConfigPUBLIC_EGRESSr   REGISTRYParseRELEASE_TRACK_TO_API_VERSIONMessageToFieldPaths2CloudbuildProjectsLocationsWorkerPoolsPatchRequestRelativeNamejoinprojects_locations_workerPoolsPatchParseRelativeNamerS   r
   WaitForCloudOperationPollerprojects_locations_operationsUpdatedResource)r(   release_trackwp_name	wp_regionclientmessagesparentwprd   worker_configncwp_resourceupdate_maskreq
updated_opop_resource
updated_wps                    r    r%   r%      s    'kk)	!!((//99;I,,];&..}=(!!))--t-<& "	&99


!4!46b &99;B))+M+"&":":m(!.!8!8


"m +8B'				!B&t/A/A**---$2E2E 
 
 
<
<
M
M 	o .0b*

 
 
<
<
J
J 	o .0b* ""((
<!>>}M""	 ) 	+  33B7+CC##%+& 	D 	(#
 44::3?*""44oo"L 5 N+~~!!&"G"G"("F"FH)+*
 k"	s !44 	ggmmBCis   *M N-!NNN)"r-   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.api_lib.computer	   rl   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   r   %googlecloudsdk.command_lib.cloudbuildr   googlecloudsdk.corer   r   r   ReleaseTracksr   r   UniverseCompatibleUpdateCommandr   r:   r2   rH   rF   r%   r0   r"   r    <module>r      s    " &  ' C = ? A . ( . B # * ) D%%(()-@T -@  *-@` D%%**+2 2 ,2j D%%++,2& 2 -2jUr"   