
    %3              	          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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Jr  SSKrSr\R>                  \R@                  " \RB                  RD                  5      \
RF                  " \
RH                  RJ                  5       " S S\RL                  \
RN                  5      5       5       5       r(\R>                  \R@                  " \RB                  RR                  5      \
RF                  " \
RH                  RR                  5       " S S\(5      5       5       5       r*\R>                  \R@                  " \RB                  RV                  5      \
RF                  " \
RH                  RX                  5       " S S\(5      5       5       5       r-g)zdeployments create command.    )absolute_import)division)unicode_literals)
exceptions)dm_api_util)dm_base)apis)base)alpha_flags)dm_util)dm_write)flags)importer)	arg_utils)labels_util)log)
propertiesNi  c                       \ rS rSrSrSS0r\R                  " S\R                  " SS5      R                  R                  SS	S
9r\\R                  R                   4S j5       rS rS r SS jrS rS rS rSrg)Create-   gCreate a deployment.

This command inserts (creates) a new deployment based on a provided config
file.
EXAMPLESa  
To create a new deployment from a top-level YAML file, run:

  $ {command} my-deployment --config=config.yaml --description="My deployment"

To create a new deployment from a top-level template file, run:

  $ gcloud deployment-manager deployments create my-deployment   --template=template.{jinja|py}   --properties="string-key:'string-value',integer-key:12345"

To create a new deployment directly from a composite type, run:

  $ gcloud deployment-manager deployments create my-deployment   --composite-type=<project-id>/composite:<type-name>   --properties="string-key:'string-value',integer-key:12345"

To preview a deployment without actually creating resources, run:

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

To instantiate a deployment that has been previewed, issue an update command for that deployment without specifying a config file.

