Skip to content

Commit

Permalink
Resolving the Comments for Example
Browse files Browse the repository at this point in the history
  • Loading branch information
jkallem-equinix committed Aug 21, 2024
1 parent 785c6ed commit 9789a31
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 158 deletions.
22 changes: 3 additions & 19 deletions examples/services/fabricv4/cloud_router/cloud_router.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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"},
Expand Down Expand Up @@ -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"
Expand Down
50 changes: 0 additions & 50 deletions examples/services/fabricv4/cloud_router/cloud_router_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""


Expand All @@ -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.
"""


Expand All @@ -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.
"""


Expand All @@ -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.
"""


Expand Down
14 changes: 0 additions & 14 deletions examples/services/fabricv4/connections/connection_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down
40 changes: 6 additions & 34 deletions examples/services/fabricv4/connections/fcr_2_port_connection.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"},
Expand All @@ -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,
Expand Down Expand Up @@ -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'
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -144,25 +128,13 @@

"""
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)
connection_management.delete_connection(fcr2colo)

"""
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)
33 changes: 0 additions & 33 deletions examples/services/fabricv4/oauth2/configure_client_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9789a31

Please sign in to comment.