コード例 #1
0
    def get_instance_config(self, name, options=None):
        """
        Gets information about a particular instance configuration.

        Example:
            >>> from google.cloud import spanner_admin_instance_v1
            >>>
            >>> client = spanner_admin_instance_v1.InstanceAdminClient()
            >>>
            >>> name = client.instance_config_path('[PROJECT]', '[INSTANCE_CONFIG]')
            >>>
            >>> response = client.get_instance_config(name)

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

        Returns:
            A :class:`~google.cloud.spanner_admin_instance_v1.types.InstanceConfig` instance.

        Raises:
            :exc:`google.gax.errors.GaxError` if the RPC is aborted.
            :exc:`ValueError` if the parameters are invalid.
        """
        request = spanner_instance_admin_pb2.GetInstanceConfigRequest(
            name=name)
        return self._get_instance_config(request, options)
    def test_get_instance_config(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_config_path('[PROJECT]', '[INSTANCE_CONFIG]')

        # Mock response
        name_2 = 'name2-1052831874'
        display_name = 'displayName1615086568'
        expected_response = {'name': name_2, 'display_name': display_name}
        expected_response = spanner_instance_admin_pb2.InstanceConfig(
            **expected_response)
        grpc_stub.GetInstanceConfig.return_value = expected_response

        response = client.get_instance_config(name)
        self.assertEqual(expected_response, response)

        grpc_stub.GetInstanceConfig.assert_called_once()
        args, kwargs = grpc_stub.GetInstanceConfig.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.GetInstanceConfigRequest(
            name=name)
        self.assertEqual(expected_request, actual_request)
コード例 #3
0
    def test_get_instance_config(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        display_name = "displayName1615086568"
        expected_response = {"name": name_2, "display_name": display_name}
        expected_response = spanner_instance_admin_pb2.InstanceConfig(
            **expected_response
        )

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        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_config_path("[PROJECT]", "[INSTANCE_CONFIG]")

        response = client.get_instance_config(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.GetInstanceConfigRequest(
            name=name
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #4
0
    def get_instance_config(
        self,
        name,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Gets information about a particular instance configuration.

        Example:
            >>> from google.cloud import spanner_admin_instance_v1
            >>>
            >>> client = spanner_admin_instance_v1.InstanceAdminClient()
            >>>
            >>> name = client.instance_config_path('[PROJECT]', '[INSTANCE_CONFIG]')
            >>>
            >>> response = client.get_instance_config(name)

        Args:
            name (str): Required. The name of the requested instance configuration. Values are
                of the form ``projects/<project>/instanceConfigs/<config>``.
            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.

        Returns:
            A :class:`~google.cloud.spanner_admin_instance_v1.types.InstanceConfig` instance.

        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 "get_instance_config" not in self._inner_api_calls:
            self._inner_api_calls[
                "get_instance_config"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.get_instance_config,
                    default_retry=self._method_configs["GetInstanceConfig"].
                    retry,
                    default_timeout=self._method_configs["GetInstanceConfig"].
                    timeout,
                    client_info=self._client_info,
                )

        request = spanner_instance_admin_pb2.GetInstanceConfigRequest(
            name=name)
        return self._inner_api_calls["get_instance_config"](request,
                                                            retry=retry,
                                                            timeout=timeout,
                                                            metadata=metadata)
コード例 #5
0
    def test_get_instance_config(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        display_name = 'displayName1615086568'
        expected_response = {'name': name_2, 'display_name': display_name}
        expected_response = spanner_instance_admin_pb2.InstanceConfig(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel)

        # Setup Request
        name = client.instance_config_path('[PROJECT]', '[INSTANCE_CONFIG]')

        response = client.get_instance_config(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = spanner_instance_admin_pb2.GetInstanceConfigRequest(
            name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request