Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update snippets.py
  • Loading branch information
sangramql committed Sep 17, 2018
commit 97fe27db19879aa2b7e99c09dad069cd20fda091
6 changes: 6 additions & 0 deletions bigtable/google/cloud/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ def list_instances(self):
def list_clusters(self):
"""List the clusters in the project.

For example:

.. literalinclude:: snippets.py
:start-after: [START bigtable_list_clusters]

This comment was marked as spam.

:end-before: [END bigtable_list_clusters]

This comment was marked as spam.


:rtype: tuple
:returns:
(clusters, failed_locations), where 'clusters' is list of
Expand Down
20 changes: 19 additions & 1 deletion bigtable/google/cloud/bigtable/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def delete(self):
def cluster(self, cluster_id, location_id=None,
serve_nodes=None, default_storage_type=None):
"""Factory to create a cluster associated with this instance.

For example:

.. literalinclude:: snippets.py
Expand Down Expand Up @@ -409,6 +409,12 @@ def cluster(self, cluster_id, location_id=None,
def list_clusters(self):
"""List the clusters in this instance.

For example:

.. literalinclude:: snippets.py
:start-after: [START bigtable_list_clusters]

This comment was marked as spam.

:end-before: [END bigtable_list_clusters]

This comment was marked as spam.


:rtype: tuple
:returns:
(clusters, failed_locations), where 'clusters' is list of
Expand All @@ -424,6 +430,12 @@ def list_clusters(self):
def table(self, table_id, app_profile_id=None):
"""Factory to create a table associated with this instance.

For example:

.. literalinclude:: snippets.py
:start-after: [START bigtable_create_table]
:end-before: [END bigtable_create_table]

:type table_id: str
:param table_id: The ID of the table.

Expand All @@ -438,6 +450,12 @@ def table(self, table_id, app_profile_id=None):
def list_tables(self):
"""List the tables in this instance.

For example:

.. literalinclude:: snippets.py
:start-after: [START bigtable_list_tables]
:end-before: [END bigtable_list_tables]

:rtype: list of :class:`Table <google.cloud.bigtable.table.Table>`
:returns: The list of tables owned by the instance.
:raises: :class:`ValueError <exceptions.ValueError>` if one of the
Expand Down
52 changes: 33 additions & 19 deletions docs/bigtable/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def snippet(func):
def bigtable_create_instance(client, to_delete):
# [START bigtable_create_prod_instance]
from google.cloud.bigtable import enums

location_id = 'us-central1-f'
serve_nodes = 3
storage_type = enums.StorageType.SSD
Expand All @@ -58,11 +58,13 @@ def bigtable_create_instance(client, to_delete):
@snippet
def bigtable_create_cluster(client):
# [START bigtable_create_cluster]
from google.cloud.bigtable import enums

instance = client.instance("instance_my1")
location_id = 'us-central1-a'
serve_nodes = 3
storage_type = enums.StorageType.SSD

cluster = instance.cluster("cluster_my2", location_id=location_id,
serve_nodes=serve_nodes,
default_storage_type=storage_type)
Expand All @@ -73,7 +75,6 @@ def bigtable_create_cluster(client):
@snippet
def bigtable_list_instances(client):
# [START bigtable_list_instances]
print '\nListing Instances:'
for instance_local in client.list_instances()[0]:
print instance_local.instance_id
# [END bigtable_list_instances]
Expand All @@ -88,7 +89,7 @@ def bigtable_list_clusters(client):
labels = {'prod-label': 'prod-label'}
instance = client.instance("instance_my1", instance_type=production,
labels=labels)

for cluster in instance.list_clusters()[0]:
print cluster.cluster_id
# [END bigtable_list_clusters]
Expand All @@ -97,40 +98,34 @@ def bigtable_list_clusters(client):
@snippet
def bigtable_instance_exists(client):
# [START bigtable_check_instance_exists]
from google.cloud.bigtable import enums
instance = client.instance("instance_my1")
if instance.exists():
print 'Instance {} exists.'.format(instance_id)
print 'Instance {} exists.'.format("instance_my1")
# [END bigtable_check_instance_exists]


@snippet
def bigtable_cluster_exists(client):
from google.cloud.bigtable import enums
instance = client.instance("instance_my1")

# [START bigtable_check_cluster_exists]
location_id = 'us-central1-a'
serve_nodes = 3
storage_type = enums.StorageType.SSD
storage_type = enums.StorageType.SSD
cluster = instance.cluster("ssd-cluster1", location_id=location_id,
serve_nodes=serve_nodes,
default_storage_type=storage_type)
if cluster.exists():
print '\nCluster {} already exists.'.format(cluster_id)
print '\nCluster {} already exists.'.format("ssd-cluster1")
# [END bigtable_check_cluster_exists]


@snippet
def bigtable_delete_instance(client):
# [START bigtable_delete_instance]
instance = client.instance("instance_my1")
print '\nDeleting Instance'
if not instance.exists():
print 'Instance {} does not exists.'.format(instance_id)
else:
instance.delete()
print 'Deleted Instance: {}'.format(instance_id)
instance.delete()
# [END bigtable_delete_instance]


Expand All @@ -145,6 +140,25 @@ def bigtable_delete_cluster(client):
# [END bigtable_delete_cluster]


@snippet
def bigtable_create_table(client):
# [START bigtable_create_table]
instance = client.instance("instance_my1")
table = instance.table("table_my")
table.create()
# [END bigtable_create_table]


@snippet
def bigtable_list_tables(client):
# [START bigtable_list_tables]
instance = client.instance("instance_my1")
tables = instance.list_tables()
for tbl in tables:
print tbl.table_id
# [END bigtable_list_tables]


def _line_no(func):
code = getattr(func, '__code__', None) or getattr(func, 'func_code')
return code.co_firstlineno
Expand All @@ -164,14 +178,14 @@ def _name_and_doc(func):
def main():
client = bigtable.Client(project='my-project', admin=True)
for example in _find_examples():
to_delete = []
print('%-25s: %s' % _name_and_doc(example))
to_delete = []
print '%-25s: %s' % _name_and_doc(example)

This comment was marked as spam.

This comment was marked as spam.

try:
example(client, to_delete)
except AssertionError as failure:
print(' FAIL: %s' % (failure,))
print ' FAIL: %s' % (failure,)
except Exception as error: # pylint: disable=broad-except
print(' ERROR: %r' % (error,))
print ' ERROR: %r' % (error,)
for item in to_delete:
item.delete()

Expand Down