<commit_before># -*- coding: utf-8 -*-
'''
states for infoblox stuff

ensures a record is either present or absent in an Infoblox DNS system

.. versionadded:: 2016.3.0
'''
from __future__ import absolute_import

# Import Python libs
import logging

log = logging.getLogger(__name__)


def __virtual__():
    '''
    make sure the infoblox module is available
    '''
    return True if 'infoblox.get_record' in __salt__ else False


def present(name,
            value,
            record_type,
            dns_view,
            infoblox_server=None,
            infoblox_user=None,
            infoblox_password=None,
            infoblox_api_version='v1.4.2',
            sslVerify=True):
    '''
    Ensure a record exists

    name
        Name of the record

    value
        Value of the record

    record_type
        record type (host, a, cname, etc)

    dns_view
        DNS View

    infoblox_server
        infoblox server to connect to (will try pillar if not specified)

    infoblox_user
        username to use to connect to infoblox (will try pillar if not specified)

    infoblox_password
        password to use to connect to infoblox (will try pillar if not specified)

    verify_ssl
        verify SSL certificates

    Example:

    .. code-block:: yaml

        some-state:
            infoblox.present:
              - name: some.dns.record
              - value: 10.1.1.3
              - record_type: host
              - sslVerify: False
    '''
    record_type = record_type.lower()
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    records = __salt__['infoblox.get_record'](name,
                                              record_type,
                                              infoblox_server=infoblox_server,
                                              infoblox_user=infoblox_user,
                                              infoblox_password=<PASSWORD>,
                                              dns_view=dns_view,
                                              infoblox_api_version=infoblox_api_version,
                                              sslVerify=sslVerify)
    if records:
        # check records for updates
        for record in records:
            update_record = False
            if record_type == 'cname':
                if record['Canonical Name'] != value:
                    update_record = True
            elif record_type == 'a':
                if record['IP Address'] != value:
                    update_record = True
            elif record_type == 'host':
                if record['IP Addresses'] != value:
                    update_record = True<commit_msg>Convert IP values to unicode in infoblox state module. Convert IP value to list for host records.<commit_after># -*- coding: utf-8 -*-
'''
states for infoblox stuff

ensures a record is either present or absent in an Infoblox DNS system

.. versionadded:: 2016.3.0
'''
from __future__ import absolute_import

# Import Python libs
import logging

log = logging.getLogger(__name__)


def __virtual__():
    '''
    make sure the infoblox module is available
    '''
    return True if 'infoblox.get_record' in __salt__ else False


def present(name,
            value,
            record_type,
            dns_view,
            infoblox_server=None,
            infoblox_user=None,
            infoblox_password=<PASSWORD>,
            infoblox_api_version='v1.4.2',
            sslVerify=True):
    '''
    Ensure a record exists

    name
        Name of the record

    value
        Value of the record

    record_type
        record type (host, a, cname, etc)

    dns_view
        DNS View

    infoblox_server
        infoblox server to connect to (will try pillar if not specified)

    infoblox_user
        username to use to connect to infoblox (will try pillar if not specified)

    infoblox_password
        password to use to connect to infoblox (will try pillar if not specified)

    verify_ssl
        verify SSL certificates

    Example:

    .. code-block:: yaml

        some-state:
            infoblox.present:
              - name: some.dns.record
              - value: 10.1.1.3
              - record_type: host
              - sslVerify: False
    '''
    record_type = record_type.lower()
    value_utf8 = unicode(value, "utf-8")
    ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
    records = __salt__['infoblox.get_record'](name,
                                              record_type,
                                              infoblox_server=infoblox_server,
                                              infoblox_user=infoblox_user,
                                              infoblox_password=<PASSWORD>,
                                              dns_view=dns_view,
                                              infoblox_api_version=infoblox_api_version,
                                              sslVerify=sslVerify)
    if records:
        # check records for updates
        for record in records:
            update_record = False
            if record_type == 'cname':
                if record['Canonical Name'] != value_utf8:
                    update_record = True
            elif record_type == 'a':
                if record['IP Address'] != value_utf8:
                    update_record = True
            elif record_type == 'host':
                if record['IP Addresses'] != [value_utf8]:
                    update_record = True
{'fraction_non_alphanumeric': 0.0726775956284153, 'fraction_numerical': 0.006375227686703097, 'mean_word_length': 1.4846153846153847, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2607889', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1387, 'n_words': 414}