HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/infoblox.cpython-310.pyc
o

�N�gF�
@s|dZddlZdZzddlZWney$Zz
ee�ZWYdZ[ndZ[wwdZdd�ZiZ	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Z				dDdd�Zdd�ZdEdd�Zdd�ZdFdd �ZdGd!d"�ZdEd#d$�ZdHd%d&�ZdHd'd(�ZdId)d*�ZdJd+d,�Z	dGd-d.�Z	dGd/d0�ZdEd1d2�ZdEd3d4�Z d5d6�Z!dEd7d8�Z"dFd9d:�Z#d;d<�Z$d=d>�Z%dKd@dA�Z&dJdBdC�Z'dS)La�
This module have been tested on infoblox API v1.2.1,
other versions of the API are likly workable.

:depends: libinfoblox, https://github.com/steverweber/libinfoblox

    libinfoblox can be installed using `pip install libinfoblox`

API documents can be found on your infoblox server at:

    https://INFOBLOX/wapidoc

:configuration: The following configuration defaults can be
    defined (pillar or config files '/etc/salt/master.d/infoblox.conf'):

    .. code-block:: python

        infoblox.config:
            api_sslverify: True
            api_url: 'https://INFOBLOX/wapi/v1.2.1'
            api_user: 'username'
            api_key: 'password'

    Many of the functions accept `api_opts` to override the API config.

    .. code-block:: bash

        salt-call infoblox.get_host name=my.host.com             api_url: 'https://INFOBLOX/wapi/v1.2.1'             api_user=admin             api_key=passs

�N�infobloxcCstdutfS�N)�
IMPORT_ERR�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/infoblox.py�__virtual__-srcKsdddddd�}dt�vrt�d�}|�td|i��t|���t|���@D]}||||<q'|S)zU
    Return configuration
    user passed api_opts override salt config.get vars
    Tzhttps://INFOBLOX/wapi/v1.2.1���
api_sslverify�api_url�api_user�api_key�__salt__z.configz
config.get)�globals�__virtualname__�updater�set�keys)�api_opts�configZ
config_key�krrr�_get_config4s�

rcKs�td
i|��}d�|d|d|d�}|tvr4tt���t|d}t|dr4|dkr4t|dSi}tt���|d<tj|d|d|d|dd	�|d<|t|<|dS)Nzinfoblox_session_{},{},{}rrr
�time�obj�<r
r	r)r�format�cache�intr�libinfobloxZSession)rrZ	cache_key�	timedelta�crrr�
_get_infobloxHs$�
�r!cC�t�||�S)z�
    Diff two complex infoblox objects.
    This is used from salt states to detect changes in objects.

    Using ``func:nextavailableip`` will not cause a diff if the ipaddress is in
    range
    )rZdiff_obj)ZobjaZobjbrrr�diff_objects^sr#cCr")z�
    Return true if the ipaddress is in the range of the nextavailableip function

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.is_ipaddr_in_ipfunc_range             ipaddr="10.0.2.2" ipfunc="func:nextavailableip:10.0.0.0/8"
    )r�is_ipaddr_in_ipfunc_range)ZipaddrZipfuncrrrr$isr$cKs*tdd|i|��}td|d|d�|��S)z�
    Update host record. This is a helper call to update_object.

    Find a hosts ``_ref`` then call update_object with the record data.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.update_host name=fqdn data={}
    �name�_ref��objref�dataNr)�get_host�
update_object�r%r)r�orrr�update_hostwsr.cK�:dt�vrtdrdd|��iStdi|��}|�||�S)z�
    Update raw infoblox object. This is a low level api call.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.update_object objref=[ref_of_object] data={}
    �__opts__�test�Testz Would attempt to update object: Nr)rr0r!r+)r(r)rrrrrr+��
r+cKs8dt�vrtdrdd|��iStdi|��}|�|�S)z�
    Delete infoblox object. This is a low level api call.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.delete_object objref=[ref_of_object]
    r0r1r2z Would attempt to delete object: Nr)rr0r!�
delete_object)r(rrrrrr4�s

r4cKr/)z�
    Create raw infoblox object. This is a low level api call.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.update_object object_type=record:host  data={}
    r0r1r2z Would attempt to create object: Nr)rr0r!�
create_object)Zobject_typer)rrrrrr5�r3r5FcKs(|si}tdi|��}|�|||||�S)z�
    Get raw infoblox object. This is a low level api call.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.get_object objref=[_ref of object]
    Nr)r!�
