
    8              	          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 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ZdZej>                   ej@                  ejB                  jD                         e
jF                  e
jH                  jJ                         G d dejL                  e
jN                                             Z(ej>                   ej@                  ejB                  jR                         e
jF                  e
jH                  jR                         G d de(                           Z*ej>                   ej@                  ejB                  jV                         e
jF                  e
jH                  jX                         G d de(                           Z-y)zdeployments update command.    )absolute_import)division)unicode_literals)
exceptions)dm_api_util)dm_base)	dm_labels)apis)base)alpha_flags)dm_util)dm_write)flags)importer)	arg_utils)labels_util)log)
propertiesNi  c                      e Zd ZdZddiZ ej                   ej                  dd      j                  j                        Z ej                  d ej                  dd      j                  j                  dd	      Z ej                  d ej                  dd
      j                  j                  dd	      Zeej&                  j(                  fd       Zd Zd Zd Zy)UpdateUpdate a deployment based on a provided config file.

  This command will update a deployment with the new config file provided.
  Different policies for create, update, and delete policies can be specified.
  EXAMPLESa  
To update an existing deployment with a new config YAML file, run:

  $ {command} my-deployment --config=new_config.yaml

To update an existing deployment with a new config template file, run:

  $ {command} my-deployment --template=new_config.{jinja|py}

To update an existing deployment with a composite type as a new config, run:

  $ {command} my-deployment --composite-type=<project-id>/composite:<new-config>


To preview an update to an existing deployment without actually modifying the resources, run:

  $ {command} my-deployment --config=new_config.yaml --preview

To apply an update that has been previewed, provide the name of the previewed deployment, and no config file:

  $ {command} my-deployment

To specify different create, update, or delete policies, include any subset of the following flags:

  $ {command} my-deployment --config=new_config.yaml --create-policy=acquire --delete-policy=abandon

To perform an update without waiting for the operation to complete, run:

  $ {command} my-deployment --config=new_config.yaml --async

To update an existing deployment with a new config file and a fingerprint, run:

  $ {command} my-deployment --config=new_config.yaml --fingerprint=deployment-fingerprint

Either the `--config`, `--template`, or `--composite-type` flag is required unless launching an already-previewed update to a deployment. If you want to update a deployment's metadata, such as the labels or description, you must run a separate command with `--update-labels`, `--remove-labels`, or `--description`, as applicable.

More information is available at https://cloud.google.com/deployment-manager/docs/deployments/updating-deployments.
deploymentmanagerv2z--create-policyz;Create policy for resources that have changed in the updatezcreate-or-acquire)help_strdefaultv2betac                    t        j                  |        t        j                  |        t        j                  |        | j	                  ddd       | j                         }t        j                  |       |t        j                  j                  t        j                  j                  fv r|j	                  ddd       t        j                  | d	       | j	                  d
dddd       |t        j                  j                  t        j                  j                  fv r*t        j                  j                  j!                  |        n)t        j"                  j                  j!                  |        t        j$                  j                  j!                  |        t        j&                  |        | j(                  j+                  t         j,                         y)a\  Args is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use to add arguments that go
          on the command line after this command. Positional arguments are
          allowed.
      version: The version this tool is running as. base.ReleaseTrack.GA
          is the default.
    z--descriptionz&The new description of the deployment.description)helpdestz--manifest-idzMManifest Id of a previous deployment. This flag cannot be used with --config.manifest_idF)enable_clearz	--previewzdPreview the requested update without making any changes to the underlying resources. (default=False)preview
