describe_vswitches
Retrieve detailed information about VSwitches within Alibaba Cloud RDS by specifying region, VPC, zone, or other parameters to filter and organize results efficiently.
Instructions
Query VSwitch list.
Args:
region_id: The region ID of the VSwitch. At least one of region_id or vpc_id must be specified.
vpc_id: The ID of the VPC to which the VSwitch belongs. At least one of region_id or vpc_id must be specified.
vswitch_id: The ID of the VSwitch to query.
zone_id: The zone ID of the VSwitch.
vswitch_name: The name of the VSwitch.
resource_group_id: The resource group ID of the VSwitch.
page_number: The page number of the list. Default: 1.
page_size: The number of entries per page. Maximum value: 50. Default: 10.
Returns:
Dict[str, Any]: The response containing the list of VSwitches.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| is_default | No | ||
| page_number | No | ||
| page_size | No | ||
| region_id | No | ||
| resource_group_id | No | ||
| vpc_id | No | ||
| vswitch_id | No | ||
| vswitch_name | No | ||
| zone_id | No |
Input Schema (JSON Schema)
{
"properties": {
"is_default": {
"default": null,
"title": "Is Default",
"type": "boolean"
},
"page_number": {
"default": 1,
"title": "Page Number",
"type": "integer"
},
"page_size": {
"default": 10,
"title": "Page Size",
"type": "integer"
},
"region_id": {
"default": null,
"title": "Region Id",
"type": "string"
},
"resource_group_id": {
"default": null,
"title": "Resource Group Id",
"type": "string"
},
"vpc_id": {
"default": null,
"title": "Vpc Id",
"type": "string"
},
"vswitch_id": {
"default": null,
"title": "Vswitch Id",
"type": "string"
},
"vswitch_name": {
"default": null,
"title": "Vswitch Name",
"type": "string"
},
"zone_id": {
"default": null,
"title": "Zone Id",
"type": "string"
}
},
"title": "describe_vswitchesArguments",
"type": "object"
}
Implementation Reference
- The main handler function for the 'describe_vswitches' tool. It queries VSwitch information using the Alibaba Cloud VPC SDK.@mcp.tool(annotations=READ_ONLY_TOOL) async def describe_vswitches( region_id: str = None, vpc_id: str = None, vswitch_id: str = None, zone_id: str = None, vswitch_name: str = None, is_default: bool = None, resource_group_id: str = None, page_number: int = 1, page_size: int = 10, ) -> Dict[str, Any]: """Query VSwitch list. Args: region_id: The region ID of the VSwitch. At least one of region_id or vpc_id must be specified. vpc_id: The ID of the VPC to which the VSwitch belongs. At least one of region_id or vpc_id must be specified. vswitch_id: The ID of the VSwitch to query. zone_id: The zone ID of the VSwitch. vswitch_name: The name of the VSwitch. resource_group_id: The resource group ID of the VSwitch. page_number: The page number of the list. Default: 1. page_size: The number of entries per page. Maximum value: 50. Default: 10. Returns: Dict[str, Any]: The response containing the list of VSwitches. """ try: # Initialize the client if not region_id and not vpc_id: raise OpenAPIError("At least one of region_id or vpc_id must be specified") client = get_vpc_client(region_id) # Create request request = vpc_20160428_models.DescribeVSwitchesRequest( page_number=page_number, page_size=page_size ) # Add optional parameters if provided if vpc_id: request.vpc_id = vpc_id if vswitch_id: request.vswitch_id = vswitch_id if zone_id: request.zone_id = zone_id if vswitch_name: request.vswitch_name = vswitch_name if is_default is not None: request.is_default = is_default if resource_group_id: request.resource_group_id = resource_group_id # Make the API request response = client.describe_vswitches(request) return response.body.to_map() except Exception as e: logger.error(f"Error occurred while querying VSwitches: {str(e)}") raise OpenAPIError(f"Failed to query VSwitches: {str(e)}")
- Helper function to create and configure the VPC client used by the describe_vswitches handler.def get_vpc_client(region_id: str) -> VpcClient: """Get VPC client instance. Args: region_id: The region ID for the VPC client. Returns: VpcClient: The VPC client instance for the specified region. """ ak, sk, sts = get_aksk() config = Config( access_key_id=ak, access_key_secret=sk, security_token=sts, region_id=region_id, protocol="https", connect_timeout=10 * 1000, read_timeout=300 * 1000 ) return VpcClient(config)
- Import for the VPC client class.from alibabacloud_vpc20160428.client import Client as VpcClient
- Import for VPC models used in the request.from alibabacloud_vpc20160428 import models as vpc_20160428_models