From 9789a3162627594d668165a95286ed5e1f205abe Mon Sep 17 00:00:00 2001 From: jkallem Date: Wed, 21 Aug 2024 12:33:06 -0700 Subject: [PATCH] Resolving the Comments for Example --- .../fabricv4/cloud_router/cloud_router.py | 22 ++------ .../cloud_router/cloud_router_management.py | 50 ------------------- .../connections/connection_management.py | 14 ------ .../connections/fcr_2_aws_connection.py | 8 +-- .../connections/fcr_2_azure_connection.py | 8 +-- .../connections/fcr_2_port_connection.py | 40 +++------------ .../oauth2/configure_client_credentials.py | 33 ------------ 7 files changed, 17 insertions(+), 158 deletions(-) diff --git a/examples/services/fabricv4/cloud_router/cloud_router.py b/examples/services/fabricv4/cloud_router/cloud_router.py index 00855498..b50d080a 100644 --- a/examples/services/fabricv4/cloud_router/cloud_router.py +++ b/examples/services/fabricv4/cloud_router/cloud_router.py @@ -1,5 +1,5 @@ from examples.services.fabricv4.utils import utils -from equinix.services import fabricv4 as module +from equinix.services import fabricv4 import cloud_router_management @@ -14,18 +14,10 @@ Construct a `CloudRouterPostRequest` object using the `module.CloudRouterPostRequest` class. This object contains the details required to create the Fabric Cloud Router. - - Notes: - - Ensure that the necessary modules and classes (e.g., `CloudRouterPostRequest`) are imported - and accessible before invoking this method. - - The values provided in the request object are hardcoded for this example; modify them according - to your requirements. - - This method only constructs and logs the request object; it does not send the request to the API. - You may need to call an appropriate method or function to execute the API call. """ utils.pr_yellow('\nCreate Fabric Cloud Router') - fcr_request = module.CloudRouterPostRequest( + fcr_request = CloudRouterPostRequest( type="XF_ROUTER", name="Python_FCR", location={"metro_code": "SV"}, @@ -61,17 +53,9 @@ This method performs an update operation on a specified Fabric Cloud Router by replacing the current name with a new one. It leverages the Equinix Fabric API to execute this change. - - Notes: - ----- - - Ensure that the provided UUID corresponds to an existing Fabric Cloud Router. - - The `op` field in `CloudRouterChangeOperation` is set to "replace", which indicates that the current name - of the router will be replaced with the new name. - - The `path` field is set to "/name", which specifies that the operation targets the name attribute of the router. - - The `value` field is set to the new name provided by the user. """ - update_name = [module.CloudRouterChangeOperation( + update_name = [CloudRouterChangeOperation( op="replace", path="/name", value="panthers-test-updated1" diff --git a/examples/services/fabricv4/cloud_router/cloud_router_management.py b/examples/services/fabricv4/cloud_router/cloud_router_management.py index 34b92a99..7f77ce62 100644 --- a/examples/services/fabricv4/cloud_router/cloud_router_management.py +++ b/examples/services/fabricv4/cloud_router/cloud_router_management.py @@ -9,20 +9,6 @@ """ Create a Fabric Cloud Router (FCR) using the provided request payload. - - Args: - fcr_request: An instance of the request payload object for creating a Fabric Cloud Router. - - Returns: - str: The UUID of the created Fabric Cloud Router. - - Steps: - 1. Print the FCR request payload. - 2. Initialize the Equinix Fabric client. - 3. Call the create_cloud_router API method with the request payload. - 4. Parse and format the API response into JSON. - 5. Print the creation response and the UUID of the created FCR. - 6. Return the UUID of the created FCR. """ @@ -43,18 +29,6 @@ def create_fcr(fcr_request): """ Retrieve the details of an existing Fabric Cloud Router (FCR) by its UUID. - - Args: - fcr_uuid (str): The UUID of the Fabric Cloud Router to retrieve. - - Returns: - None: This method prints the details of the FCR to the console. - - Steps: - 1. Initialize the Equinix Fabric client. - 2. Call the get_cloud_router_by_uuid API method with the UUID. - 3. Parse and format the API response into JSON. - 4. Print the response with the FCR details. """ @@ -71,19 +45,6 @@ def get_fcr_uuid(fcr_uuid): """ Update an existing Fabric Cloud Router (FCR) using the provided UUID and update payload. - - Args: - fcr_uuid (str): The UUID of the Fabric Cloud Router to update. - update_payload: An instance of the update payload object containing the updates for the FCR. - - Returns: - None: This method prints the update response to the console. - - Steps: - 1. Initialize the Equinix Fabric client. - 2. Call the update_cloud_router_by_uuid API method with the UUID and update payload. - 3. Parse and format the API response into JSON. - 4. Print the response with the updated FCR details. """ @@ -100,17 +61,6 @@ def update_fcr_by_uuid(fcr_uuid, update_payload): """ Delete an existing Fabric Cloud Router (FCR) using the provided UUID. - - Args: - fcr_uuid (str): The UUID of the Fabric Cloud Router to delete. - - Returns: - None: This method prints the deletion response to the console. - - Steps: - 1. Initialize the Equinix Fabric client. - 2. Call the delete_cloud_router_by_uuid API method with the UUID. - 3. Print the deletion response. """ diff --git a/examples/services/fabricv4/connections/connection_management.py b/examples/services/fabricv4/connections/connection_management.py index 52393bcf..983241c4 100644 --- a/examples/services/fabricv4/connections/connection_management.py +++ b/examples/services/fabricv4/connections/connection_management.py @@ -16,16 +16,6 @@ def create_fcr_connection(fcr_uuid, fcr2colo_request): This method handles the process of establishing a connection between a Fabric Cloud Router (FCR) and a colocation or another FCR within the Equinix Fabric. It generates the connection request payload, sends the request to the Equinix Fabric API, and returns the unique identifier (UUID) of the created connection. - - Returns: - str: The UUID of the newly created connection, which can be used for further operations like querying the connection - status, updating, or deleting the connection. - - Example Usage: - fcr_uuid = "1234-abcd-5678-efgh" - fcr2colo_request = FCRConnectionRequest(...) # An instance of a request object with necessary attributes. - connection_uuid = create_fcr_connection(fcr_uuid, fcr2colo_request) - print(f"Created FCR Connection UUID: {connection_uuid}") """ utils.pr_purple('\nFCR Connection Request Payload:\n') ic(fcr2colo_request.to_json()) @@ -48,10 +38,6 @@ def configure_routing_protocol(connection_uuid,routing_protocol_request): specified routing protocol request. The method leverages the Equinix Fabric API to create the routing protocol associated with the connection. The response from the API is formatted and printed for verification. - - This would configure a BGP routing protocol for the specified connection, using - the provided ASNs and authentication key, and then print the response from the - Equinix Fabric API. """ rp_type = fabricv4.RoutingProtocolBase(routing_protocol_request) client = configure_client_credentials.get_equinix_fabric_client() diff --git a/examples/services/fabricv4/connections/fcr_2_aws_connection.py b/examples/services/fabricv4/connections/fcr_2_aws_connection.py index 28245ae2..f57e9ecb 100644 --- a/examples/services/fabricv4/connections/fcr_2_aws_connection.py +++ b/examples/services/fabricv4/connections/fcr_2_aws_connection.py @@ -2,7 +2,7 @@ import os from examples.services.fabricv4.utils import utils -from equinix.services import fabricv4 as module +from equinix.services import fabricv4 from examples.services.fabricv4.cloud_router import cloud_router_management from examples.services.fabricv4.connections import connection_management @@ -19,7 +19,7 @@ """ utils.pr_yellow('\nCreate Fabric Cloud Router') - fcr_request = module.CloudRouterPostRequest( + fcr_request = CloudRouterPostRequest( type="XF_ROUTER", name="fcrtoawsfcr_01", location={"metro_code": "SV"}, @@ -47,7 +47,7 @@ provider). """ utils.pr_yellow('\nCreate Fabric Cloud Router to AWS Connection') - fcr2aws_request = module.ConnectionPostRequest( + fcr2aws_request = ConnectionPostRequest( type="IP_VC", name="fcr2aws_conn_python_01", bandwidth=50, @@ -100,7 +100,7 @@ - Direct IPv4 Configuration: Specifies the Equinix Interface IP (equinixIfaceIp) with the value '99.65.179.45/30'. """ utils.pr_yellow('\nConfigure Routing Protocol Detail by UUID') - routing_protocol_request = module.RoutingProtocolDirectType( + routing_protocol_request = RoutingProtocolDirectType( type="DIRECT", directIpv4={ "equinixIfaceIp": 'ip' diff --git a/examples/services/fabricv4/connections/fcr_2_azure_connection.py b/examples/services/fabricv4/connections/fcr_2_azure_connection.py index ff0d74bc..2298f10e 100644 --- a/examples/services/fabricv4/connections/fcr_2_azure_connection.py +++ b/examples/services/fabricv4/connections/fcr_2_azure_connection.py @@ -2,7 +2,7 @@ import os from examples.services.fabricv4.utils import utils -from equinix.services import fabricv4 as module +from equinix.services import fabricv4 from examples.services.fabricv4.cloud_router import cloud_router_management from examples.services.fabricv4.connections import connection_management @@ -18,7 +18,7 @@ This object contains the details required to create the Fabric Cloud Router. """ utils.pr_yellow('\nCreate Fabric Cloud Router') - fcr_request = module.CloudRouterPostRequest( + fcr_request = CloudRouterPostRequest( type="XF_ROUTER", name="fcrtoazurefcr_01", location={"metro_code": "DC"}, @@ -46,7 +46,7 @@ provider). """ utils.pr_yellow('\nCreate Fabric Cloud Router to Azure Connection') - fcr2azure_request = module.ConnectionPostRequest( + fcr2azure_request = ConnectionPostRequest( type="IP_VC", name="fcr2azure_conn_python_01", bandwidth=50, @@ -97,7 +97,7 @@ - Direct IPv4 Configuration: Specifies the Equinix Interface IP (equinixIfaceIp) with the value '99.65.179.45/30'. """ utils.pr_yellow('\nConfigure Routing Protocol Detail by UUID') - routing_protocol_request = module.RoutingProtocolDirectType( + routing_protocol_request = RoutingProtocolDirectType( type="DIRECT", directIpv4={ "equinixIfaceIp": 'ip' diff --git a/examples/services/fabricv4/connections/fcr_2_port_connection.py b/examples/services/fabricv4/connections/fcr_2_port_connection.py index 08071d2e..f975d0e5 100644 --- a/examples/services/fabricv4/connections/fcr_2_port_connection.py +++ b/examples/services/fabricv4/connections/fcr_2_port_connection.py @@ -1,7 +1,7 @@ import time from examples.services.fabricv4.utils import utils -from equinix.services import fabricv4 as module +from equinix.services import fabricv4 from examples.services.fabricv4.cloud_router import cloud_router_management from examples.services.fabricv4.connections import connection_management @@ -12,12 +12,9 @@ This method sends a request to create a new Fabric Cloud Router with specified configurations such as router type, name, location, package, and associated project and account details. Notifications are also configured to receive updates regarding the router. - - Construct a `CloudRouterPostRequest` object using the `module.CloudRouterPostRequest` class. - This object contains the details required to create the Fabric Cloud Router. """ utils.pr_yellow('\nCreate Fabric Cloud Router') - fcr_request = module.CloudRouterPostRequest( + fcr_request = CloudRouterPostRequest( type="XF_ROUTER", name="fcrtoportfcr_01", location={"metro_code": "SV"}, @@ -44,7 +41,7 @@ bandwidth, redundancy priority, and the details of both the A-side (Cloud Router) and Z-side (Equinix Port). """ utils.pr_yellow('\nCreate Fabric Cloud Router to Colo Connection') - fcr2colo_request = module.ConnectionPostRequest( + fcr2colo_request = ConnectionPostRequest( type="IP_VC", name="fcr2port_conn_python_01", bandwidth=10, @@ -83,18 +80,9 @@ """ Configures a routing protocol for a Fabric Cloud Router (FCR) to Port connection identified by the provided connection UUID. - - This method is designed to configure the routing protocol details for an existing connection between a Fabric - Cloud Router and Port. It uses the `connection_uuid` to identify the connection and applies the specified - routing protocol settings. - - The routing protocol configuration includes the following details: - - Protocol Type: DIRECT - - Direct IPv4 Configuration: Specifies the Equinix Interface IP (equinixIfaceIp) with the value - '99.65.179.9/30'. """ utils.pr_yellow('\nConfigure Routing Protocol Detail by UUID') - routing_protocol_request = module.RoutingProtocolDirectType( + routing_protocol_request = RoutingProtocolDirectType( type="DIRECT", directIpv4={ "equinixIfaceIp": 'ip' @@ -118,7 +106,7 @@ identified by its UUID, passed as the `fcr2colo` parameter. """ utils.pr_yellow('\nUpdate Name Details Using Connection_UUID') - port_conn_name_update = [module.ConnectionChangeOperation( + port_conn_name_update = [ConnectionChangeOperation( op="replace", path="/name", value="fcr2PortUpdate" @@ -128,13 +116,9 @@ """ Updates the bandwidth details of a connection using the provided Connection UUID. - - This function changes the name attribute of an existing connection name to 50 Mbps - by performing a "replace" operation on the connection's bandwidth field. The connection is - identified by its UUID, passed as the `fcr2colo` parameter. """ utils.pr_yellow('\nUpdate Bandwidth Details Using Connection_UUID') - port_conn_bandwidth_update = [module.ConnectionChangeOperation( + port_conn_bandwidth_update = [ConnectionChangeOperation( op="replace", path="/bandwidth", value=50 @@ -144,12 +128,6 @@ """ Deletes a Fabric Cloud Router (FCR) to Port Colo connection. - - This function performs the following steps: - 1. Prints a message indicating that the deletion of the Fabric Cloud Router - to Port connection is about to begin. The message is printed in yellow for visibility. - 2. Calls the `delete_connection` method from the `connection_management` module - to delete the specified Fabric Cloud Router to Port connection. """ utils.pr_yellow('\nDelete Fabric Cloud Router to Colo Connection') time.sleep(60) @@ -157,12 +135,6 @@ """ Deletes a Fabric Cloud Router (FCR) with the specified UUID. - - This method handles the deletion of a Fabric Cloud Router by calling the - relevant function in the `cloud_router_management` module. It first prints - a message to the console indicating the start of the deletion process, - using a yellow color for emphasis. After that, it proceeds to delete the - specified Fabric Cloud Router. """ utils.pr_yellow('\nDelete Fabric Cloud Router') cloud_router_management.delete_fcr(fcr_uuid) \ No newline at end of file diff --git a/examples/services/fabricv4/oauth2/configure_client_credentials.py b/examples/services/fabricv4/oauth2/configure_client_credentials.py index 057bfef3..147ace1b 100644 --- a/examples/services/fabricv4/oauth2/configure_client_credentials.py +++ b/examples/services/fabricv4/oauth2/configure_client_credentials.py @@ -15,39 +15,6 @@ def get_equinix_fabric_client(): environment variables `EQUINIX_API_CLIENTID` and `EQUINIX_API_CLIENTSECRET`. These credentials are then used to obtain an OAuth2 access token, which is subsequently used to configure the Equinix Fabric API client. - - The method performs the following steps: - 1. Retrieves the `client_id` and `client_secret` from environment variables. - 2. Creates an `OAuth2Service` instance using the client credentials. - 3. Requests an access token using the `client_credentials` grant type. - 4. Configures the Equinix Fabric API client with the obtained access token. - 5. Returns the initialized `fabricv4.ApiClient` instance. - - Returns: - fabricv4.ApiClient: An instance of `fabricv4.ApiClient` that is authenticated - and ready to interact with the Equinix Fabric API. - - Raises: - EnvironmentError: If the `EQUINIX_API_CLIENT_ID` or `EQUINIX_API_CLIENT_SECRET` - environment variables are not set. - OAuth2Error: If there is an error obtaining the access token from the OAuth2 - service. - - Example: - To use this function, ensure that the environment variables are set and call - it as follows: - - ```python - client = get_equinix_fabric_client() - # Now you can use `client` to interact with the Equinix Fabric API - ``` - - Note: - This method is configured to work with the PROD (PRODUCTION) - environment of the Equinix API. If you need to connect to a different - environment, adjust the `access_token_url`, `authorize_url`, and `base_url` - accordingly. - """ client_id = os.getenv("EQUINIX_API_CLIENT_ID")