Skip to content

Commit e651eac

Browse files
authored
Merge pull request #336 from CiscoDevNet/relative-imports
Relative imports for shared code
2 parents dd6179c + 867b73d commit e651eac

File tree

94 files changed

+4387
-479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+4387
-479
lines changed

plugins/module_utils/bootflash/bootflash_files.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
import inspect
2121
import logging
2222

23-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
23+
from ..common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
2424
EpBootflashFiles
25-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
26-
ConversionUtils
27-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.properties import \
28-
Properties
25+
from ..common.conversion import ConversionUtils
26+
from ..common.properties import Properties
2927

3028

3129
@Properties.add_rest_send

plugins/module_utils/bootflash/bootflash_info.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@
2121
import logging
2222
from pathlib import PurePosixPath
2323

24-
from ansible_collections.cisco.dcnm.plugins.module_utils.bootflash.convert_file_info_to_target import \
25-
ConvertFileInfoToTarget
26-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.imagemanagement.rest.discovery.discovery import \
24+
from ..common.api.v1.imagemanagement.rest.discovery.discovery import \
2725
EpBootflashDiscovery
28-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
26+
from ..common.api.v1.imagemanagement.rest.imagemgnt.bootflash.bootflash import \
2927
EpBootflashInfo
30-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
31-
ConversionUtils
32-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.properties import \
33-
Properties
34-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.results import \
35-
Results
28+
from ..common.conversion import ConversionUtils
29+
from ..common.properties import Properties
30+
from ..common.results import Results
31+
from .convert_file_info_to_target import ConvertFileInfoToTarget
3632

3733

3834
@Properties.add_rest_send

plugins/module_utils/common/api/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
import logging
2121

22-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.conversion import \
23-
ConversionUtils
22+
from ..conversion import ConversionUtils
2423

2524

