attach_whitelist_template_to_instance
Apply a whitelist template to an Alibaba Cloud RDS instance to manage access permissions by specifying the region ID, instance ID, and template ID.
Instructions
allocate db instance public connection.
Args:
region_id: The region ID of the RDS instance.
db_instance_id: The ID of the RDS instance.
template_id: Whitelist Template ID. Can be obtained via DescribeAllWhitelistTemplate.
Returns:
dict[str, Any]: The response.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| db_instance_id | Yes | ||
| region_id | Yes | ||
| template_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"db_instance_id": {
"title": "Db Instance Id",
"type": "string"
},
"region_id": {
"title": "Region Id",
"type": "string"
},
"template_id": {
"title": "Template Id",
"type": "integer"
}
},
"required": [
"region_id",
"db_instance_id",
"template_id"
],
"title": "attach_whitelist_template_to_instanceArguments",
"type": "object"
}
Implementation Reference
- The main handler function that implements the 'attach_whitelist_template_to_instance' tool by calling the Alibaba Cloud RDS OpenAPI AttachWhitelistTemplateToInstance via the SDK.async def attach_whitelist_template_to_instance( region_id: str, db_instance_id: str, template_id: int ): """ allocate db instance public connection. Args: region_id: The region ID of the RDS instance. db_instance_id: The ID of the RDS instance. template_id: Whitelist Template ID. Can be obtained via DescribeAllWhitelistTemplate. Returns: dict[str, Any]: The response. """ try: client = get_rds_client(region_id) request = rds_20140815_models.AttachWhitelistTemplateToInstanceRequest( region_id=region_id, ins_name=db_instance_id, template_id=template_id ) response = await client.attach_whitelist_template_to_instance_async(request) return response.body.to_map() except Exception as e: raise e
- Helper tool to describe all whitelist templates, used to obtain template_id for the attach tool.async def describe_all_whitelist_template( region_id: str, template_name: str = None ) -> List[Dict[str, Any]]: """ describe all whitelist template. Args: region_id: The region ID of the RDS instance. template_name: The ID of the RDS instance. Returns: List[Dict[str, Any]]: The response contains all whitelist template information. """ try: client = get_rds_client(region_id) next_pages = True all_whitelists = [] page_num = 1 while next_pages: request = rds_20140815_models.DescribeAllWhitelistTemplateRequest( template_name=template_name, fuzzy_search=False if template_name is None else True, max_records_per_page=100, page_numbers=page_num ) response = await client.describe_all_whitelist_template_async(request) next_pages = response.body.data.has_next page_num += 1 all_whitelists.extend(response.body.data.templates) return [item.to_map() for item in all_whitelists] except Exception as e: raise e
- Helper tool to describe the whitelist template linked to an instance.async def describe_instance_linked_whitelist_template( region_id: str, db_instance_id: str ): """ describe instance linked whitelist template. Args: region_id: The region ID of the RDS instance. db_instance_id: The ID of the RDS instance. Returns: dict[str, Any]: The response. """ try: client = get_rds_client(region_id) request = rds_20140815_models.DescribeInstanceLinkedWhitelistTemplateRequest( region_id=region_id, ins_name=db_instance_id ) response = await client.describe_instance_linked_whitelist_template_async(request) return response.body.to_map() except Exception as e: raise e