get_object)r(r)�
return_fieldsZmax_resultsZensure_none_or_one_resultrrrrrr6�s
�r6cKstdi|��}|j|d�}|S)aZ
    Create a cname record.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.create_cname data={             "comment": "cname to example server",             "name": "example.example.com",             "zone": "example.com",             "view": "Internal",             "canonical": "example-ha-0.example.com"         }
    )r)Nr)r!�create_cname)r)rr�hostrrrr8�sr8cKs"tdi|��}|j|||d�}|S)z�
    Get CNAME information.

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.get_cname name=example.example.com
        salt-call infoblox.get_cname canonical=example-ha-0.example.com
    )r%�	canonicalr7Nr)r!�	get_cname)r%r:r7rrr-rrrr;�sr;cKs6tdd|i|��}|std��td|d|d�|��S)a�
    Update CNAME. This is a helper call to update_object.

    Find a CNAME ``_ref`` then call update_object with the record data.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.update_cname name=example.example.com data="{
                'canonical':'example-ha-0.example.com',
                'use_ttl':true,
                'ttl':200,
                'comment':'Salt managed CNAME'}"
    r%zCNAME record not foundr&r'Nr)r;�	Exceptionr+r,rrr�update_cname�sr=cKs0td||d�|��}|rt|dfi|��SdS)a"
    Delete CNAME. This is a helper call to delete_object.

    If record is not found, return True

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.delete_cname name=example.example.com
        salt-call infoblox.delete_cname canonical=example-ha-0.example.com
    )r%r:r&TNr)r;r4)r%r:rZcnamerrr�delete_cnames
r>cKs$tdi|��}|j||||d�}|S)z�
    Get host information

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.get_host hostname.domain.ca
        salt-call infoblox.get_host ipv4addr=123.123.122.12
        salt-call infoblox.get_host mac=00:50:56:84:6e:ae
    )r%�mac�ipv4addrr7Nr)r!r*)r%r@r?r7rrr9rrrr*s
�r*cKs"tdi|��}|j|||d�}|S)z�
    Get all host information

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.get_host_advanced hostname.domain.ca
    )r%r?r@Nr)r!�get_host_advanced)r%r@r?rrr9rrrrA1s
