Skip to content

Latest commit

 

History

History
141 lines (96 loc) · 5.36 KB

File metadata and controls

141 lines (96 loc) · 5.36 KB

Instance Admin API

Warning

gRPC is required for using the Cloud Bigtable API. As of May 2016, grpcio is only supported in Python 2.7, so importing :mod:`gcloud.bigtable` in other versions of Python will fail.

After creating a :class:`Client <gcloud.bigtable.client.Client>`, you can interact with individual instances for a project.

List Instances

If you want a comprehensive list of all existing instances, make a ListInstances API request with :meth:`Client.list_instances() <gcloud.bigtable.client.Client.list_instances>`:

instances = client.list_instances()

Instance Factory

To create a :class:`Instance <gcloud.bigtable.instance.Instance>` object:

instance = client.instance(instance_id, location_id,
                           display_name=display_name)
  • location_id is the ID of the location in which the instance's cluster will be hosted, e.g. 'us-central1-c'. location_id is required for instances which do not already exist.
  • display_name is optional. When not provided, display_name defaults to the instance_id value.

You can also use :meth:`Client.instance` to create a local wrapper for instances that have already been created with the API, or through the web conole:

instance = client.instance(existing_instance_id)
instance.reload()

Create a new Instance

After creating the instance object, make a CreateInstance API request with :meth:`create() <gcloud.bigtable.instance.Instance.create>`:

instance.display_name = 'My very own instance'
instance.create()

Check on Current Operation

Note

When modifying a instance (via a CreateInstance request), the Bigtable API will return a long-running operation and a corresponding :class:`Operation <gcloud.bigtable.instance.Operation>` object will be returned by :meth:`create() <gcloud.bigtable.instance.Instance.create>`.

You can check if a long-running operation (for a :meth:`create() <gcloud.bigtable.instance.Instance.create>` has finished by making a GetOperation request with :meth:`Operation.finished() <gcloud.bigtable.instance.Operation.finished>`:

>>> operation = instance.create()
>>> operation.finished()
True

Get metadata for an existing Instance

After creating the instance object, make a GetInstance API request with :meth:`reload() <gcloud.bigtable.instance.Instance.reload>`:

instance.reload()

This will load display_name for the existing instance object.

Update an existing Instance

After creating the instance object, make an UpdateInstance API request with :meth:`update() <gcloud.bigtable.instance.Instance.update>`:

client.display_name = 'New display_name'
instance.update()

Delete an existing Instance

Make a DeleteInstance API request with :meth:`delete() <gcloud.bigtable.instance.Instance.delete>`:

instance.delete()

Next Step

Now we go down the hierarchy from :class:`Instance <gcloud.bigtable.instance.Instance>` to a :class:`Table <gcloud.bigtable.table.Table>`.

Head next to learn about the :doc:`bigtable-table-api`.