-
Notifications
You must be signed in to change notification settings - Fork 46
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
Conversation
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)
Ansible sanity seems to expect absolute paths for introspection with the main module code.
Fixing the relative imports after reading the following: https://docs.python.org/3.13/reference/simple_stmts.html#import
tests/sanity/ignore-2.15.txt - plugins/module_utils/sender_requests.py import-3.11!skip
plugins/module_utils/common/sender_requests.py import-3.11 # TODO remove this if/when requests is added to the standard library
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`` |
There was a problem hiding this comment.
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/
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
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/*