CiscoDevNet / ansible-dcnm

Apache License 2.0
47 stars 37 forks source link

dcnm_fabric: Add support for IPFM fabrics (ready for review) #294

Closed allenrobel closed 5 months ago

allenrobel commented 6 months ago

Commit Contents

  1. Support for IP Fabric for Media fabrics.
  2. ControllerFeatures() class to retrieve admin and oper state of NDFC features.
  3. FabricTypes() add FABRIC_TYPE to feature mapping.
    • Maps FABRIC_TYPE to the NDFC feature (e.g. "vxlan", "pmn") required to be enabled for that FABRIC_TYPE
  4. Smart Endpoints
    • A standardized, shareable, extensible set of classes for retrieving NDFC REST API endpoints.
    • Exactly parallels NDFC REST API hierarchy.
    • Currently contains endpoints used by the dcnm_fabric and image_upgrade modules.
    • We can add more in the future.
    • Example NDFC REST API endpoint retrieval is below.
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.rest.control.fabrics.fabrics import \
    EpFabricConfigDeploy

instance = EpFabricConfigDeploy()
# fabric_name is validated by the class to conform to NDFC requirements.
try:
    instance.fabric_name = "MyFabric"
except ValueError as error:
    ansible_module.fail_json(error)
response = dcnm_send(module, instance.verb, instance.path)

# etc...

Review notes

Smart Endpoints

  1. Most files in this commit have to do with Smart Endpoints; small classes which, together, construct and validate NDFC REST API endpoints. The parent class is Api() in module_utils/common/api. Below that, are subclasses which inherit from Api(); each subclass adding its portion to the final endpoint path retrieved via the leaf classes. For example Api() builds the initial path (self.api) of /appcenter/cisco/ndfc/api. Then the V1() class in api/v1/.v1.py adds self.v1 = f"{self.api}/v1"} to the path, etc, down the endpoint path hierarchy.
  2. Each class does its own validations depending on the requirements of the endpoint. Generally, the contents of the set() self.mandatory_properties -- inherited from Api() -- are updated within a leaf subclass. For example, see the leaf class EpTemplate() in ./api/v1/configtemplate/rest/config/templates/templates.py, which mandates that template_name be set by adding "template_name" to the self.mandatory_properties set within its constructor.
  3. dcnm_fabric has been updated to use Smart Endpoints throughput and the "legacy" endpoint class ApiEndpoints() has been removed. Most of the diffs within module_utils/fabric have to do with replacing the legacy endpoints with Smart Endpoints.

dcnm_fabric IPFM Support

  1. Three lines in the file below add IPFM support:
    • module_utils/fabric/fabric_types.py, lines 74, 83, 94,
  2. The remaining diffs in this commit are related to the addition of integration tests, and modifications to unit tests in tests/unit/modules/dcnm/dcnm_fabric/test_fabric_types.py for IPFM on lines 50, 67, 123, and 134.