store_true)r    r!   r   actionN)r   AddDeploymentNameFlagAddPropertiesFlagAddAsyncFlagadd_argumentadd_mutually_exclusive_groupAddConfigFlagsr   ReleaseTrackALPHABETAr   AddUpdateLabelsFlagsr   _create_policy_v2beta_flag_map
choice_argAddToParser_create_policy_flag_map_delete_policy_flag_mapAddFingerprintFlagdisplay_info	AddFormatRESOURCES_AND_OUTPUTS_FORMAT)parserversiongroups      4lib/surface/deployment_manager/deployments/update.pyArgszUpdate.Argss   s~    
'	F#	v
5   //1E	4$$**D,=,=,B,BCC
4	   $$V%@
0   4$$**D,=,=,B,BCC++66BB6J$$//;;FC
""--99&A	V$
!!%"D"DE    c                 H    |s t         j                  j                  d       yy)zCalled after resources are displayed if the default format was used.

    Args:
      resources_were_displayed: True if resources were displayed.
    z1No resources or outputs found in your deployment.N)r   statusPrint)selfresources_were_displayeds     r=   EpilogzUpdate.Epilog   s     $	jjJK $r?   c           
         | j                   j                  |j                  dt        j                  j
                  j                  j                  id      }|j                  d      s!|j                  rt        j                  |_        d}| j                  j                  |j                        }|j                   |j"                  |j$                  Rt'        j(                  | j                  |j                   |j"                  |j$                  |j                        |_        n| j-                         t.        j,                  j0                  t.        j,                  j2                  fv ro|j4                  rct'        j6                  | j8                  | j                  t;        j<                         |j                  |j4                  |j                        |_        	 | j8                  j>                  jA                  | j                  jC                  t;        j<                         |j                  	            }|jD                  r%tG        jH                  |jD                        |_"        n|jD                  xs d
|_"        | j-                         t.        j,                  j0                  fv r;|jJ                  r/tG        jL                  | j                  |jJ                        |_%        | jO                  ||      |_(        | j-                         t.        j,                  jR                  u xs |j4                   }|j                    xr0 |xr, tU        |jV                        xs tU        |jX                        }|jZ                  |jZ                  |_-        n?|jZ                  r|jZ                  j]                         rd|_-        n|jZ                  |_-        |rt        jj                  |_        	 tl        jn                  jq                  |jr                        jt                  }| j-                         t.        j,                  j0                  t.        j,                  j2                  fv r4tl        jv                  jq                  |jx                        jt                  }	n3tl        jz                  jq                  |jx                        jt                  }	| j                  j}                  |t;        j<                         |j                  |j~                  | j                  j|                  j                  |	      | j                  j|                  j                  |            }
| j8                  }t        j                  |      |j                  d<   |j>                  jm                  |
      }tg        j                  | j8                  | j                  t;        j<                         |j                        }|rB|j                  rt        j                  d       t        j                  j                  d       |S tG        j                  |jD                         |j                  r|S |jt                  }	 t        j                  | j8                  | j                  |dt;        j<                         t              }tG        j                  |d       tg        j                  | j8                  | j                  t;        j<                         |j                        S # t^        j`                  $ r)}tc        jd                  |tf        jh                        d}~ww xY w# t^        j`                  $ r)}tc        jd                  |tf        jh                        d}~ww xY w# t^        j`                  $ r)}tc        jd                  |tf        jh                        d}~ww xY w)a  Run 'deployments update'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      If --async=true, returns Operation to poll.
      Else, returns a struct containing the list of resources and list of
        outputs in the deployment.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    projectzdeploymentmanager.deployments)params
collectionformatF)nameN)configtemplatecomposite_typer   )rG   
deploymentr?   )deploymentResourcerG   rO   r$   createPolicydeletePolicyzX-Cloud-DM-PatchzEUpdating Deployment metadata is synchronous, --async flag is ignored.z2Update deployment metadata completed successfully.update)timeoutr   )P	resourcesParsedeployment_namer   VALUEScorerG   	GetOrFailIsSpecifiedasync_r   OPERATION_FORMATrJ   messages
DeploymentrO   rL   rM   rN   r   BuildTargetConfigtargetr-   r   r.   r/   r"   BuildTargetConfigFromManifestclientr   
GetProjectdeploymentsGet&DeploymentmanagerDeploymentsGetRequestfingerprintr   DecodeFingerprint
credentialCredentialFrom_GetUpdatedDeploymentLabelslabelsGAboolupdate_labelsremove_labelsr   isspaceapitools_exceptions	HttpErrorr   HttpExceptionr   HTTP_ERROR_FORMATDEPLOYMENT_FORMATr   r5   GetEnumForChoicedelete_policyrK   r1   create_policyr4   )DeploymentmanagerDeploymentsUpdateRequestr$   CreatePolicyValueValuesEnumDeletePolicyValueValuesEnumsix	text_typeadditional_http_headersFetchDeploymentr   warningrA   rB   PrintFingerprintr   WaitForOperationOPERATION_TIMEOUTLogOperationStatusFetchResourcesAndOutputs)rC   argsdeployment_refpatch_requestrO   current_deploymentno_manifesterrorparsed_delete_flagparsed_create_flagrequestrc   	operationupdated_deploymentop_names                  r=   Runz
Update.Run   s:     ^^)):,,1199CCD2 * 4N H%$++**dkM))&& * J KKDMM$9##+"44
--==,,__&j 


