|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# [START spanner_create_instance_partition] |
| 16 | +# |
| 17 | +# Creates an instance partition. |
| 18 | +# |
| 19 | +# @param project_id [String] The ID of the Google Cloud project. |
| 20 | +# @param instance_id [String] The ID of the Spanner instance. |
| 21 | +# @param instance_partition_id [String] The ID of the Spanner instance partition. |
| 22 | +def spanner_create_instance_partition project_id:, instance_id:, instance_partition_id: |
| 23 | + require "google/cloud/spanner/admin/instance" |
| 24 | + |
| 25 | + instance_admin_client = Google::Cloud::Spanner::Admin::Instance.instance_admin |
| 26 | + |
| 27 | + instance_path = instance_admin_client.instance_path \ |
| 28 | + project: project_id, |
| 29 | + instance: instance_id |
| 30 | + instance_partition = { |
| 31 | + display_name: "Test Instance Partition", |
| 32 | + config: instance_admin_client.instance_config_path(project: project_id, instance_config: "nam3"), |
| 33 | + node_count: 1 |
| 34 | + } |
| 35 | + |
| 36 | + job = instance_admin_client.create_instance_partition \ |
| 37 | + parent: instance_path, |
| 38 | + instance_partition_id: instance_partition_id, |
| 39 | + instance_partition: instance_partition |
| 40 | + |
| 41 | + puts "Waiting for create instance partition operation to complete" |
| 42 | + job.wait_until_done! |
| 43 | + |
| 44 | + if job.error? |
| 45 | + puts job.error |
| 46 | + else |
| 47 | + puts "Created instance partition #{instance_partition_id} on instance #{instance_id}" |
| 48 | + end |
| 49 | +end |
| 50 | +# [END spanner_create_instance_partition] |
| 51 | + |
| 52 | +if $PROGRAM_NAME == __FILE__ |
| 53 | + spanner_create_instance_partition project_id: ARGV.shift, |
| 54 | + instance_id: ARGV.shift, |
| 55 | + instance_partition_id: ARGV.shift |
| 56 | +end |
0 commit comments