2625
class Api:
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (c) 2024 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import, division, print_function
16+
17+
__metaclass__ = type
18+
__author__ = "Allen Robel"
19+
20+
import logging
21+
22+
from ..conversion import ConversionUtils
23+
24+
25+
class ApiNd:
26+
"""
27+
## API endpoints for ND- ApiNd()
28+
29+
### Description
30+
Common methods and properties for ApiNd() subclasses.
31+
32+
### Path
33+
``/api``
34+
"""
35+
36+
def __init__(self):
37+
self.class_name = self.__class__.__name__
38+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
39+
self.conversion = ConversionUtils()
40+
# Popuate in subclasses to indicate which properties
41+
# are mandatory for the subclass.
42+
self.required_properties = set()
43+
self.log.debug("ENTERED api.ApiNd()")
44+
self.api = "/api"
45+
self._init_properties()
46+
47+
def _init_properties(self):
48+
self._path = None
49+
self._verb = None
50+
51+
@property
52+
def path(self):
53+
"""
54+
Return the endpoint path.
55+
"""
56+
return self._path
57+
58+
@property
59+
def verb(self):
60+
"""
61+
Return the endpoint verb.
62+
"""
63+
return self._verb
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2024 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import, division, print_function
16+
17+
__metaclass__ = type
18+
__author__ = "Allen Robel"
19+
20+
import logging
21+
22+
from ..config import Config
23+
24+
25+
class ClassEp(Config):
26+
"""
27+
## API endpoints - Api().Config().ClassEp()
28+
29+
### Description
30+
Common methods and properties for Api().Config().Class() subclasses.
31+
32+
### Path
33+
``/api/config/class``
34+
35+
### Notes
36+
1. We could not use Class() as the class name since it's a
37+
reserved Python name.
38+
2. Same goes for the directory name (class_ep vs class).
39+
i.e. imports didn't work when we tried class as a directory name
40+
or a file name.
41+
"""
42+
43+
def __init__(self):
44+
super().__init__()
45+
self.class_name = self.__class__.__name__
46+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
47+
self.log.debug("ENTERED api.config.class_ep.ClassEp()")
48+
self.class_ep = f"{self.config}/class"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2024 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import, division, print_function
16+
17+
__metaclass__ = type
18+
__author__ = "Allen Robel"
19+
20+
import logging
21+
22+
from ..v2 import V2
23+
24+
25+
class EpSites(V2):
26+
"""
27+
## Api().Config().ClassEp().V2().EpSites()
28+
29+
### Description
30+
31+
Endpoint information for retrieving Federation Sites from the
32+
controller.
33+
34+
### Raises
35+
36+
- None
37+
38+
### Path
39+
40+
``/api/config/class/v2/sites``
41+
42+
### Verb
43+
44+
``GET``
45+
46+
### Parameters
47+
48+
- path: retrieve the path for the endpoint
49+
- verb: retrieve the verb for the endpoint
50+
51+
### Usage
52+
53+
```python
54+
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.config.class_ep.v2.sites import EpSites
55+
instance = EpSites()
56+
path = instance.path
57+
verb = instance.verb
58+
```
59+
60+
"""
61+
62+
def __init__(self):
63+
super().__init__()
64+
self.class_name = self.__class__.__name__
65+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
66+
self.log.debug("ENTERED api.config.class_ep.v2.sites.EpSites()")
67+
# trailing backslash is needed here
68+
self._path = f"{self.v2}/sites/"
69+
self._verb = "GET"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2024 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import, division, print_function
16+
17+
__metaclass__ = type
18+
__author__ = "Allen Robel"
19+
20+
import logging
21+
22+
from ..class_ep import ClassEp
23+
24+
25+
class V2(ClassEp):
26+
"""
27+
## API endpoints - Api().Config().ClassEp().V2()
28+
29+
### Description
30+
Common methods and properties for Api().Config().ClassEp().V2() subclasses.
31+
32+
### Path
33+
``/api/config/class/v2``
34+
"""
35+
36+
def __init__(self):
37+
super().__init__()
38+
self.class_name = self.__class__.__name__
39+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
40+
self.log.debug("ENTERED api.config.class_ep.v2.V2()")
41+
self.v2 = f"{self.class_ep}/v2"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2024 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import, division, print_function
16+
17+
__metaclass__ = type
18+
__author__ = "Allen Robel"
19+
20+
import logging
21+
22+
from ..api_nd import ApiNd
23+
24+
25+
class Config(ApiNd):
26+
"""
27+
## config API enpoints - Api().Config()
28+
29+
### Description
30+
Common methods and properties for API config subclasses.
31+
32+
### Path
33+
``/api/config/``
34+
"""
35+
36+
def __init__(self):
37+
super().__init__()
38+
self.class_name = self.__class__.__name__
39+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
40+
self.log.debug("ENTERED api.config.Config()")
41+
self.config = f"{self.api}/config"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2024 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import, division, print_function
16+
17+
__metaclass__ = type
18+
__author__ = "Allen Robel"
19+
20+
import logging
21+
22+
from ..config import Config
23+
24+
25+
class Federation(Config):
26+
"""
27+
## Federation API enpoints - Api().Config().Federation()
28+
29+
### Description
30+
Common methods and properties for API Federation subclasses.
31+
32+
### Path
33+
``/api/config/federation/``
34+
"""
35+
36+
def __init__(self):
37+
super().__init__()
38+
self.class_name = self.__class__.__name__
39+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
40+
self.log.debug("ENTERED api.config.Federation()")
41+
self.federation = f"{self.config}/federation"
42+
43+
44+
class EpFederationMembers(Federation):
45+
def __init__(self):
46+
super().__init__()
47+
self.class_name = self.__class__.__name__
48+
self.log = logging.getLogger(f"dcnm.{self.class_name}")
49+
50+
self._verb = "GET"
51+
self._path = f"{self.federation}/members"
52+
msg = "ENTERED api.config.federation."
53+
msg += f"Federation.{self.class_name}"
54+
self.log.debug(msg)

0 commit comments

Comments
 (0)