def _Cluster(self, args): msgs = util.GetAdminMessages() num_nodes = arguments.ProcessInstanceTypeAndNodes(args) storage_type = msgs.Cluster.DefaultStorageTypeValueValuesEnum( args.cluster_storage_type.upper()) return msgs.Cluster( serveNodes=num_nodes, defaultStorageType=storage_type, # TODO(b/36049938): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(args.cluster_zone))
def _Clusters(self, args): """Get the clusters configs from command arguments. Args: args: the argparse namespace from Run(). Returns: A dict mapping from cluster id to msg.Cluster. """ msgs = util.GetAdminMessages() storage_type = msgs.Cluster.DefaultStorageTypeValueValuesEnum( args.cluster_storage_type.upper()) if args.cluster_config is not None: if (args.cluster is not None or args.cluster_zone is not None or args.cluster_num_nodes is not None): raise exceptions.InvalidArgumentException( '--cluster-config --cluster --cluster-zone --cluster-num-nodes', 'Use --cluster-config or the combination of --cluster, ' '--cluster-zone and --cluster-num-nodes to specify cluster(s), not ' 'both.') clusters = {} for cluster_dict in args.cluster_config: nodes = cluster_dict['nodes'] if 'nodes' in cluster_dict else 1 cluster = msgs.Cluster( serveNodes=nodes, defaultStorageType=storage_type, # TODO(b/36049938): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(cluster_dict['zone'])) if 'kms-key' in cluster_dict: cluster.encryptionConfig = msgs.EncryptionConfig( kmsKeyName=cluster_dict['kms-key']) clusters[cluster_dict['id']] = cluster return clusters elif args.cluster is not None: if args.cluster_zone is None: raise exceptions.InvalidArgumentException( '--cluster-zone', '--cluster-zone must be specified.') cluster = msgs.Cluster( serveNodes=arguments.ProcessInstanceTypeAndNodes(args), defaultStorageType=storage_type, # TODO(b/36049938): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(args.cluster_zone)) return {args.cluster: cluster} else: raise exceptions.InvalidArgumentException( '--cluster --cluster-config', 'Use --cluster-config to specify cluster(s).')
def Run(self, args): """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. """ cli = bigtable_util.GetAdminClient() ref = bigtable_util.GetInstanceRef(args.instance) parent_ref = resources.REGISTRY.Create('bigtableadmin.projects', projectId=ref.projectsId) msgs = bigtable_util.GetAdminMessages() instance_type = msgs.Instance.TypeValueValuesEnum(args.instance_type) num_nodes = arguments.ProcessInstanceTypeAndNodes(args, instance_type) msg = msgs.CreateInstanceRequest( instanceId=ref.Name(), parent=parent_ref.RelativeName(), instance=msgs.Instance(displayName=args.display_name, type=msgs.Instance.TypeValueValuesEnum( args.instance_type)), clusters=msgs.CreateInstanceRequest. ClustersValue(additionalProperties=[ msgs.CreateInstanceRequest.ClustersValue.AdditionalProperty( key=args.cluster, value=msgs.Cluster( serveNodes=num_nodes, defaultStorageType=( msgs.Cluster.DefaultStorageTypeValueValuesEnum( args.cluster_storage_type.upper())), # TODO(b/36056455): switch location to resource # when b/29566669 is fixed on API location=bigtable_util.LocationUrl(args.cluster_zone))) ])) result = cli.projects_instances.Create(msg) operation_ref = bigtable_util.GetOperationRef(result) if args.async_: log.CreatedResource(operation_ref, kind='bigtable instance {0}'.format( ref.Name()), is_async=True) return result return bigtable_util.AwaitInstance( operation_ref, 'Creating bigtable instance {0}'.format(ref.Name()))
def _Cluster(self, args): msgs = util.GetAdminMessages() num_nodes = arguments.ProcessInstanceTypeAndNodes(args) storage_type = msgs.Cluster.DefaultStorageTypeValueValuesEnum( args.cluster_storage_type.upper()) cluster = msgs.Cluster( serveNodes=num_nodes, defaultStorageType=storage_type, # TODO(b/36049938): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(args.cluster_zone)) kms_key = arguments.GetAndValidateKmsKeyName(args) if kms_key: cluster.encryptionConfig = msgs.EncryptionConfig( kmsKeyName=kms_key) return cluster
def _Clusters(self, args): """Get the clusters configs from command arguments. Args: args: the argparse namespace from Run(). Returns: A dict mapping from cluster id to msg.Cluster. """ msgs = util.GetAdminMessages() storage_type = msgs.Cluster.DefaultStorageTypeValueValuesEnum( args.cluster_storage_type.upper()) if args.cluster_config is not None: if (args.cluster is not None or args.cluster_zone is not None or args.cluster_num_nodes is not None): raise exceptions.InvalidArgumentException( '--cluster-config --cluster --cluster-zone --cluster-num-nodes', 'Use --cluster-config or the combination of --cluster, ' '--cluster-zone and --cluster-num-nodes to specify cluster(s), not ' 'both.') self._ValidateClusterConfigArgs(args.cluster_config) new_clusters = {} for cluster_dict in args.cluster_config: nodes = cluster_dict.get('nodes', 1) cluster = msgs.Cluster( serveNodes=nodes, defaultStorageType=storage_type, # TODO(b/36049938): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(cluster_dict['zone'])) if 'kms-key' in cluster_dict: cluster.encryptionConfig = msgs.EncryptionConfig( kmsKeyName=cluster_dict['kms-key']) if ('autoscaling-min-nodes' in cluster_dict or 'autoscaling-max-nodes' in cluster_dict or 'autoscaling-cpu-target' in cluster_dict): cluster.clusterConfig = clusters.BuildClusterConfig( autoscaling_min=cluster_dict['autoscaling-min-nodes'], autoscaling_max=cluster_dict['autoscaling-max-nodes'], autoscaling_cpu_target=cluster_dict[ 'autoscaling-cpu-target']) # serveNodes must be set to None or 0 to enable Autoscaling. # go/cbt-autoscaler-api cluster.serveNodes = None new_clusters[cluster_dict['id']] = cluster return new_clusters elif args.cluster is not None: if args.cluster_zone is None: raise exceptions.InvalidArgumentException( '--cluster-zone', '--cluster-zone must be specified.') cluster = msgs.Cluster( serveNodes=arguments.ProcessInstanceTypeAndNodes(args), defaultStorageType=storage_type, # TODO(b/36049938): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(args.cluster_zone)) return {args.cluster: cluster} else: raise exceptions.InvalidArgumentException( '--cluster --cluster-config', 'Use --cluster-config to specify cluster(s).')