Use the Storage Control API

The Storage Control API provides a unified place for performing metadata-oriented control plane operations, which include network routing, resource management, and long-running operations. The Storage Control API is separate from the Cloud Storage API, which handles data plane operations that move your data within Google Cloud.

The following instructions describe how to get started with the Storage Control API by using Cloud Storage client libraries.

Install the client library

C++

For more information about installing the C++ library, see Setting up a C++ development environment.

C#

If you are using Visual Studio 2017 or higher, open nuget package manager window and type the following:

Install-Package Google.Cloud.Storage.Control.V2

If you are using .NET Core command-line interface tools to install your dependencies, run the following command:

dotnet add package Google.Cloud.Storage.Control.V2

For more information, see Setting up a C# Development Environment.

Go

go get cloud.google.com/go/storage/control/apiv2

For more information, see Setting up a Go Development Environment.

Java

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.37.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-storage</artifactId>
  </dependency>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-storage-control</artifactId>
  </dependency>

For more information, see Setting up a Java Development Environment.

Node.js

npm install @google-cloud/storage-control

For more information, see Setting up a Node.js Development Environment.

PHP

composer require google/cloud-storage-control

For more information, see Setting up a PHP Development Environment.

Python

pip install google-cloud-storage-control

For more information, see Setting up a Python Development Environment.

Ruby

gem install google-cloud-storage-control

For more information, see Setting up a Ruby Development Environment.

Set up authentication

Use the Cloud Storage authentication instructions for setting up client libraries.

Use Storage Control

C++

For more information, see the Cloud Storage C++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

#include "google/cloud/storagecontrol/v2/storage_control_client.h"
#include <iostream>

int main(int argc, char* argv[]) try {
  if (argc != 2) {
    std::cerr << "Usage: " << argv[0] << " bucket-id\n";
    return 1;
  }
  auto const name =
      std::string{"projects/_/buckets/"} + argv[1] + "/storageLayout";

  namespace storagecontrol = ::google::cloud::storagecontrol_v2;
  auto client = storagecontrol::StorageControlClient(
      storagecontrol::MakeStorageControlConnection());

  auto layout = client.GetStorageLayout(name);
  if (!layout) throw std::move(layout).status();
  std::cout << layout->DebugString() << "\n";

  return 0;
} catch (google::cloud::Status const& status) {
  std::cerr << "google::cloud::Status thrown: " << status << "\n";
  return 1;
}

C#

For more information, see the Cloud Storage C# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

using Google.Cloud.Storage.Control.V2;
using System;

public class StorageControlQuickstartSample
{
    public StorageLayout StorageControlQuickstart(string bucketName = "your-unique-bucket-name")
    {
        StorageControlClient storageControl = StorageControlClient.Create();

        // Using "_" for projectId means global bucket namespace
        var layoutName = new StorageLayoutName("_", bucketName);
        StorageLayout response = storageControl.GetStorageLayout(layoutName);

        Console.WriteLine($"Bucket {bucketName} has location type {response.LocationType}");
        return response;
    }
}

Go

For more information, see the Cloud Storage Go API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

// This sample demonstrates how to set up and make an API call with the
// Storage Control client.
package main

import (
	"context"
	"flag"
	"fmt"
	"log"
	"time"

	control "cloud.google.com/go/storage/control/apiv2"
	controlpb "cloud.google.com/go/storage/control/apiv2/controlpb"
)

func main() {
	// Set this flag to an existing Cloud Storage bucket when running the sample.
	bucketName := flag.String("bucket", "", "Cloud Storage bucket name")
	flag.Parse()
	log.Printf("bucket : %v", *bucketName)

	ctx := context.Background()

	// Create a client.
	client, err := control.NewStorageControlClient(ctx)
	if err != nil {
		log.Fatalf("failed to create client: %v", err)
	}
	defer client.Close()

	// Create a request to get the storage layout for the bucket.
	req := &