-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from CiscoDevNet/relative-imports
Relative imports for shared code
- Loading branch information
Showing
94 changed files
with
4,387 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
plugins/module_utils/common/api/config/class_ep/class_ep.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
69
plugins/module_utils/common/api/config/class_ep/v2/sites/sites.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
plugins/module_utils/common/api/config/federation/federation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.