Пример #1
0
def get_connector(*args, **kwargs):
    ''' Returns an instance of infoblox_client.connector.Connector
    :params args: positional arguments are silently ignored
    :params kwargs: dict that is passed to Connector init
    :returns: Connector
    '''
    if not HAS_INFOBLOX_CLIENT:
        raise Exception('infoblox-client is required but does not appear '
                        'to be installed.  It can be installed using the '
                        'command `pip install infoblox-client`')

    if not set(kwargs.keys()).issubset(NIOS_PROVIDER_SPEC.keys()):
        raise Exception(
            'invalid or unsupported keyword argument for connector')
    for key, value in iteritems(NIOS_PROVIDER_SPEC):
        if key not in kwargs:
            # apply default values from NIOS_PROVIDER_SPEC since we cannot just
            # assume the provider values are coming from AnsibleModule
            if 'default' in value:
                kwargs[key] = value['default']

            # override any values with env variables unless they were
            # explicitly set
            env = ('INFOBLOX_%s' % key).upper()
            if env in os.environ:
                kwargs[key] = os.environ.get(env)

    return Connector(kwargs)
Пример #2
0
def get_connector(*args, **kwargs):
    if not HAS_INFOBLOX_CLIENT:
        raise Exception('infoblox-client is required but does not appear '
                        'to be installed.  It can be installed using the '
                        'command `pip install infoblox-client`')

    if not set(kwargs.keys()).issubset(nios_provider_spec.keys()):
        raise Exception(
            'invalid or unsupported keyword argument for connector')

    for key in nios_provider_spec.keys():
        if key not in kwargs:
            env = ('INFOBLOX_%s' % key).upper()
            if env in os.environ:
                kwargs[key] = os.environ.get(env)

    return Connector(kwargs)
Пример #3
0
def get_connector(module):
    if not HAS_INFOBLOX_CLIENT:
        module.fail_json(msg='infoblox-client is required but does not appear '
                             'to be installed.  It can be installed using the '
                             'command `pip install infoblox-client`')
    return Connector(module.params['provider'])