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 Create(cluster_ref, zone, serve_nodes=3): """Create a cluster. Args: cluster_ref: A resource reference to the cluster to create. zone: string, The zone this cluster should be inside. serve_nodes: int, The number of nodes in this cluster. Returns: Long running operation. """ client = util.GetAdminClient() msgs = util.GetAdminMessages() storage_type = ( msgs.Cluster.DefaultStorageTypeValueValuesEnum.STORAGE_TYPE_UNSPECIFIED) cluster_msg = msgs.Cluster( serveNodes=serve_nodes, location=util.LocationUrl(zone), defaultStorageType=storage_type) msg = msgs.BigtableadminProjectsInstancesClustersCreateRequest( cluster=cluster_msg, clusterId=cluster_ref.Name(), parent=cluster_ref.Parent().RelativeName()) return client.projects_instances_clusters.Create(msg)
def _Cluster(self, args): msgs = util.GetAdminMessages() storage_type = (msgs.Cluster.DefaultStorageTypeValueValuesEnum. STORAGE_TYPE_UNSPECIFIED) cluster = msgs.Cluster(serveNodes=args.num_nodes, location=util.LocationUrl(args.zone), defaultStorageType=storage_type) kms_key = arguments.GetAndValidateKmsKeyName(args) if kms_key: cluster.encryptionConfig = msgs.EncryptionConfig( kmsKeyName=kms_key) if (args.autoscaling_min_nodes is not None or args.autoscaling_max_nodes is not None or args.autoscaling_cpu_target is not None): cluster.clusterConfig = clusters.BuildClusterConfig( autoscaling_min=args.autoscaling_min_nodes, autoscaling_max=args.autoscaling_max_nodes, autoscaling_cpu_target=args.autoscaling_cpu_target) # serveNodes must be set to None or 0 to enable Autoscaling. # go/cbt-autoscaler-api cluster.serveNodes = None return cluster
def _Cluster(self, args): msgs = util.GetAdminMessages() storage_type = (msgs.Cluster.DefaultStorageTypeValueValuesEnum. STORAGE_TYPE_UNSPECIFIED) cluster = msgs.Cluster(serveNodes=args.num_nodes, location=util.LocationUrl(args.zone), defaultStorageType=storage_type) return cluster
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. """ # TODO(b/73365914) remove after deprecation period display_name = args.display_name or args.description cli = bigtable_util.GetAdminClient() ref = resources.REGISTRY.Parse( args.instance, params={ 'projectsId': properties.VALUES.core.project.GetOrFail, }, collection='bigtableadmin.projects.instances') parent_ref = resources.REGISTRY.Create('bigtableadmin.projects', projectId=ref.projectsId) msgs = bigtable_util.GetAdminMessages() msg = msgs.CreateInstanceRequest( instanceId=ref.Name(), parent=parent_ref.RelativeName(), instance=msgs.Instance( # TODO(b/73365914) replace with args.display_name after deprecation displayName=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=args.cluster_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 = resources.REGISTRY.ParseRelativeName( result.name, 'bigtableadmin.operations') if args. async: log.CreatedResource(operation_ref, kind='bigtable instance {0}'.format( ref.Name()), async=True) return result return bigtable_util.WaitForInstance( cli, 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()) 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 _Cluster(self, args): msgs = util.GetAdminMessages() storage_type = (msgs.Cluster.DefaultStorageTypeValueValuesEnum. STORAGE_TYPE_UNSPECIFIED) cluster = msgs.Cluster(serveNodes=args.num_nodes, location=util.LocationUrl(args.zone), defaultStorageType=storage_type) kms_key = arguments.GetAndValidateKmsKeyName(args) if kms_key: cluster.encryptionConfig = msgs.EncryptionConfig( kmsKeyName=kms_key) return cluster
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 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 = util.GetAdminClient() ref = resources.REGISTRY.Parse( args.instance, collection='bigtableadmin.projects.instances') msgs = util.GetAdminMessages() msg = msgs.BigtableadminProjectsInstancesCreateRequest( projectsId=ref.projectsId, createInstanceRequest=msgs.CreateInstanceRequest( instanceId=ref.Name(), instance=msgs.Instance(displayName=args.description), clusters=msgs.CreateInstanceRequest. ClustersValue(additionalProperties=[ msgs.CreateInstanceRequest.ClustersValue. AdditionalProperty( key=args.cluster, value=msgs.Cluster( serveNodes=args.cluster_num_nodes, defaultStorageType=( msgs.Cluster.DefaultStorageTypeValueValuesEnum( args.cluster_storage_type)), # TODO(user): switch location to resource # when b/29566669 is fixed on API location=util.LocationUrl(args.cluster_zone))) ]))) result = cli.projects_instances.Create(msg) if not args. async: # TODO(user): enable this line when b/29563942 is fixed in apitools pass # util.WaitForOpV2(result, 'Creating instance') return result
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).')