$"3"3"9"9"&"3"3"8"8": :"@@
++t}}





#
#T%5%5tHj
(K;;2266
--
>
>((*'22 ?  
		!(!:!:4;K;K!L

 "4!?!?!F3
 
			!2!2!8!8 9	9doo ' 6 6t}}7;!H

 ::
"$j &&(&&))* C262B2B.B ++o @+ @
t!!
"
>d4+=+=&> 				!!3!?!?
4#3#3#;#;#=!%
!%!1!1
 ++dk)K!99JJ


"d 				



!
!4#4#4#9#9! 
 11BB""$$(D 	
 **;;""$$(D 	 GG'$$&#..,,OO334FGOO334FG H Jg {{f;>==
<f$$%78$$++G4i '66
++t}}g&8&8&:

#
#% 
;;
++ 	

MN!!1==> {{g
M--KKMM %'	 	""9h7 11$++t}}292D2D2F2@2K2KM M (( K$$UK,I,IJJKZ (( K$$UK,I,IJJK !** M&&uk.K.KLLMsQ   G4\ 'H?] '] !A^ ] $\;;] ]?$]::]?^>$^99^>c                     t        j                  |      }t        j                  |      }t        j                  |j
                  | j                  j                  ||      S )N)r   GetUpdateLabelsDictFromArgsGetRemoveLabelsListFromArgsr	   UpdateLabelsrm   r^   DeploymentLabelEntry)rC   r   rO   rp   rq   s        r=   rl   z"Update._GetUpdatedDeploymentLabelsE  sQ    ;;DAM;;DAM!!*"3"3"&--"D"D"/@ @r?   N)__name__
__module____qualname____doc__detailed_helpr   GetDeleteFlagEnumMapr
   GetMessagesModuler{   r}   r5   r   ChoiceEnumMapperr|   r4   r1   staticmethodr   r-   rn   r>   rE   r   rl    r?   r=   r   r   .   s     %'-R 7E66t148112M2MP 7I66t148112M2ML!# $>9#=#=t18<112M2ML!$#  ,,// 0F 0FdLTMl@r?   r   c                        e Zd ZdZed        Zy)UpdateAlphar   c                     t         j                  | t        j                  j                         t        j                  |        | j                  j                  t
        j                         y N)r;   )
r   r>   r   r-   r.   r   AddCredentialFlagr7   r8   r9   r:   s    r=   r>   zUpdateAlpha.ArgsW  sF    
KK 1 1 7 7K8!!&)
!!+"J"JKr?   Nr   r   r   r   r   r>   r   r?   r=   r   r   M  s     L Lr?   r   c                        e Zd ZdZed        Zy)
UpdateBetar   c                 b    t         j                  | t        j                  j                         y r   )r   r>   r   r-   r/   r   s    r=   r>   zUpdateBeta.Argsh  s    
KK 1 1 6 6K7r?   Nr   r   r?   r=   r   r   ^  s     8 8r?   r   ).r   
__future__r   r   r   apitools.base.pyr   rs   )googlecloudsdk.api_lib.deployment_managerr   r   r	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   -googlecloudsdk.command_lib.deployment_managerr   r   r   r   r   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r~   r   UnicodeIsSupportedReleaseTracksr-   rn   UseDmApiDmApiVersionV2UpdateCommand	DmCommandr   r.   r   r/   V2BETAr   r   r?   r=   <module>r      s    " &  ' > A = ? , ( . E A B ? B : < # * 
   D%%(()'&&))*Y@T!2!2 Y@ + * Y@x D%%++,'&&,,-L& L . - L D%%**+'&&--.	8 	8 / , 	8r?   