def get_instance( self, location: str, instance: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ): """ Gets the details of a specific Memcached instance. :param location: The location of the Cloud Memorystore instance (for example europe-west1) :param instance: The logical name of the Memcached instance in the customer project. :param project_id: Project ID of the project that contains the instance. If set to None or missing, the default project_id from the GCP connection is used. :param retry: A retry object used to retry requests. If ``None`` is specified, requests will not be retried. :param timeout: 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. :param metadata: Additional metadata that is provided to the method. """ client = self.get_conn() metadata = metadata or () name = CloudMemcacheClient.instance_path(project_id, location, instance) result = client.get_instance(name=name, retry=retry, timeout=timeout, metadata=metadata or ()) self.log.info("Fetched Instance: %s", name) return result
def update_instance( self, update_mask: Union[Dict, FieldMask], instance: Union[Dict, cloud_memcache.Instance], project_id: str, location: Optional[str] = None, instance_id: Optional[str] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ): """ Updates the metadata and configuration of a specific Memcached instance. :param update_mask: Required. Mask of fields to update. At least one path must be supplied in this field. The elements of the repeated paths field may only include these fields from ``Instance``: - ``displayName`` If a dict is provided, it must be of the same form as the protobuf message :class:`~google.protobuf.field_mask_pb2.FieldMask`) Union[Dict, google.protobuf.field_mask_pb2.FieldMask] :param instance: Required. Update description. Only fields specified in ``update_mask`` are updated. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.memcache_v1beta2.types.cloud_memcache.Instance` :param location: The location of the Cloud Memorystore instance (for example europe-west1) :param instance_id: The logical name of the Memcached instance in the customer project. :param project_id: Project ID of the project that contains the instance. If set to None or missing, the default project_id from the Google Cloud connection is used. :param retry: A retry object used to retry requests. If ``None`` is specified, requests will not be retried. :param timeout: 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. :param metadata: Additional metadata that is provided to the method. """ client = self.get_conn() metadata = metadata or () if isinstance(instance, dict): instance = cloud_memcache.Instance(instance) elif not isinstance(instance, cloud_memcache.Instance): raise AirflowException( "instance is not instance of Instance type or python dict") if location and instance_id: name = CloudMemcacheClient.instance_path(project_id, location, instance_id) instance.name = name self.log.info("Updating instances: %s", instance.name) result = client.update_instance(update_mask=update_mask, resource=instance, retry=retry, timeout=timeout, metadata=metadata or ()) result.result() self.log.info("Instance updated: %s", instance.name)
def update_parameters( self, update_mask: Union[Dict, FieldMask], parameters: Union[Dict, cloud_memcache.MemcacheParameters], project_id: str, location: str, instance_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ): """ Updates the defined Memcached Parameters for an existing Instance. This method only stages the parameters, it must be followed by apply_parameters to apply the parameters to nodes of the Memcached Instance. :param update_mask: Required. Mask of fields to update. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.protobuf.field_mask_pb2.FieldMask` Union[Dict, google.protobuf.field_mask_pb2.FieldMask] :param parameters: The parameters to apply to the instance. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.memcache_v1beta2.types.cloud_memcache.MemcacheParameters` :param location: The location of the Cloud Memorystore instance (for example europe-west1) :param instance_id: The logical name of the Memcached instance in the customer project. :param project_id: Project ID of the project that contains the instance. If set to None or missing, the default project_id from the Google Cloud connection is used. :param retry: A retry object used to retry requests. If ``None`` is specified, requests will not be retried. :param timeout: 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. :param metadata: Additional metadata that is provided to the method. """ client = self.get_conn() metadata = metadata or () if isinstance(parameters, dict): parameters = cloud_memcache.MemcacheParameters(parameters) elif not isinstance(parameters, cloud_memcache.MemcacheParameters): raise AirflowException( "instance is not instance of MemcacheParameters type or python dict" ) name = CloudMemcacheClient.instance_path(project_id, location, instance_id) self.log.info("Staging update to instance: %s", instance_id) result = client.update_parameters( name=name, update_mask=update_mask, parameters=parameters, retry=retry, timeout=timeout, metadata=metadata, ) result.result() self.log.info("Update staged for instance: %s", instance_id)
def apply_parameters( self, node_ids: Sequence[str], apply_all: bool, project_id: str, location: str, instance_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None, ): """ Will update current set of Parameters to the set of specified nodes of the Memcached Instance. :param node_ids: Nodes to which we should apply the instance-level parameter group. :type node_ids: Sequence[str] :param apply_all: Whether to apply instance-level parameter group to all nodes. If set to true, will explicitly restrict users from specifying any nodes, and apply parameter group updates to all nodes within the instance. :type apply_all: bool :param location: The location of the Cloud Memorystore instance (for example europe-west1) :type location: str :param instance_id: The logical name of the Memcached instance in the customer project. :type instance_id: str :param project_id: Project ID of the project that contains the instance. If set to None or missing, the default project_id from the Google Cloud connection is used. :type project_id: str :param retry: A retry object used to retry requests. If ``None`` is specified, requests will not be retried. :type retry: google.api_core.retry.Retry :param timeout: 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. :type timeout: float :param metadata: Additional metadata that is provided to the method. :type metadata: Sequence[Tuple[str, str]] """ client = self.get_conn() metadata = metadata or () name = CloudMemcacheClient.instance_path(project_id, location, instance_id) self.log.info("Applying update to instance: %s", instance_id) result = client.apply_parameters( name=name, node_ids=node_ids, apply_all=apply_all, retry=retry, timeout=timeout, metadata=metadata or (), ) result.result() self.log.info("Instance updated: %s", instance_id)
def create_instance( self, location: str, instance_id: str, instance: Union[Dict, cloud_memcache.Instance], project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None, ): """ Creates a Memcached instance based on the specified tier and memory size. By default, the instance is accessible from the project's `default network <https://cloud.google.com/compute/docs/networks-and-firewalls#networks>`__. :param location: The location of the Cloud Memorystore instance (for example europe-west1) :type location: str :param instance_id: Required. The logical name of the Memcached instance in the customer project with the following restrictions: - Must contain only lowercase letters, numbers, and hyphens. - Must start with a letter. - Must be between 1-40 characters. - Must end with a number or a letter. - Must be unique within the customer project / location :type instance_id: str :param instance: Required. A Memcached [Instance] resource If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.memcache_v1beta2.types.cloud_memcache.Instance` :type instance: Union[Dict, google.cloud.memcache_v1beta2.types.cloud_memcache.Instance] :param project_id: Project ID of the project that contains the instance. If set to None or missing, the default project_id from the GCP connection is used. :type project_id: str :param retry: A retry object used to retry requests. If ``None`` is specified, requests will not be retried. :type retry: google.api_core.retry.Retry :param timeout: 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. :type timeout: float :param metadata: Additional metadata that is provided to the method. :type metadata: Sequence[Tuple[str, str]] """ client = self.get_conn() metadata = metadata or () parent = path_template.expand( "projects/{project}/locations/{location}", project=project_id, location=location) instance_name = CloudMemcacheClient.instance_path( project_id, location, instance_id) try: instance = client.get_instance(name=instance_name, retry=retry, timeout=timeout, metadata=metadata) self.log.info("Instance exists. Skipping creation.") return instance except NotFound: self.log.info("Instance not exists.") if isinstance(instance, dict): instance = cloud_memcache.Instance(instance) elif not isinstance(instance, cloud_memcache.Instance): raise AirflowException( "instance is not instance of Instance type or python dict") self._append_label(instance, "airflow-version", "v" + version.version) result = client.create_instance( parent=parent, instance_id=instance_id, resource=instance, retry=retry, timeout=timeout, metadata=metadata or (), ) result.result() self.log.info("Instance created.") return client.get_instance( name=instance_name, retry=retry, timeout=timeout, metadata=metadata or (), )