More information is available at https://cloud.google.com/deployment-manager/docs/configuration/.
z--create-policydeploymentmanagerv2betaz;Create policy for resources that have changed in the updatezcreate-or-acquire)help_strdefaultc                    U R                  5       nU R                  SS9n[        R                  " U5        [        R                  " U5        [        R                  " U 5        [        R
                  " U 5        [        R                  " U 5        UR                  SSSSSS9  U R                  S	S
SS9  U R                  SSSSSS9  U R                  R                  [        R                  5        g)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.
T)requiredz--automatic-rollback-on-errorzIf the create request results in a deployment with resource errors, delete that deployment immediately after creation. (default=False)automatic_rollbackF
store_true)helpdestr   actionz--descriptionz1Optional description of the deployment to insert.description)r!   r"   z	--previewzePreview the requested create without actually instantiating the underlying resources. (default=False)previewN)add_mutually_exclusive_groupr   AddConfigFlagsAddAsyncFlagAddDeploymentNameFlagAddPropertiesFlagr   AddCreateLabelsFlagsadd_argumentdisplay_info	AddFormatRESOURCES_AND_OUTPUTS_FORMAT)parserversiongroupconfig_groups       4lib/surface/deployment_manager/deployments/create.pyArgsCreate.ArgsZ   s     //1E666EL	&	u	'	F#$$V,	' "   @  
 0   !!%"D"DE    c                 R    U(       d   [         R                  R                  S5        gg)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     r4   EpilogCreate.Epilog   s     $	jjJK $r7   c                    U R                   R                  UR                  S[        R                  R
                  R                  R                  0SS9nUR                  S5      (       d&  UR                  (       a  [        R                  Ul        U R                  R                  UR                  [         R"                  " U R                  UR$                  UR&                  UR(                  UR                  S9S9nU R+                  X5         U R,                  R.                  R1                  U R3                  U[4        R6                  " 5       US95      n[8        R:                  " U R,                  U R                  [4        R6                  " 5       UR                  5      n[<        R>                  " U5        UR                  (       a  U$ URJ                  n [L        RN                  " U R,                  U R                  US	[4        R6                  " 5       [P        S
9n[<        RR                  " US5        [8        R\                  " U R,                  U R                  [4        R6                  " 5       UR                  5      $ ! [@        RB                   a*  n[D        RF                  " U[8        RH                  5      eSnAff = f! [@        RB                   a*  n[D        RF                  " U[8        RH                  5      eSnAf[T        RV                   a[  nU RY                  UUU[4        R6                  " 5       U5      n[[        USS5      (       a  [        R                  Ul        Us SnA$ SnAff = f)a  Run 'deployments create'.

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.
  ConfigError: Config file could not be read or parsed, or the
      deployment creation operation encountered an error.
projectzdeploymentmanager.deployments)params
collectionformat)configtemplatecomposite_typer   )nametarget)argsr@   
deploymentNcreate)operation_descriptionr@   timeoutr   r   F)/	resourcesParsedeployment_namer   VALUEScorer@   	GetOrFailIsSpecifiedasync_r   OPERATION_FORMATrC   messages
DeploymentrJ   r   BuildTargetConfigrD   rE   rF   _SetMetadataclientdeploymentsInsert_BuildRequestr   
GetProjectr   FetchDeploymentFingerprintr   PrintFingerprintapitools_exceptions	HttpErrorr   HttpExceptionHTTP_ERROR_FORMATrG   r   WaitForOperationOPERATION_TIMEOUTLogOperationStatusdm_exceptionsOperationError_HandleOperationErrorgetattrFetchResourcesAndOutputs)	r;   rI   deployment_refrJ   	operationfingerprinterrorop_nameresponses	            r4   Run
Create.Run   s   $ ^^)):,,1199CCD2 * 4N X&&T[[**dk))&&))$--1537==9=9L9L59__	F * J 	d'K++))00


!3!3!5*  NOi
  ::
++
--





#
#	%k
 {+ {{g--KKMM"*&&(%'	 	""9h7 11$++t}}292D2D2F2@2K2KM M9 (( K$$UK,I,IJJK !** M&&uk.K.KLL)) --e.2.7.5.@.@.B.<	>
 4-u55..$+sE   B'I: AJ; :J8%J33J8;M&%K44M&AM!M&!M&c                 8   U R                   R                  X#UR                  S9nU(       an  UR                  (       a]  [        R
                  R                  UR                  5      R                  nU R                   R                  R                  U5      Ul	        U$ )N)r@   rJ   r%   )
rW   )DeploymentmanagerDeploymentsInsertRequestr%   create_policyr   _create_policy_flag_mapGetEnumForChoicerG   CreatePolicyValueValuesEnumcreatePolicy)r;   rI   r@   rJ   supports_create_policyrequestparsed_create_flags          r4   r^   Create._BuildRequest   s    
 mmEE F FG$"4"4!99JJ


"d  --
A
A
%
%&8
9  Nr7   c                     UR                   (       a_  U R                  UR                  [        R                  " U5      5      n[
        R                  " U R                  U R                  X45      nXv/$ UeN)	r   _PerformRollbackrJ   six	text_typer   GetOperationr[   rW   )r;   rq   rI   ro   r@   rn   delete_operationcreate_operations           r4   rk   Create._HandleOperationError   sb    ..~/H/H/2}}U/CE$11$++t}}2;F 11
Kr7   c           	      0   UR                   (       a  UR                   Ul         [        R                  " U5      nU(       aQ  [        [        R
                  " U5      5       VVs/ s H  u  pEU R                  R                  XES9PM      snnUl        g g s  snnf )N)keyvalue)	r$   r   GetUpdateLabelsDictFromArgssortedr   	iteritemsrW   DeploymentLabelEntrylabels)r;   rI   rJ   
label_dictkvs         r4   rZ   Create._SetMetadata   sz    #//j88>J S]]:677da --
,
,
,
<7j s   "%Bc           	         [         R                  " SU-   S-   U-   5        [         R                  R                  S5         U R                  R
                  R                  U R                  R                  [        R                  " 5       US95      n["        R$                  " U R                  U R                  UR&                  S[        R                  " 5       [(        S9  [        R*                  " U R                  U R                  U[        R                  " 5       5      nU$ ! [        R                   a*  n[        R                  " U[        R                   5      eS nAff = f)NzThere was an error deploying z:
zP`--automatic-rollback-on-error` flag was supplied; deleting failed deployment...)r@   rJ   delete)rM   )r   warningr9   r:   r[   r\   DeleterW   )DeploymentmanagerDeploymentsDeleteRequestr   r_   rb   rc   r   rd   r   re   r   rf   rG   rg   r   )r;   rP   error_messager   rq   completed_operations         r4   r   Create._PerformRollback  s-   KK/!"$)*,9: ; JJ 5 6K0077
--
A
A((*( B  dkk"mm.33&%002&79 &224;;37==3C3:3E3E3GI  (( K$$UK,I,IJJKs    AD   E4%EE N)F)__name__
__module____qualname____firstlineno____doc__detailed_helpr   ChoiceEnumMapperr	   GetMessagesModule)DeploymentmanagerDeploymentsUpdateRequestr{   ry   staticmethodr
   ReleaseTrackGAr5   r=   rt   r^   rk   rZ   r   __static_attributes__r   r7   r4   r   r   -   s      -8 &6618<112M2ML!# ,,// *F *FXLPMl ,1	
r7   r   c                   H   ^  \ rS rSrSr\S 5       rU 4S jrU 4S jrSr	U =r
$ )CreateAlphai)  r   c                 ,   [         R                  U [        R                  R                  S9  [
        R                  " U 5        U R                  R                  [
        R                  5        [         R                  R                  R                  U 5        g N)r1   )r   r5   r
   r   ALPHAr   AddCredentialFlagr-   r.   r/   ry   
choice_argAddToParserr0   s    r4   r5   CreateAlpha.Args3  s`    
KK 1 1 7 7K8!!&)
!!+"J"JK
""--99&Ar7   c                    > UR                   (       a0  [        R                  " U R                  UR                   5      Ul         [        [
        U ]  X5        g r   )
credentialr   CredentialFromrW   superr   rZ   )r;   rI   rJ   	__class__s      r4   rZ   CreateAlpha._SetMetadata:  s:    %44T]]59__Fj	+t)$;r7   c                 ,   > [         [        U ]  UUUSS9$ NT)rI   r@   rJ   r}   )r   r   r^   r;   rI   r@   rJ   r   s       r4   r^   CreateAlpha._BuildRequest@  s(    d1#	 2 % %r7   r   )r   r   r   r   r   r   r5   rZ   r^   r   __classcell__r   s   @r4   r   r   )  s-     B B<% %r7   r   c                   <   ^  \ rS rSrSr\S 5       rU 4S jrSrU =r	$ )
CreateBetaiH  r   c                     [         R                  U [        R                  R                  S9  [         R
                  R                  R                  U 5        g r   )r   r5   r
   r   BETAry   r   r   r   s    r4   r5   CreateBeta.ArgsR  s8    
KK 1 1 6 6K7
""--99&Ar7   c                 ,   > [         [        U ]  UUUSS9$ r   )r   r   r^   r   s       r4   r^   CreateBeta._BuildRequestW  s(    T0#	 1 % %r7   r   )
r   r   r   r   r   r   r5   r^   r   r   r   s   @r4   r   r   H  s(     B B% %r7   r   ).r   
__future__r   r   r   apitools.base.pyr   rb   )googlecloudsdk.api_lib.deployment_managerr   r   ri   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   rg   UnicodeIsSupportedReleaseTracksr   r   UseDmApiDmApiVersionV2CreateCommand	DmCommandr   r   r   r   V2BETAr   r   r7   r4   <module>r      s}    " &  ' > A = Q , ( . E A B ? B : < # * 
   D%%(()'&&))*vT!2!2 v + * vr D%%++,'&&,,-%& % . - %8 D%%**+'&&--.% % / , %r7   