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
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
58333d3
Initial endpoint tree
allenrobel Oct 8, 2024
7ec4cce
WIP: EppFederationMembers()
allenrobel Oct 8, 2024
e336036
Documented path for FederationMembers
allenrobel Oct 9, 2024
baff5a5
Add endpoint and endpoint parser classes
allenrobel Oct 9, 2024
8ce0c41
WIP: epp_sites.py: Add more properties
allenrobel Oct 10, 2024
7c06f58
Run endpoints through linters
allenrobel Oct 10, 2024
fa9ffba
epp_sites.py: Add properties
allenrobel Oct 10, 2024
2c7a5c7
EpFederationManager: Rename and add docstring
allenrobel Oct 12, 2024
0ab257f
Changed imports from absolute to relative.
allenrobel Oct 19, 2024
06e9f5b
Appease linters
allenrobel Oct 25, 2024
5e19cbd
Revert modules/* to use absolute paths
allenrobel Oct 25, 2024
7b1d764
Fix (hopefully) relative imports
allenrobel Oct 25, 2024
d5fdac3
Fix PEP8 whitespace and indent errors
allenrobel Oct 25, 2024
f3ff77a
Fix import errors
allenrobel Oct 26, 2024
85211e2
Try ignore import for sender_requests.py
allenrobel Oct 26, 2024
176d67f
Skip import test for plugins/module_utils/sender_requests.py
allenrobel Oct 26, 2024
8c03b8e
Fix path to sender_requests.py in sanity/ignore-*.txt
allenrobel Oct 26, 2024
885e1ac
Update sanity/ignore-*.txt wit python version to skip
allenrobel Oct 26, 2024
44d901e
sanity - ignore python versions 3.9, 3.10, 3.11 for sender_requests.py
allenrobel Oct 26, 2024
8ce83ac
sanity - sender_requests.py, ignore 3.10
allenrobel Oct 26, 2024
69b8ca1
Rename ENV vars that sender_requests.py reads
allenrobel Oct 29, 2024
bfa9454
Merge branch 'develop' into relative-imports
allenrobel Nov 15, 2024
7d9bd92
ignore-2.16.txt: Add sender_requests.py
allenrobel Nov 15, 2024
2c83a33
Modify imports for module_utils/bootflash/*
allenrobel Nov 20, 2024
1b7c167
Convert remaining api absolute imports to relative
allenrobel Nov 20, 2024
867b73d
Merge branch 'develop' into relative-imports
allenrobel Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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