Skip to content

Commit 893e241

Browse files
sumit-qltseaver
authored andcommitted
Bigtable : Add 'Instance._state' property (googleapis#5736)
1 parent 2bcc689 commit 893e241

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

bigtable/google/cloud/bigtable/instance.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,29 @@ class Instance(object):
7979
be associated with a given resource. Label values must
8080
be between 0 and 63 characters long. Keys and values
8181
must both be under 128 bytes.
82+
83+
:type _state: int
84+
:param _state: (`OutputOnly`)
85+
The current state of the instance.
86+
Possible values are represented by the following constants:
87+
:data:`google.cloud.bigtable.enums.Instance.State.STATE_NOT_KNOWN`.
88+
:data:`google.cloud.bigtable.enums.Instance.State.READY`.
89+
:data:`google.cloud.bigtable.enums.Instance.State.CREATING`.
8290
"""
8391

8492
def __init__(self,
8593
instance_id,
8694
client,
8795
display_name=None,
8896
instance_type=None,
89-
labels=None):
97+
labels=None,
98+
_state=None):
9099
self.instance_id = instance_id
91100
self._client = client
92101
self.display_name = display_name or instance_id
93102
self.type_ = instance_type
94103
self.labels = labels
104+
self._state = _state
95105

96106
@classmethod
97107
def from_pb(cls, instance_pb, client):
@@ -119,6 +129,7 @@ def from_pb(cls, instance_pb, client):
119129
raise ValueError('Project ID on instance does not match the '
120130
'project ID on the client')
121131
instance_id = match.group('instance_id')
132+
122133
result = cls(instance_id, client)
123134
result._update_from_pb(instance_pb)
124135
return result
@@ -132,6 +143,7 @@ def _update_from_pb(self, instance_pb):
132143
self.display_name = instance_pb.display_name
133144
self.type_ = instance_pb.type
134145
self.labels = dict(instance_pb.labels)
146+
self._state = instance_pb.state
135147

136148
@property
137149
def name(self):
@@ -151,6 +163,11 @@ def name(self):
151163
return self._client.instance_admin_client.instance_path(
152164
project=self._client.project, instance=self.instance_id)
153165

166+
@property
167+
def state(self):
168+
"""google.cloud.bigtable.enums.Instance.State: state of Instance."""
169+
return self._state
170+
154171
def __eq__(self, other):
155172
if not isinstance(other, self.__class__):
156173
return NotImplemented

bigtable/tests/system.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def test_create_instance_defaults(self):
176176
def test_create_instance(self):
177177
from google.cloud.bigtable import enums
178178
_DEVELOPMENT = enums.Instance.Type.DEVELOPMENT
179+
_STATE = enums.Instance.State.READY
179180

180181
ALT_INSTANCE_ID = 'new' + unique_resource_id('-')
181182
instance = Config.CLIENT.instance(ALT_INSTANCE_ID,
@@ -198,6 +199,7 @@ def test_create_instance(self):
198199
self.assertEqual(instance.display_name, instance_alt.display_name)
199200
self.assertEqual(instance.type_, instance_alt.type_)
200201
self.assertEqual(instance_alt.labels, LABELS)
202+
self.assertEqual(_STATE, instance_alt.state)
201203

202204
def test_cluster_exists(self):
203205
NONEXISTING_CLUSTER_ID = 'cluster-id'

bigtable/tests/unit/test_instance.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,26 @@ def test_constructor_defaults(self):
9393
self.assertIsNone(instance.type_)
9494
self.assertIsNone(instance.labels)
9595
self.assertIs(instance._client, client)
96+
self.assertIsNone(instance.state)
9697

9798
def test_constructor_non_default(self):
9899
from google.cloud.bigtable import enums
99100

100101
instance_type = enums.Instance.Type.DEVELOPMENT
102+
state = enums.Instance.State.READY
101103
labels = {'test': 'test'}
102104
client = object()
103105

104106
instance = self._make_one(self.INSTANCE_ID, client,
105107
display_name=self.DISPLAY_NAME,
106108
instance_type=instance_type,
107-
labels=labels)
109+
labels=labels, _state=state)
108110
self.assertEqual(instance.instance_id, self.INSTANCE_ID)
109111
self.assertEqual(instance.display_name, self.DISPLAY_NAME)
110112
self.assertEqual(instance.type_, instance_type)
111113
self.assertEqual(instance.labels, labels)
112114
self.assertIs(instance._client, client)
115+
self.assertEqual(instance.state, state)
113116

114117
def test_table_factory(self):
115118
from google.cloud.bigtable.table import Table
@@ -209,10 +212,12 @@ def test__update_from_pb_success(self):
209212
from google.cloud.bigtable import enums
210213

211214
instance_type = enums.Instance.Type.PRODUCTION
215+
state = enums.Instance.State.READY
212216
instance_pb = data_v2_pb2.Instance(
213217
display_name=self.DISPLAY_NAME,
214218
type=instance_type,
215-
labels=self.LABELS
219+
labels=self.LABELS,
220+
state=state
216221
)
217222

218223
instance = self._make_one(None, None)
@@ -223,6 +228,7 @@ def test__update_from_pb_success(self):
223228
self.assertEqual(instance.display_name, self.DISPLAY_NAME)
224229
self.assertEqual(instance.type_, instance_type)
225230
self.assertEqual(instance.labels, self.LABELS)
231+
self.assertEqual(instance._state, state)
226232

227233
def test__update_from_pb_success_defaults(self):
228234
from google.cloud.bigtable_admin_v2.proto import (
@@ -261,11 +267,13 @@ def test_from_pb_success(self):
261267
client = _Client(project=self.PROJECT)
262268

263269
instance_type = enums.Instance.Type.PRODUCTION
270+
state = enums.Instance.State.READY
264271
instance_pb = data_v2_pb2.Instance(
265272
name=self.INSTANCE_NAME,
266273
display_name=self.INSTANCE_ID,
267274
type=instance_type,
268-
labels=self.LABELS
275+
labels=self.LABELS,
276+
state=state
269277
)
270278

271279
klass = self._get_target_class()
@@ -276,6 +284,7 @@ def test_from_pb_success(self):
276284
self.assertEqual(instance.display_name, self.INSTANCE_ID)
277285
self.assertEqual(instance.type_, instance_type)
278286
self.assertEqual(instance.labels, self.LABELS)
287+
self.assertEqual(instance._state, state)
279288

280289
def test_from_pb_bad_instance_name(self):
281290
from google.cloud.bigtable_admin_v2.proto import (

0 commit comments

Comments
 (0)