
    )                        S r SSK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  \R                  \R                  " \R                  R                   \R                  R"                  5       " S
 S\R$                  5      5       5       r\R                  " \R                  R(                  5       " S S\5      5       rg)z"bigtable instances create command.    N)clusters)util)base)
exceptions)	arguments)log)	resourcesc                       \ rS rSrSrSrS\R                  " S5      0r\	S 5       r
S rS rS	 rS
 r\	SS j5       rSrg)CreateInstance   Create a new Bigtable instance.FEXAMPLESa            To create an instance with id `my-instance-id` with a cluster located
          in `us-east1-c`, run:

            $ {command} my-instance-id --display-name="My Instance" --cluster-config=id=my-cluster-id,zone=us-east1-c

          To create an instance with multiple clusters, run:

            $ {command} my-instance-id --display-name="My Instance" --cluster-config=id=my-cluster-id-1,zone=us-east1-c --cluster-config=id=my-cluster-id-2,zone=us-west1-c,nodes=3

          To create an instance with `HDD` storage and `10` nodes, run:

            $ {command} my-hdd-instance --display-name="HDD Instance" --cluster-storage-type=HDD --cluster-config=id=my-cluster-id,zone=us-east1-c,nodes=10

          c                    [         R                  " U5      R                  SS9R                  5       R	                  5       R                  5       R                  5       R                  5       R                  5       R                  5         U R                  (       a$  [         R                  " U5      R                  5         [         R                  " USSS9  UR                  R                  [         R                  5        g)z Register flags for this command.T)requiredz	to create)
positionalN)r   ArgAdderAddInstanceDisplayNameAddClusterConfigAddDeprecatedClusterAddDeprecatedClusterZoneAddDeprecatedClusterNodesAddClusterStorageAddAsyncAddDeprecatedInstanceType_support_tagsAddTagsAddInstanceResourceArgdisplay_infoAddCacheUpdaterInstanceCompleter)clsparsers     (lib/surface/bigtable/instances/create.pyArgsCreateInstance.Args6   s     	6"				.							!	!	#	"	"	$					"	"	$  ((*$$V[TJ
''	(C(CD    c                 $    U R                  U5      $ )zExecutes the instances create 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.
)_Run)selfargss     r#   RunCreateInstance.RunK   s     99T?r&   c                    [         R                  " 5       nUR                  R                  R	                  5       n[
        R                  R                  SUR                  S9n[         R                  " 5       nUR                  R                  UR                  5      nU R                  U5      n/ n[        UR                  5       5       H7  u  pUR!                  UR"                  R$                  R'                  XS95        M9     Sn[)        US5      (       a6  UR*                  (       a%  UR                  R-                  UR*                  5      nUR#                  UR/                  5       UR1                  5       UR                  UR2                  UU R5                  U5      US9UR"                  R%                  US9S9nUR6                  R                  U5      n[         R8                  " U5      nUR:                  (       aC  [<        R>                  " UR1                  5       S	RA                  UR/                  5       5      S
S9  U$ [         RB                  " USRA                  UR/                  5       5      5      $ )z8Implements Run() with different possible features flags.zbigtableadmin.projects)	projectIdkeyvalueNedition)displayNametypetagsr2   additionalProperties)
instanceIdparentinstancer   zbigtable instance {0}T)kindis_asynczCreating bigtable instance {0})"r   GetAdminClientCONCEPTSr:   Parser	   REGISTRYCreate
projectsIdGetAdminMessagesInstanceTypeValueValuesEnuminstance_type	_ClusterssorteditemsappendCreateInstanceRequestClustersValueAdditionalPropertyhasattrr2   EditionValueValuesEnumNameRelativeNamedisplay_name_Tagsprojects_instancesGetOperationRefasync_r   CreatedResourceformatAwaitInstance)r)   r*   cliref
parent_refmsgsrF   new_clustersclusters_properties
cluster_idclusterr2   msgresultoperation_refs                  r#   r(   CreateInstance._RunX   s    


C
--
 
 
&
&
(C##** CNN + <J  "DMM55d6H6HIM>>$'L%l&8&8&:;
  

$
$
2
2
E
E F -.  <
 GtYDLL44T\\Bg

$
$88:&&())D!	  
 ++99!4 : 
 % C ##**3/F((0M{{	

