def delete_instance(self, name, options=None):
        """
        Deletes an instance.

        Immediately upon completion of the request:

        * Billing ceases for all of the instance's reserved resources.

        Soon afterward:

        * The instance and *all of its databases* immediately and
          irrevocably disappear from the API. All data in the databases
          is permanently deleted.

        Example:
            >>> from google.cloud import spanner_admin_instance_v1
            >>>
            >>> client = spanner_admin_instance_v1.InstanceAdminClient()
            >>>
            >>> name = client.instance_path('[PROJECT]', '[INSTANCE]')
            >>>
            >>> client.delete_instance(name)

        Args:
            name (str): Required. The name of the instance to be deleted. Values are of the form
                ``projects/<project>/instances/<instance>``
            options (~google.gax.CallOptions): Overrides the default
                settings for this call, e.g, timeout, retries etc.

        Raises:
            :exc:`google.gax.errors.GaxError` if the RPC is aborted.
            :exc:`ValueError` if the parameters are invalid.
        """
        request = spanner_instance_admin_pb2.DeleteInstanceRequest(name=name)
        self._delete_instance(request, options)
Esempio n. 2
0
    def delete_instance(self,
                        name,
                        retry=google.api_core.gapic_v1.method.DEFAULT,
                        timeout=google.api_core.gapic_v1.method.DEFAULT,
                        metadata=None):
        """
        Deletes an instance.

        Immediately upon completion of the request:

        -  Billing ceases for all of the instance's reserved resources.

        Soon afterward:

        -  The instance and *all of its databases* immediately and irrevocably
           disappear from the API. All data in the databases is permanently
           deleted.

        Example:
            >>> from google.cloud import spanner_admin_instance_v1
            >>>
            >>> client = spanner_admin_instance_v1.InstanceAdminClient()
            >>>
            >>> name = client.instance_path('[PROJECT]', '[INSTANCE]')
            >>>
            >>> client.delete_instance(name)

        Args:
            name (str): Required. The name of the instance to be deleted. Values are of the form
                ``projects/<project>/instances/<instance>``
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if 'delete_instance' not in self._inner_api_calls:
            self._inner_api_calls[
                'delete_instance'] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.delete_instance,
                    default_retry=self._method_configs['DeleteInstance'].retry,
                    default_timeout=self._method_configs['DeleteInstance'].
                    timeout,
                    client_info=self._client_info,
                )

        request = spanner_instance_admin_pb2.DeleteInstanceRequest(name=name, )
        self._inner_api_calls['delete_instance'](
            request, retry=retry, timeout=timeout, metadata=metadata)
    def test_delete_instance(self):
        channel = ChannelStub()
        client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

        # Setup Request
        name = client.instance_path('[PROJECT]', '[INSTANCE]')

        client.delete_instance(name)

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.DeleteInstanceRequest(
            name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 4
0
    def test_delete_instance(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = spanner_admin_instance_v1.InstanceAdminClient()

        # Setup Request
        name = client.instance_path("[PROJECT]", "[INSTANCE]")

        client.delete_instance(name)

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.DeleteInstanceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_delete_instance(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = spanner_admin_instance_v1.InstanceAdminClient()

        # Mock request
        name = client.instance_path('[PROJECT]', '[INSTANCE]')

        client.delete_instance(name)

        grpc_stub.DeleteInstance.assert_called_once()
        args, kwargs = grpc_stub.DeleteInstance.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = spanner_instance_admin_pb2.DeleteInstanceRequest(
            name=name)
        self.assertEqual(expected_request, actual_request)