def create(self): """Create this cluster. .. note:: Uses the ``project``, ``instance`` and ``cluster_id`` on the current :class:`Cluster` in addition to the ``serve_nodes``. To change them before creating, reset the values via .. code:: python cluster.serve_nodes = 8 cluster.cluster_id = 'i-changed-my-mind' before calling :meth:`create`. :rtype: :class:`Operation` :returns: The long-running operation corresponding to the create operation. """ client = self._instance._client # We expect a `google.longrunning.operations_pb2.Operation`. request_pb = _prepare_create_request(self) operation_pb = client._instance_stub.CreateCluster(request_pb) operation_future = operation.from_grpc( operation_pb, client._operations_stub, data_v2_pb2.Cluster, metadata_type=messages_v2_pb2.UpdateClusterMetadata) return operation_future
def update(self): """Update this cluster. .. note:: Updates the ``serve_nodes``. If you'd like to change them before updating, reset the values via .. code:: python cluster.serve_nodes = 8 before calling :meth:`update`. :rtype: :class:`Operation` :returns: The long-running operation corresponding to the update operation. """ client = self._instance._client # We expect a `google.longrunning.operations_pb2.Operation`. request_pb = data_v2_pb2.Cluster( name=self.name, serve_nodes=self.serve_nodes, ) operation_pb = client._instance_stub.UpdateCluster(request_pb) operation_future = operation.from_grpc( operation_pb, client._operations_stub, data_v2_pb2.Cluster, metadata_type=messages_v2_pb2.UpdateClusterMetadata) return operation_future
def create(self): """Create this instance. .. note:: Uses the ``project`` and ``instance_id`` on the current :class:`Instance` in addition to the ``display_name``. To change them before creating, reset the values via .. code:: python instance.display_name = 'New display name' instance.instance_id = 'i-changed-my-mind' before calling :meth:`create`. :rtype: :class:`Operation` :returns: The long-running operation corresponding to the create operation. """ request_pb = _prepare_create_request(self) # We expect a `google.longrunning.operations_pb2.Operation`. operation_pb = self._client._instance_stub.CreateInstance(request_pb) operation_future = operation.from_grpc( operation_pb, self._client._operations_stub, data_v2_pb2.Instance, metadata_type=messages_v2_pb2.CreateInstanceMetadata) return operation_future
def test_from_grpc(): operation_proto = make_operation_proto(done=True) operations_stub = mock.sentinel.operations_stub future = operation.from_grpc( operation_proto, operations_stub, struct_pb2.Struct, metadata_type=struct_pb2.Struct) assert future._result_type == struct_pb2.Struct assert future._metadata_type == struct_pb2.Struct assert future.operation.name == TEST_OPERATION_NAME assert future.done
def test_from_grpc(): operation_proto = make_operation_proto(done=True) operations_stub = mock.sentinel.operations_stub future = operation.from_grpc( operation_proto, operations_stub, struct_pb2.Struct, metadata_type=struct_pb2.Struct, grpc_metadata=[("x-goog-request-params", "foo")], ) assert future._result_type == struct_pb2.Struct assert future._metadata_type == struct_pb2.Struct assert future.operation.name == TEST_OPERATION_NAME assert future.done assert future._refresh.keywords["metadata"] == [("x-goog-request-params", "foo")] assert future._cancel.keywords["metadata"] == [("x-goog-request-params", "foo")]