$
$
&&--chhj9 m7>>sxxzJL Lr&   c           
         [         R                  " 5       nUR                  R                  UR                  R                  5       5      nUR                  Gbd  UR                  c  UR                  c  UR                  b  [        R                  " SS5      eU R                  UR                  5        0 nUR                   H  nUR                  SS5      nUR                  SUR                  R                  UR                  R                  R                  5      5      nUR                  UUU[         R                   " US   5      S9nS	U;   a  UR#                  US	   S
9Ul        SU;   d  SU;   d  SU;   a:  SU;   a  US   n	OSn	[&        R(                  " US   US   US   U	S9Ul        SUl        XUS   '   M     U$ UR                  b  UR                  c  [        R                  " SS5      eUR                  [.        R0                  " U5      UUR                  R                  UR                  R                  R                  5      [         R                   " UR                  5      S9nUR                  U0$ [        R                  " SS5      e)zGet the clusters configs from command arguments.

Args:
  args: the argparse namespace from Run().

Returns:
  A dict mapping from cluster id to msg.Cluster.
Nz=--cluster-config --cluster --cluster-zone --cluster-num-nodesz}Use --cluster-config or the combination of --cluster, --cluster-zone and --cluster-num-nodes to specify cluster(s), not both.nodes   znode-scaling-factorzone)
serveNodesnodeScalingFactordefaultStorageTypelocationzkms-key)
kmsKeyNameautoscaling-min-nodesautoscaling-max-nodesautoscaling-cpu-targetautoscaling-storage-target)autoscaling_minautoscaling_maxautoscaling_cpu_targetautoscaling_storage_targetidz--cluster-zonez!--cluster-zone must be specified.)rj   rl   rk   rm   z--cluster --cluster-configz+Use --cluster-config to specify cluster(s).)r   rC   Cluster!DefaultStorageTypeValueValuesEnumcluster_storage_typeuppercluster_configra   cluster_zonecluster_num_nodesr   InvalidArgumentException_ValidateClusterConfigArgsget NodeScalingFactorValueValuesEnumNODE_SCALING_FACTOR_1XLocationUrlEncryptionConfigencryptionConfigr   BuildClusterConfigclusterConfigrj   r   ProcessInstanceTypeAndNodes)
r)   r*   r]   storage_typer^   cluster_dictrg   node_scaling_factorra   storage_targets
             r#   rG   CreateInstance._Clusters   s      "D<<AA!!'')+L &
,,
"*##/11K 	 %%d&9&9:l--,  !,*..!LL99==TT
 ,,1+ %%l6&:;  = $%)%:%:%i0 &; &2'
" $|3#|3$4)\9)*FGN!N"*"="=*+BC*+BC%12J%K)7	#9'
  $'
+2\$'(K .L 		!				"11AC 	C::4@) LLIIll;;RR
 ##D$5$56  	8g llG$$//
&
7 r&   c                     U Hc  nSU;   d  SU;   d  SU;   d  SU;   d  M  SU;   a  [         R                  " SS5      eSU;  d  SU;  d  SU;  d  MN  [         R                  " SS	5      e   g
)z9Validates arguments in cluster-config as a repeated dict.ro   rp   rq   rr   rg   ze--autoscaling-min-nodes --autoscaling-max-nodes --autoscaling-cpu-target --autoscaling-storage-targetzAt most one of nodes | autoscaling-min-nodes autoscaling-max-nodes autoscaling-cpu-target autoscaling-storage-target may be specified in --cluster-configzH--autoscaling-min-nodes --autoscaling-max-nodes --autoscaling-cpu-targetzrAll of --autoscaling-min-nodes --autoscaling-max-nodes --autoscaling-cpu-target must be set to enable Autoscaling.N)r   r   )r)   r|   r   s      r#   r   )CreateInstance._ValidateClusterConfigArgs   s     '
!\
1
!\
1
"l
2
&,
6l"33FPQ Q $<7#<7$L833)+$% %# 'r&   c                 (   U R                   (       d  g[        X5      nU(       d  g[        R                  " 5       R                  R
                  nU" [        UR                  5       5       VVs/ s H  u  pVUR                  XVS9PM     snnS9$ s  snnf )zGet the tags from command arguments.

Args:
  args: the argparse namespace from Run().
  tags_arg_name: the name of the tags argument.

Returns:
  A dict mapping from tag key to tag value.
Nr/   r6   )	r   getattrr   rC   rD   	TagsValuerH   rI   rM   )r!   r*   tags_arg_namer5   tags_messager0   r1   s          r#   rS   CreateInstance._Tags   s     4'D((*33==L %TZZ\2
2
 +++A2
 
s   -B
 N)r5   )__name__
__module____qualname____firstlineno____doc__r   textwrapdedentdetailed_helpclassmethodr$   r+   r(   rG   r   rS   __static_attributes__r   r&   r#   r   r      sj     (- (// # -$ E E(.L`Tl%4  r&   r   c                   :   ^  \ rS rSrSrSr\U 4S j5       rSrU =r	$ )CreateInstanceAlphai  r   Tc                 t   > [         [        U ]  U5        [        R                  " U5      R                  5         g )N)superr   r$   r   r   AddInstanceEdition)r!   r"   	__class__s     r#   r$   CreateInstanceAlpha.Args  s*    	
s(0v113r&   r   )
r   r   r   r   r   r   r   r$   r   __classcell__)r   s   @r#   r   r     s    '-4 4r&   r   )r   r   googlecloudsdk.api_lib.bigtabler   r   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.bigtabler   googlecloudsdk.corer   r	   UniverseCompatibleReleaseTracksReleaseTrackGABETACreateCommandr   ALPHAr   r   r&   r#   <module>r      s    )  4 0 ( . 9 # ) D%%(($*;*;*@*@AsT'' s B sl D%%++,4. 4 -4r&   