Skip to content

Commit

Permalink
Refactor : Renaming Bloxone Python Client to Universal DDI Python Cli…
Browse files Browse the repository at this point in the history
…ent (infobloxopen#67)

* updated python-client occurences , changed env variables

* Resolved linter errors

* added alias for csp_url

* Reverted bloxone.py

* updated documentation

* Modified Exclude statements

* updated requirements
  • Loading branch information
unasra authored Jan 30, 2025
1 parent 13a3bce commit bebcc7a
Show file tree
Hide file tree
Showing 69 changed files with 152 additions and 149 deletions.
12 changes: 6 additions & 6 deletions plugins/doc_fragments/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
class ModuleDocFragment:
DOCUMENTATION = r"""
options:
api_key:
portal_key:
description:
- The API token for authentication against Infoblox BloxOne API. If not set, the environment variable E(BLOXONE_API_KEY) will be used.
- The API token for authentication against Infoblox BloxOne API. If not set, the environment variable E(INFOBLOX_PORTAL_KEY) will be used.
type: str
aliases: [ bloxone_api_key ]
aliases: [ infoblox_portal_key, api_key ]
csp_url:
portal_url:
description:
- The Infoblox Cloud Services Portal (CSP) URL. If not set, the environment variable E(BLOXONE_CSP_URL) will be used.
- The Infoblox Cloud Services Portal (CSP) URL. If not set, the environment variable E(INFOBLOX_PORTAL_URL) will be used.
type: str
aliases: [ bloxone_csp_url ]
aliases: [ infoblox_portal_url, csp_url ]
default: 'https://csp.infoblox.com'
"""
57 changes: 30 additions & 27 deletions plugins/module_utils/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
from ansible.module_utils.basic import AnsibleModule, env_fallback, missing_required_lib

try:
import bloxone_client
import universal_ddi_client

HAS_BLOXONE_CLIENT = True
BLOXONE_CLIENT_IMP_ERR = None
HAS_UNIVERSAL_DDI_CLIENT = True
UNIVERSAL_DDI_CLIENT_IMP_ERR = None
except ImportError:
HAS_BLOXONE_CLIENT = False
BLOXONE_CLIENT_IMP_ERR = traceback.format_exc()
HAS_UNIVERSAL_DDI_CLIENT = False
UNIVERSAL_DDI_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()
args_full = universal_ddi_client_common_argument_spec()
try:
args_full.update(kwargs["argument_spec"])
except (TypeError, NameError):
Expand All @@ -33,13 +33,13 @@ def __init__(self, *args, **kwargs):
super(BloxoneAnsibleModule, self).__init__(*args, **kwargs)
self._client = None

if not HAS_BLOXONE_CLIENT:
if not HAS_UNIVERSAL_DDI_CLIENT:
self.fail_json(
msg=missing_required_lib(
"bloxone_client",
url="https://github.com/infobloxopen/bloxone-python-client",
"universal_ddi_client",
url="https://github.com/infobloxopen/universal-ddi-python-client",
),
exception=BLOXONE_CLIENT_IMP_ERR,
exception=UNIVERSAL_DDI_CLIENT_IMP_ERR,
)

@property
Expand All @@ -61,39 +61,42 @@ def validate_readonly_on_update(self, existing, update_body, fields):
return update_body


def bloxone_client_common_argument_spec():
def universal_ddi_client_common_argument_spec():
return dict(
api_key=dict(
type="str", aliases=["bloxone_api_key"], fallback=(env_fallback, ["BLOXONE_API_KEY"]), no_log=True
portal_key=dict(
type="str",
aliases=["infoblox_portal_key", "api_key"],
fallback=(env_fallback, ["INFOBLOX_PORTAL_KEY"]),
no_log=True,
),
csp_url=dict(
portal_url=dict(
type="str",
aliases=["bloxone_csp_url"],
fallback=(env_fallback, ["BLOXONE_CSP_URL"]),
aliases=["infoblox_portal_url", "csp_url"],
fallback=(env_fallback, ["INFOBLOX_PORTAL_URL"]),
default="https://csp.infoblox.com",
),
)


def _get_client(module):
config = _get_client_config(module)
client = bloxone_client.ApiClient(config)
client = universal_ddi_client.ApiClient(config)
return client


def _get_client_config(module):
csp_url = module.params.get("csp_url")
api_key = module.params.get("api_key")
portal_url = module.params.get("portal_url")
portal_key = module.params.get("portal_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,
if not portal_url:
portal_url = None
if not portal_key:
portal_key = None

config = universal_ddi_client.Configuration(
csp_url=portal_url,
api_key=portal_key,
client_name="ansible",
)
config.debug = True
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/dns_auth_nsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import AuthNSG, AuthNsgApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -425,7 +425,7 @@ class AuthNsgModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(AuthNsgModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = AuthNSG.from_dict(self._payload_params)
self._existing = None
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_auth_nsg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import AuthNsgApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/dns_auth_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -1968,8 +1968,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import AuthZone, AuthZoneApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -1978,7 +1978,7 @@ class AuthZoneModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(AuthZoneModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = AuthZone.from_dict(self._payload_params)
self._existing = None
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_auth_zone_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,8 +1391,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import AuthZoneApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/dns_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import Delegation, DelegationApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -192,7 +192,7 @@ class DelegationModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(DelegationModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = Delegation.from_dict(self._payload_params)
self._existing = None
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_delegation_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import DelegationApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_forward_nsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class ForwardNsgModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(ForwardNsgModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = ForwardNSG.from_dict(self._payload_params)
self._existing = None
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/dns_forward_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import ForwardZone, ForwardZoneApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -269,7 +269,7 @@ class ForwardZoneModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(ForwardZoneModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = ForwardZone.from_dict(self._payload_params)
self._existing = None
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_forward_zone_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import ForwardZoneApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ class RecordModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(RecordModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = Record.from_dict(self._payload_params)
self._existing = None
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/dns_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3775,8 +3775,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import View, ViewApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -3785,7 +3785,7 @@ class ViewModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(ViewModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = View.from_dict(self._payload_params)
self._existing = None
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/dns_view_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,8 +2629,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from dns_config import ViewApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/infra_join_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from infra_provision import JoinToken, UIJoinTokenApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -84,7 +84,7 @@ class JoinTokenModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(JoinTokenModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = JoinToken.from_dict(self._payload_params)
self._existing = None
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/infra_join_token_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from infra_provision import UIJoinTokenApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipam_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from ipam import Address, AddressApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -358,7 +358,7 @@ def __init__(self, *args, **kwargs):
super(AddressModule, self).__init__(*args, **kwargs)
self.next_available_id = self.params.get("next_available_id")

exclude = ["state", "csp_url", "api_key", "id", "next_available_id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id", "next_available_id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = Address.from_dict(self._payload_params)
self._existing = None
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipam_address_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2340,8 +2340,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from ipam import AddressBlock, AddressBlockApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -2357,7 +2357,7 @@ def __init__(self, *args, **kwargs):
self.params["address"], netmask = self.params["address"].split("/")
self.params["cidr"] = int(netmask)

exclude = ["state", "csp_url", "api_key", "id", "next_available_id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id", "next_available_id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = AddressBlock.from_dict(self._payload_params)

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ipam_address_block_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,8 +1642,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from ipam import AddressBlockApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ipam_address_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from ipam import AddressApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ipam_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@
from ansible_collections.infoblox.bloxone.plugins.module_utils.modules import BloxoneAnsibleModule

try:
from bloxone_client import ApiException, NotFoundException
from ipam import IpamHost, IpamHostApi
from universal_ddi_client import ApiException, NotFoundException
except ImportError:
pass # Handled by BloxoneAnsibleModule

Expand All @@ -248,7 +248,7 @@ class IpamHostModule(BloxoneAnsibleModule):
def __init__(self, *args, **kwargs):
super(IpamHostModule, self).__init__(*args, **kwargs)

exclude = ["state", "csp_url", "api_key", "id"]
exclude = ["state", "csp_url", "api_key", "portal_url", "portal_key", "id"]
self._payload_params = {k: v for k, v in self.params.items() if v is not None and k not in exclude}
self._payload = IpamHost.from_dict(self._payload_params)
self._existing = None
Expand Down
Loading

0 comments on commit bebcc7a

Please sign in to comment.