Skip to content

Relative imports for shared code #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Nov 20, 2024
Merged

Relative imports for shared code #336

merged 26 commits into from
Nov 20, 2024

Conversation

allenrobel
Copy link
Collaborator

@allenrobel allenrobel commented Oct 25, 2024

When other projects try to leverage the code in ansible-dcnm, it results in import errors if ansible-dcnm is not installed under ansible_collections/cisco/dcnm.

This PR changes the imports for all code that is shareable such that it can be imported wherever the ansible-dcnm repository happens to be cloned.

This PR also includes some new endpoints and endpoint parsers for Federations and OneManage, as well as sender_requests.py. None of these are used by any modules currently.

Code modified includes only that which is possible to be shared by other projects (i.e. code that is not dependent on Ansible).

module_utils/common/api/*
module_utils/common/controller_features.py
module_utils/common/controller_version.py
module_utils/common/ep/*
module_utils/common/epp/*
module_utils/common/image_policies.py
module_utils/common/maintenance_mode.py
module_utils/common/maintenance_mode_info.py
module_utils/common/rest_send.py
module_utils/common/rest_send_v2.py
module_utils/common/sender_dcnm.py
module_utils/common/sender_requests.py
module_utils/common/switch_details.py
module_utils/fabric/*
module_utils/image_policy/*
module_utils/image_upgrade/*

1. Create initial tree for ND endpoints.

2. EpFederationMembers()

Class to return endpoint to list federation members.
common/epp/api/config/federation/epp_federation_members.py

Work in progress.
Adding the Documented path for EpFederationMembers endpoint under new ep tree:
   ep/nexus/api/federation/v4/members/members.py

/nexus/api/federation/v4/members

HOWEVER, the documented path returns a 500 error, so will continue using the undocumented path that the GUI uses:

/api/config/federation/members/

Also, adding the following:

module_utils/common/sender_requests.py (from fabric_vrfs_endpoint branch)
module_utils/common/epp/epp_login.py
module_utils/common/api/login.py (EpLogin() class)
1. Added the following endpoint classes and their parent classes

module_utils/common/api/config/class_ep/v2/sites/sites.py - EpSites()
module_utils/common/api/config/federation/federation.py - EpFederationMembers()
module_utils/common/api/config/federation/manager/manager.py - EpFederationManager()

2. Added the following endpoint parsers

- module_utils/common/epp/api/config/class_epp/v2/sites/epp_sites.py - EppSitesByName()
- module_utils/common/epp/api/config/federation/manager/epp_federation_manager.py - EppFederationManager()

3.Modified to remove unused class EppFabricsVrfsByKeyValue():

- module_utils/common/epp/api/config/federation/epp_federation_members.py
The sites endpoint returns a complex structure with several dicts.  Created a generic method to extract values for these dicts -- given a property that returns the dict, and a keyname within the dict -- and leveraged it in properties to return individual dict item values.

Still a work in progress since there are several more dicts to process.
Run module_utils/common/api/* through black, isort, pylint.
1. Add properties for items in the following dictionaries:
   - meta
   - nxos
   - siteReachabilty

2. Run through black, isort, pylint
EpFederationManager() rename to EpFederationManagerGet() and add a class doctstring.
Changed imports from absolute to relative in the following files:

modules:

modules/dcnm_fabric.py
modules/dcnm_maintenance_mode.py
modules/dcnm_image_policy.py
modules/dcnm_image_upgrade.py

module_utils:

module_utils/fabric/*
module_utils/image_policy/*
module_utils/image_upgrade/*
module_utils/common/* (except common/network)
@allenrobel allenrobel added the Work in Progress Code not ready for review. label Oct 25, 2024
@allenrobel allenrobel self-assigned this Oct 25, 2024
@allenrobel allenrobel requested a review from mikewiebe October 26, 2024 04:50
@allenrobel allenrobel added ready for review PR is ready to be reviewed and removed Work in Progress Code not ready for review. labels Oct 26, 2024
Since NDFC is eventually going away (integrated with Nexus Dashboard instead of being a separate app), we're renaming the environment variables that sender_requests.py reads.

NDFC_DOMAIN -> ND_DOMAIN
NDFC_IP4 -> ND_IP4
NDFC_PASSWORD -> ND_PASSWORD
NDFC_USERNAME -> ND_USERNAME

Currently, nothing within ansible-dcnm repository relies on this, so this
change will not break anything.
1. Convert absolute imports to relative imports in the following files

- plugins/module_utils/bootflash/bootflash_files.py
- plugins/module_utils/bootflash/bootflash_info.py
Convert remaining imports under module_utils/common/api/* from absolute to relative.
Common methods and properties for ND subclasses.

### Path
``/nexus/api``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why the root of this endpoint name is /nexus/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the root for Nexus Dashboard endpoints, which is used by EppFederationMemberByName(). Though, this class is not yet being used (I figured it would be needed later for the OneManage stuff).

If you'd prefer, I could remove the Federation things for now and add them only if/when needed for OneManage.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to remove. Just curious

Copy link
Collaborator

@mikewiebe mikewiebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allenrobel LGTM. Just had one question in the comments

@allenrobel allenrobel merged commit e651eac into develop Nov 20, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants