Skip to content

Commit

Permalink
Merge pull request #336 from CiscoDevNet/relative-imports
Browse files Browse the repository at this point in the history
Relative imports for shared code
  • Loading branch information
allenrobel authored Nov 20, 2024
2 parents dd6179c + 867b73d commit e651eac
Show file tree
Hide file tree
Showing 94 changed files with 4,387 additions and 479 deletions.
8 changes: 3 additions & 5 deletions plugins/module_utils/bootflash/bootflash_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
import inspect
import logging

from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
from ..common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
EpBootflashFiles
from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
ConversionUtils
from ansible_collections.cisco.dcnm.plugins.module_utils.common.properties import \
Properties
from ..common.conversion import ConversionUtils
from ..common.properties import Properties


@Properties.add_rest_send
Expand Down
16 changes: 6 additions & 10 deletions plugins/module_utils/bootflash/bootflash_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@
import logging
from pathlib import PurePosixPath

from ansible_collections.cisco.dcnm.plugins.module_utils.bootflash.convert_file_info_to_target import \
ConvertFileInfoToTarget
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.imagemanagement.rest.discovery.discovery import \
from ..common.api.v1.imagemanagement.rest.discovery.discovery import \
EpBootflashDiscovery
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
from ..common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
EpBootflashInfo
from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
ConversionUtils
from ansible_collections.cisco.dcnm.plugins.module_utils.common.properties import \
Properties
from ansible_collections.cisco.dcnm.plugins.module_utils.common.results import \
Results
from ..common.conversion import ConversionUtils
from ..common.properties import Properties
from ..common.results import Results
from .convert_file_info_to_target import ConvertFileInfoToTarget


@Properties.add_rest_send
Expand Down
3 changes: 1 addition & 2 deletions plugins/module_utils/common/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

import logging

from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
ConversionUtils
from ..conversion import ConversionUtils


class Api:
Expand Down
63 changes: 63 additions & 0 deletions plugins/module_utils/common/api/api_nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = "Allen Robel"

import logging

from ..conversion import ConversionUtils


class ApiNd:
"""
## API endpoints for ND- ApiNd()
### Description
Common methods and properties for ApiNd() subclasses.
### Path
``/api``
"""

def __init__(self):
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")
self.conversion = ConversionUtils()
# Popuate in subclasses to indicate which properties
# are mandatory for the subclass.
self.required_properties = set()
self.log.debug("ENTERED api.ApiNd()")
self.api = "/api"
self._init_properties()

def _init_properties(self):
self._path = None
self._verb = None

@property
def path(self):
"""
Return the endpoint path.
"""
return self._path

@property
def verb(self):
"""
Return the endpoint verb.
"""
return self._verb
48 changes: 48 additions & 0 deletions plugins/module_utils/common/api/config/class_ep/class_ep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = "Allen Robel"

import logging

from ..config import Config


class ClassEp(Config):
"""
## API endpoints - Api().Config().ClassEp()
### Description
Common methods and properties for Api().Config().Class() subclasses.
### Path
``/api/config/class``
### Notes
1. We could not use Class() as the class name since it's a
reserved Python name.
2. Same goes for the directory name (class_ep vs class).
i.e. imports didn't work when we tried class as a directory name
or a file name.
"""

def __init__(self):
super().__init__()
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")
self.log.debug("ENTERED api.config.class_ep.ClassEp()")
self.class_ep = f"{self.config}/class"
69 changes: 69 additions & 0 deletions plugins/module_utils/common/api/config/class_ep/v2/sites/sites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = "Allen Robel"

import logging

from ..v2 import V2


class EpSites(V2):
"""
## Api().Config().ClassEp().V2().EpSites()
### Description
Endpoint information for retrieving Federation Sites from the
controller.
### Raises
- None
### Path
``/api/config/class/v2/sites``
### Verb
``GET``
### Parameters
- path: retrieve the path for the endpoint
- verb: retrieve the verb for the endpoint
### Usage
```python
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.config.class_ep.v2.sites import EpSites
instance = EpSites()
path = instance.path
verb = instance.verb
```
"""

def __init__(self):
super().__init__()
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")
self.log.debug("ENTERED api.config.class_ep.v2.sites.EpSites()")
# trailing backslash is needed here
self._path = f"{self.v2}/sites/"
self._verb = "GET"
41 changes: 41 additions & 0 deletions plugins/module_utils/common/api/config/class_ep/v2/v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = "Allen Robel"

import logging

from ..class_ep import ClassEp


class V2(ClassEp):
"""
## API endpoints - Api().Config().ClassEp().V2()
### Description
Common methods and properties for Api().Config().ClassEp().V2() subclasses.
### Path
``/api/config/class/v2``
"""

def __init__(self):
super().__init__()
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")
self.log.debug("ENTERED api.config.class_ep.v2.V2()")
self.v2 = f"{self.class_ep}/v2"
41 changes: 41 additions & 0 deletions plugins/module_utils/common/api/config/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = "Allen Robel"

import logging

from ..api_nd import ApiNd


class Config(ApiNd):
"""
## config API enpoints - Api().Config()
### Description
Common methods and properties for API config subclasses.
### Path
``/api/config/``
"""

def __init__(self):
super().__init__()
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")
self.log.debug("ENTERED api.config.Config()")
self.config = f"{self.api}/config"
54 changes: 54 additions & 0 deletions plugins/module_utils/common/api/config/federation/federation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type
__author__ = "Allen Robel"

import logging

from ..config import Config


class Federation(Config):
"""
## Federation API enpoints - Api().Config().Federation()
### Description
Common methods and properties for API Federation subclasses.
### Path
``/api/config/federation/``
"""

def __init__(self):
super().__init__()
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")
self.log.debug("ENTERED api.config.Federation()")
self.federation = f"{self.config}/federation"


class EpFederationMembers(Federation):
def __init__(self):
super().__init__()
self.class_name = self.__class__.__name__
self.log = logging.getLogger(f"dcnm.{self.class_name}")

self._verb = "GET"
self._path = f"{self.federation}/members"
msg = "ENTERED api.config.federation."
msg += f"Federation.{self.class_name}"
self.log.debug(msg)
Loading

0 comments on commit e651eac

Please sign in to comment.