Example #1
0
    def __init__(self,
                 channel=None,
                 credentials=None,
                 address="redis.googleapis.com:443"):
        """Instantiate the transport class.

        Args:
            channel (grpc.Channel): A ``Channel`` instance through
                which to make calls. This argument is mutually exclusive
                with ``credentials``; providing both will raise an exception.
            credentials (google.auth.credentials.Credentials): The
                authorization credentials to attach to requests. These
                credentials identify this application to the service. If none
                are specified, the client will attempt to ascertain the
                credentials from the environment.
            address (str): The address where the service is hosted.
        """
        # If both `channel` and `credentials` are specified, raise an
        # exception (channels come with credentials baked in already).
        if channel is not None and credentials is not None:
            raise ValueError(
                "The `channel` and `credentials` arguments are mutually "
                "exclusive.")

        # Create the channel.
        if channel is None:
            channel = self.create_channel(
                address=address,
                credentials=credentials,
                options={
                    "grpc.max_send_message_length": -1,
                    "grpc.max_receive_message_length": -1,
                }.items(),
            )

        self._channel = channel

        # gRPC uses objects called "stubs" that are bound to the
        # channel and provide a basic method for each RPC.
        self._stubs = {
            "cloud_redis_stub": cloud_redis_pb2_grpc.CloudRedisStub(channel)
        }

        # Because this API includes a method that returns a
        # long-running operation (proto: google.longrunning.Operation),
        # instantiate an LRO client.
        self._operations_client = google.api_core.operations_v1.OperationsClient(
            channel)
    def __init__(self,
                 channel=None,
                 credentials=None,
                 client_config=cloud_redis_client_config.config,
                 client_info=None):
        """Constructor.

        Args:
            channel (grpc.Channel): A ``Channel`` instance through
                which to make calls. This argument is mutually exclusive
                with ``credentials``; providing both will raise an exception.
            credentials (google.auth.credentials.Credentials): The
                authorization credentials to attach to requests. These
                credentials identify this application to the service. If none
                are specified, the client will attempt to ascertain the
                credentials from the environment.
            client_config (dict): A dictionary of call options for each
                method. If not specified, the default configuration is used.
            client_info (google.api_core.gapic_v1.client_info.ClientInfo):
                The client info used to send a user-agent string along with
                API requests. If ``None``, then default info will be used.
                Generally, you only need to set this if you're developing
                your own client library.
        """
        # If both `channel` and `credentials` are specified, raise an
        # exception (channels come with credentials baked in already).
        if channel is not None and credentials is not None:
            raise ValueError(
                'The `channel` and `credentials` arguments to {} are mutually '
                'exclusive.'.format(self.__class__.__name__), )

        # Create the channel.
        if channel is None:
            channel = google.api_core.grpc_helpers.create_channel(
                self.SERVICE_ADDRESS,
                credentials=credentials,
                scopes=self._DEFAULT_SCOPES,
            )

        # Create the gRPC stubs.
        self.cloud_redis_stub = (cloud_redis_pb2_grpc.CloudRedisStub(channel))

        # Operations client for methods that return long-running operations
        # futures.
        self.operations_client = (
            google.api_core.operations_v1.OperationsClient(channel))

        if client_info is None:
            client_info = (
                google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO)
        client_info.gapic_version = _GAPIC_LIBRARY_VERSION

        # Parse out the default settings for retry and timeout for each RPC
        # from the client configuration.
        # (Ordinarily, these are the defaults specified in the `*_config.py`
        # file next to this one.)
        method_configs = google.api_core.gapic_v1.config.parse_method_configs(
            client_config['interfaces'][self._INTERFACE_NAME], )

        # Write the "inner API call" methods to the class.
        # These are wrapped versions of the gRPC stub methods, with retry and
        # timeout configuration applied, called by the public methods on
        # this class.
        self._list_instances = google.api_core.gapic_v1.method.wrap_method(
            self.cloud_redis_stub.ListInstances,
            default_retry=method_configs['ListInstances'].retry,
            default_timeout=method_configs['ListInstances'].timeout,
            client_info=client_info,
        )
        self._get_instance = google.api_core.gapic_v1.method.wrap_method(
            self.cloud_redis_stub.GetInstance,
            default_retry=method_configs['GetInstance'].retry,
            default_timeout=method_configs['GetInstance'].timeout,
            client_info=client_info,
        )
        self._create_instance = google.api_core.gapic_v1.method.wrap_method(
            self.cloud_redis_stub.CreateInstance,
            default_retry=method_configs['CreateInstance'].retry,
            default_timeout=method_configs['CreateInstance'].timeout,
            client_info=client_info,
        )
        self._update_instance = google.api_core.gapic_v1.method.wrap_method(
            self.cloud_redis_stub.UpdateInstance,
            default_retry=method_configs['UpdateInstance'].retry,
            default_timeout=method_configs['UpdateInstance'].timeout,
            client_info=client_info,
        )
        self._delete_instance = google.api_core.gapic_v1.method.wrap_method(
            self.cloud_redis_stub.DeleteInstance,
            default_retry=method_configs['DeleteInstance'].retry,
            default_timeout=method_configs['DeleteInstance'].timeout,
            client_info=client_info,
        )