-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BloxoneAnsibleModule util and IP space module (#32)
* ip space * add integration action * change name to object/objects * fix generated docs * some documentation fixes * deprecate b1_ipam_ip_space and b1_ipam_ip_space_gather * minor fix
- Loading branch information
Showing
12 changed files
with
5,164 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: integration | ||
|
||
on: | ||
push: | ||
branches: | ||
- v2 | ||
schedule: | ||
# every day at 02:00 UTC | ||
- cron: '0 2 * * *' | ||
|
||
jobs: | ||
integration: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v4 | ||
with: | ||
path: infoblox.bloxone | ||
|
||
- name: Set up integration_config.yml | ||
run: | | ||
echo "api_key: ${{ secrets.BLOXONE_API_KEY }}" > infoblox.bloxone/tests/integration/integration_config.yml | ||
echo "csp_url: ${{ secrets.BLOXONE_CSP_URL }}" >> infoblox.bloxone/tests/integration/integration_config.yml | ||
- uses: ansible-community/[email protected] | ||
with: | ||
collection-src-directory: infoblox.bloxone | ||
ansible-core-version: 'stable-2.15' | ||
target-python-version: '3.11' | ||
testing-type: integration |
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,3 @@ | ||
deprecated_features: | ||
- b1_ipam_ip_space - is deprecated in favor of `ipam_ip_space`. | ||
- b1_ipam_ip_space_gather - is deprecated in favor of `ipam_ip_space_info`. |
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,19 @@ | ||
action_groups: | ||
all: | ||
- metadata: | ||
extend_group: | ||
- ipam | ||
ipam: | ||
- ipam_ip_space | ||
- ipam_ip_space_info | ||
|
||
plugin_routing: | ||
modules: | ||
b1_ipam_ip_space: | ||
deprecation: | ||
removal_version: 3.0.0 | ||
warning_text: Use infoblox.bloxone.ipam_ip_space instead. | ||
b1_ipam_ip_space_gather: | ||
deprecation: | ||
removal_version: 3.0.0 | ||
warning_text: Use infoblox.bloxone.ipam_ip_space_info instead. |
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,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: Infoblox | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
|
||
class ModuleDocFragment: | ||
DOCUMENTATION = r""" | ||
options: | ||
api_key: | ||
description: | ||
- The API token for authentication against Infoblox BloxOne API. If not set, the environment variable E(BLOXONE_API_KEY) will be used. | ||
type: str | ||
aliases: [ bloxone_api_key ] | ||
csp_url: | ||
description: | ||
- The Infoblox Cloud Services Portal (CSP) URL. If not set, the environment variable E(BLOXONE_CSP_URL) will be used. | ||
type: str | ||
aliases: [ bloxone_csp_url ] | ||
default: 'https://csp.infoblox.com' | ||
""" |
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,115 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2024 Infoblox | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
import traceback | ||
|
||
from ansible.module_utils.basic import AnsibleModule, env_fallback, missing_required_lib | ||
|
||
try: | ||
import bloxone_client | ||
|
||
HAS_BLOXONE_CLIENT = True | ||
BLOXONE_CLIENT_IMP_ERR = None | ||
except ImportError: | ||
HAS_BLOXONE_CLIENT = False | ||
BLOXONE_CLIENT_IMP_ERR = traceback.format_exc() | ||
|
||
|
||
class BloxoneAnsibleModule(AnsibleModule): | ||
def __init__(self, *args, **kwargs): | ||
# Add common arguments to the module argument_spec | ||
args_full = bloxone_client_common_argument_spec() | ||
try: | ||
args_full.update(kwargs["argument_spec"]) | ||
except (TypeError, NameError): | ||
pass | ||
kwargs["argument_spec"] = args_full | ||
|
||
super(BloxoneAnsibleModule, self).__init__(*args, **kwargs) | ||
self._client = None | ||
|
||
if not HAS_BLOXONE_CLIENT: | ||
self.fail_json( | ||
msg=missing_required_lib( | ||
"bloxone_client", | ||
url="https://github.com/infobloxopen/bloxone-python-client", | ||
), | ||
exception=BLOXONE_CLIENT_IMP_ERR, | ||
) | ||
|
||
@property | ||
def client(self): | ||
if not self._client: | ||
self._client = _get_client(self) | ||
|
||
return self._client | ||
|
||
def is_changed(self, existing, payload): | ||
return _is_changed(existing, payload) | ||
|
||
|
||
def bloxone_client_common_argument_spec(): | ||
return dict( | ||
api_key=dict( | ||
type="str", aliases=["bloxone_api_key"], fallback=(env_fallback, ["BLOXONE_API_KEY"]), no_log=True | ||
), | ||
csp_url=dict( | ||
type="str", | ||
aliases=["bloxone_csp_url"], | ||
fallback=(env_fallback, ["BLOXONE_CSP_URL"]), | ||
default="https://csp.infoblox.com", | ||
), | ||
) | ||
|
||
|
||
def _get_client(module): | ||
config = _get_client_config(module) | ||
client = bloxone_client.ApiClient(config) | ||
return client | ||
|
||
|
||
def _get_client_config(module): | ||
csp_url = module.params.get("csp_url") | ||
api_key = module.params.get("api_key") | ||
|
||
# Use None for empty values, so that the client can handle it | ||
if not csp_url: | ||
csp_url = None | ||
if not api_key: | ||
api_key = None | ||
|
||
config = bloxone_client.Configuration( | ||
csp_url=csp_url, | ||
api_key=api_key, | ||
client_name="ansible", | ||
) | ||
config.debug = True | ||
return config | ||
|
||
|
||
def _is_changed(existing, payload): | ||
""" | ||
Check if the existing object is different from the payload. | ||
The payload keys that are not none are considered for comparison, others are ignored. | ||
If the value is a complex object, the comparison is done recursively. | ||
:param existing: | ||
:param payload: | ||
:return: | ||
""" | ||
changed = False | ||
for k, v in payload.items(): | ||
if v is not None: | ||
if isinstance(v, dict): | ||
changed = _is_changed(existing[k], v) | ||
elif existing[k] != v: | ||
changed = True | ||
if changed: | ||
break | ||
|
||
return changed |
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
Oops, something went wrong.