list_network_load_balancers
Retrieve network load balancers in a specified Oracle Cloud compartment to monitor their IP addresses and operational status.
Instructions
List all network load balancers in a compartment.
Args:
compartment_id: OCID of the compartment to list network load balancers from
Returns:
List of network load balancers with their IP addresses and state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| compartment_id | Yes |
Implementation Reference
- mcp_server_oci/mcp_server.py:1246-1250 (registration)Registration of the MCP tool 'list_network_load_balancers' using the @mcp.tool decorator with custom wrapper for logging and error handling.@mcp.tool(name="list_network_load_balancers") @mcp_tool_wrapper( start_msg="Listing network load balancers in compartment {compartment_id}...", error_prefix="Error listing network load balancers" )
- mcp_server_oci/mcp_server.py:1251-1262 (handler)The MCP tool handler: an async function that takes compartment_id, retrieves the pre-initialized OCI NetworkLoadBalancerClient, and delegates to the helper function for execution.async def mcp_list_network_load_balancers(ctx: Context, compartment_id: str) -> List[Dict[str, Any]]: """ List all network load balancers in a compartment. Args: compartment_id: OCID of the compartment to list network load balancers from Returns: List of network load balancers with their IP addresses and state """ return list_network_load_balancers(oci_clients["network_load_balancer"], compartment_id)
- Core helper function that performs pagination using OCI SDK, iterates over results, extracts and formats key attributes (id, display_name, lifecycle_state, ip_addresses, etc.) into user-friendly dicts, with logging and error propagation.def list_network_load_balancers(network_load_balancer_client: oci.network_load_balancer.NetworkLoadBalancerClient, compartment_id: str) -> List[Dict[str, Any]]: """ List all network load balancers in a compartment. Args: network_load_balancer_client: OCI NetworkLoadBalancer client compartment_id: OCID of the compartment Returns: List of network load balancers with their details """ try: nlbs_response = oci.pagination.list_call_get_all_results( network_load_balancer_client.list_network_load_balancers, compartment_id ) nlbs = [] for nlb in nlbs_response.data: nlbs.append({ "id": nlb.id, "display_name": nlb.display_name, "compartment_id": nlb.compartment_id, "lifecycle_state": nlb.lifecycle_state, "time_created": str(nlb.time_created), "is_private": nlb.is_private, "ip_addresses": [ { "ip_address": ip.ip_address, "is_public": ip.is_public, "ip_version": ip.ip_version, } for ip in nlb.ip_addresses ] if nlb.ip_addresses else [], "subnet_id": nlb.subnet_id, "network_security_group_ids": nlb.network_security_group_ids, "is_preserve_source_destination": nlb.is_preserve_source_destination, }) logger.info(f"Found {len(nlbs)} network load balancers in compartment {compartment_id}") return nlbs except Exception as e: logger.exception(f"Error listing network load balancers: {e}") raise