
    (                        S r SSKJr  SSKJr  SSKJ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&                  R0                  5       " S S\5      5       rg)z"bigtable instances create command.    )absolute_import)division)unicode_literalsN)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.Args9   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.RunN   s     99T?r)   c                 R   [         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     UR#                  UR)                  5       UR+                  5       UR                  UR,                  UU R/                  U5      S9UR"                  R%                  US9S9nUR0                  R                  U5      n[         R2                  " U5      nUR4                  (       aC  [6        R8                  " UR+                  5       SR;                  UR)                  5       5      SS	9  U$ [         R<                  " US
R;                  UR)                  5       5      5      $ )z8Implements Run() with different possible features flags.zbigtableadmin.projects)	projectIdkeyvalue)displayNametypetags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NameRelativeNamedisplay_name_Tagsprojects_instancesGetOperationRefasync_r   CreatedResourceformatAwaitInstance)r,   r-   cliref
parent_refmsgsrH   new_clustersclusters_properties
cluster_idclustermsgresultoperation_refs                 r&   r+   CreateInstance._Run[   s    


C
--
 
 
&
&
(C##** CNN + <J  "DMM55d6H6HIM>>$'L%l&8&8&:;
  

$
$
2
2
E
E F -.  <
 
$
$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   rE   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&   rI   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.
Nr2   r8   )	r   getattrr   rE   rF   	TagsValuerJ   rK   rO   )r$   r-   tags_arg_namer7   tags_messager3   r4   s          r&   rS   CreateInstance._Tags   s     4'D((*33==L %TZZ\2
2
 +++A2
 
s   -B
 N)r7   )__name__
__module____qualname____firstlineno____doc__r   textwrapdedentdetailed_helpclassmethodr'   r.   r+   rI   r   rS   __static_attributes__r   r)   r&   r   r       sj     (- (// # -$ E E()LVTl%4  r)   r   c                       \ rS rSrSrSrSrg)CreateInstanceAlphai  r   Tr   N)r   r   r   r   r   r   r   r   r)   r&   r   r     s
    '-r)   r   )r   
__future__r   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nT'' n B nb D%%++,.  -r)   