Cluster Admin API¶
After creating a Client, you can
interact with individual clusters, groups of clusters or available
zones for a project.
List Clusters¶
If you want a comprehensive list of all existing clusters, make a
ListClusters API request with
Client.list_clusters():
clusters = client.list_clusters()
List Zones¶
If you aren’t sure which zone to create a cluster in, find out
which zones your project has access to with a ListZones API request
with Client.list_zones():
zones = client.list_zones()
You can choose a string from among the result to pass to
the Cluster constructor.
Cluster Factory¶
To create a Cluster object:
cluster = client.cluster(zone, cluster_id,
display_name=display_name,
serve_nodes=3)
Both display_name and serve_nodes are optional. When not provided,
display_name defaults to the cluster_id value and serve_nodes
defaults to the minimum allowed: 3.
Even if this Cluster already
has been created with the API, you’ll want this object to use as a
parent of a Table just as the
Client is used as the parent of
a Cluster.
Create a new Cluster¶
After creating the cluster object, make a CreateCluster API request
with create():
cluster.display_name = 'My very own cluster'
cluster.create()
If you would like more than the minimum number of nodes (3) in your cluster:
cluster.serve_nodes = 10
cluster.create()
Check on Current Operation¶
Note
When modifying a cluster (via a CreateCluster, UpdateCluster or
UndeleteCluster request), the Bigtable API will return a long-running
Operation. This will be stored on the object after each of
create(),
update() and
undelete() are called.
You can check if a long-running operation (for a
create(),
update() or
undelete()) has finished
by making a GetOperation request with
operation_finished():
>>> cluster.operation_finished()
True
Note
The operation data is stored in protected fields on the
Cluster:
_operation_type, _operation_id and _operation_begin.
If these are unset, then
operation_finished()
will fail. Also, these will be removed after a long-running operation
has completed (checked via this method). We could easily surface these
properties publicly, but it’s unclear if end-users would need them.
Get metadata for an existing Cluster¶
After creating the cluster object, make a GetCluster API request
with reload():
cluster.reload()
This will load serve_nodes and display_name for the existing
cluster in addition to the cluster_id, zone and project_id
already set on the Cluster object.
Update an existing Cluster¶
After creating the cluster object, make an UpdateCluster API request
with update():
client.display_name = 'New display_name'
cluster.update()
Next Step¶
Now we go down the hierarchy from
Cluster to a
Table.
Head next to learn about the Table Admin API.