rAcKs�|���d�}|s2tdd|i|��}|rd|vr|d��S|�d�dkr0||�d�dd�S|Sd}|D]}|���d�}|�|�rNt|�t|�krN|}q6|rS|SdS)a�
    Get host domain name

    If no domains are passed, the hostname is checked for a zone in infoblox,
    if no zone split on first dot.

    If domains are provided, the best match out of the list is returned.

    If none are found the return is None

    dots at end of names are ignored.

    CLI Example:

    .. code-block:: bash

        salt-call uwl.get_host_domainname name=localhost.t.domain.com             domains=['domain.com', 't.domain.com.']

        # returns: t.domain.com
    �.r%�zone�Nrr)�lower�rstripr*�count�find�endswith�len)r%�domainsrr)�match�drrr�get_host_domainname@s�rNcKsT|���d�}|s|�d�dSt||fi|��}|r(||vr(|�d|�dS|S)a�
    Get hostname

    If no domains are passed, the hostname is checked for a zone in infoblox,
    if no zone split on first dot.

    If domains are provided, the best match out of the list is truncated from
    the fqdn leaving the hostname.

    If no matching domains are found the fqdn is returned.

    dots at end of names are ignored.

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.get_host_hostname fqdn=localhost.xxx.t.domain.com             domains="['domain.com', 't.domain.com']"
        #returns: localhost.xxx

        salt-call infoblox.get_host_hostname fqdn=localhost.xxx.t.domain.com
        #returns: localhost
    rBr)rErF�splitrN�rsplit)r%rKr�domainrrr�get_host_hostnamegsrRcKs^tdd|i|��}|r-d|vr-g}|dD]
}d|vr"|�|d�q|r'|S|r-|dSdS)z�
    Get mac address from host record.

    Use `allow_array` to return possible multiple values.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.get_host_mac host=localhost.domain.com
    r%�	ipv4addrsr?rNr�r*�append)r%�allow_arrayrr)�l�arrr�get_host_mac�s�rYcKs`td||d�|��}|r.d|vr.g}|dD]
}d|vr#|�|d�q|r(|S|r.|dSdS)a
    Get ipv4 address from host record.

    Use `allow_array` to return possible multiple values.

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.get_host_ipv4 host=localhost.domain.com
        salt-call infoblox.get_host_ipv4 mac=00:50:56:84:6e:ae
    )r%r?rSr@rNrrT)r%r?rVrr)rWrXrrr�
get_host_ipv4�s
�rZcK�tdi|��}|�||||�S)aY
    Get host ipv4addr information

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.get_ipv4addr ipv4addr=123.123.122.12
        salt-call infoblox.get_ipv4addr mac=00:50:56:84:6e:ae
        salt-call infoblox.get_ipv4addr mac=00:50:56:84:6e:ae return_fields=host return_fields='mac,host,configure_for_dhcp,ipv4addr'
    Nr)r!Zget_host_ipv4addr_object)r@r?�discovered_datar7rrrrr�get_host_ipv4addr_info�s�r]cKr[)z�
    Get host ipv6addr information

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.get_host_ipv6addr_info ipv6addr=2001:db8:85a3:8d3:1349:8a2e:370:7348
    Nr)r!Zget_host_ipv6addr_object)Zipv6addrr?r\r7rrrrr�get_host_ipv6addr_info�s�r^cKstdi|��}|j|||d�S)aN
    Get list of all networks. This is helpful when looking up subnets to use
    with func:nextavailableip

    This call is offen slow and not cached!

    some return_fields
    comment,network,network_view,ddns_domainname,disable,enable_ddns

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.get_network
    )r@�networkr7Nr)r!�get_network)r@r_r7rrrrrr`�s�r`cKs6dt�vr
tdr
ddiStdi|��}|�|||�S)a
    Delete host

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.delete_host name=example.domain.com
        salt-call infoblox.delete_host ipv4addr=123.123.122.12
        salt-call infoblox.delete_host ipv4addr=123.123.122.12 mac=00:50:56:84:6e:ae
    r0r1r2zWould attempt to delete hostNr)rr0r!�delete_host)r%r?r@rrrrrra�sracK�td|fi|��S)a
    Add host record

    Avoid race conditions, use func:nextavailableip for ipv[4,6]addrs:

    - func:nextavailableip:network/ZG54dfgsrDFEFfsfsLzA:10.0.0.0/8/default
    - func:nextavailableip:10.0.0.0/8
    - func:nextavailableip:10.0.0.0/8,external
    - func:nextavailableip:10.0.0.3-10.0.0.10

    See your infoblox API for full `data` format.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.create_host             data =
                {'name': 'hostname.example.ca',
                'aliases': ['hostname.math.example.ca'],
            'extattrs': [{'Business Contact': {'value': 'example@example.ca'}},
                {'Pol8 Classification': {'value': 'Restricted'}},
                {'Primary OU': {'value': 'CS'}},
                {'Technical Contact': {'value': 'example@example.ca'}}],
            'ipv4addrs': [{'configure_for_dhcp': True,
                'ipv4addr': 'func:nextavailableip:129.97.139.0/24',
                'mac': '00:50:56:84:6e:ae'}],
            'ipv6addrs': [], }
    zrecord:host�r5�r)rrrr�create_host
srecKstdi|��}|�|||�S)z�
    Get ip range

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.get_ipv4_range start_addr=123.123.122.12
    Nr)r!Z	get_range)�
start_addr�end_addrr7rrrrr�get_ipv4_range+s
rhcKs.t||fi|��}|rt|dfi|��SdS)z�
    Delete ip range.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.delete_ipv4_range start_addr=123.123.122.12
    r&T)rhr4)rfrgr�rrrr�delete_ipv4_range9s
rjcKrb)a4
    Create a ipv4 range

    This is a helper function to `create_object`
    See your infoblox API for full `data` format.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.create_ipv4_range data={
            start_addr: '129.97.150.160',
            end_addr: '129.97.150.170'}
    �rangercrdrrr�create_ipv4_rangeJsrlcKrb)an
    Create A record.

    This is a helper function to `create_object`.
    See your infoblox API for full `data` format.

    CLI Example:

    .. code-block:: bash

        salt-call infoblox.create_a                     data =
                    name: 'fastlinux.math.example.ca'
                    ipv4addr: '127.0.0.1'
                    view: External
    �record:arcrdrrr�create_a\srnTcKsNi}|r||d<|r||d<tdd|i|��}|r%t|�dkr%|s%td��|S)	z�
    Get A record

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.get_a name=abc.example.com
        salt-call infoblox.get_a ipv4addr=192.168.3.5
    r%r@rmr)rDz8More than one result, use allow_array to return the dataN)rm)r6rJr<)r%r@rVrr)rirrr�get_apsrocKsbt||fddi|��}|sdSt|�dkr|std��g}|D]}|�t|dfi|���q|S)a�
    Delete A record

    If the A record is used as a round robin you can set ``allow_array=True`` to
    delete all records for the hostname.

    CLI Examples:

    .. code-block:: bash

        salt-call infoblox.delete_a name=abc.example.com
        salt-call infoblox.delete_a ipv4addr=192.168.3.5
        salt-call infoblox.delete_a name=acname.example.com allow_array=True
    rVFTrDz1More than one result, use allow_array to overrider&)rorJr<rUr4)r%r@rVrri�retZrirrr�delete_a�srq)NNNF)NNN)NN)NNNNr)NF)NNF)NNT)(�__doc__rrrr<�exc�strrrrrr!r#r$r.r+r4r5r6r8r;r=r>r*rArNrRrYrZr]r^r`rarerhrjrlrnrorqrrrr�<module>s`"��
�





'
"

�
�


!