Exemplo n.º 1
0
def get_resource_connection(module):
    if hasattr(module, '_connection'):
        return module._connection

    capabilities = get_capabilities(module)
    network_api = capabilities.get('network_api')
    if network_api == 'eapi':
        if HAS_EOS:
            module._connection = eos.get_connection(module)
        else:
            module.fail_json(msg=missing_required_lib("collection arista.eos"))
    elif network_api == 'nxapi':
        if HAS_NXOS:
            module._connection = nxos.get_connection(module)
        else:
            module.fail_json(msg=missing_required_lib("collection cisco.nxos"))
    elif network_api in ('cliconf', 'exosapi'):
        module._connection = Connection(module._socket_path)
    elif network_api == 'netconf':
        module._connection = NetconfConnection(module._socket_path)
    elif network_api == "local":
        # This isn't supported, but we shouldn't fail here.
        # Set the connection to a fake connection so it fails sensibly.
        module._connection = LocalResourceConnection(module)
    else:
        module.fail_json(
            msg='Invalid connection type {0!s}'.format(network_api))

    return module._connection
Exemplo n.º 2
0
def get_connection(module):
    if hasattr(module, 'connection'):
        return module.connection

    module.connection = NetconfConnection(module._socket_path)

    return module.connection
Exemplo n.º 3
0
def get_nc_connection(module):
    global _DEVICE_NC_CONNECTION
    if not _DEVICE_NC_CONNECTION:
        load_params(module)
        conn = NetconfConnection(module._socket_path)
        _DEVICE_NC_CONNECTION = conn
    return _DEVICE_NC_CONNECTION
Exemplo n.º 4
0
def get_device_capabilities(module):
    if hasattr(module, 'capabilities'):
        return module.capabilities

    capabilities = NetconfConnection(module._socket_path).get_capabilities()
    module.capabilities = json.loads(capabilities)

    return module.capabilities
Exemplo n.º 5
0
def get_connection(module):
    if hasattr(module, '_netconf_connection'):
        return module._netconf_connection

    capabilities = get_capabilities(module)
    network_api = capabilities.get('network_api')
    if network_api == 'netconf':
        module._netconf_connection = NetconfConnection(module._socket_path)
    else:
        module.fail_json(msg='Invalid connection type %s' % network_api)

    return module._netconf_connection
Exemplo n.º 6
0
def get_connection(module):
    if hasattr(module, 'connection'):
        return module.connection

    capabilities = get_device_capabilities(module)
    network_api = capabilities.get('network_api')
    if network_api == 'cliconf':
        module.connection = Connection(module._socket_path)
    elif network_api == 'netconf':
        module.connection = NetconfConnection(module._socket_path)
    else:
        module.fail_json(msg='Invalid connection type {!s}'.format(network_api))

    return module.connection
Exemplo n.º 7
0
def get_connection(module):
    if hasattr(module, "_junos_connection"):
        return module._junos_connection

    capabilities = get_capabilities(module)
    network_api = capabilities.get("network_api")
    if network_api == "cliconf":
        module._junos_connection = Connection(module._socket_path)
    elif network_api == "netconf":
        module._junos_connection = NetconfConnection(module._socket_path)
    else:
        module.fail_json(msg="Invalid connection type %s" % network_api)

    return module._junos_connection
Exemplo n.º 8
0
def get_resource_connection(module):
    if hasattr(module, '_connection'):
        return module._connection

    capabilities = get_capabilities(module)
    network_api = capabilities.get('network_api')
    if network_api in ('cliconf', 'nxapi', 'eapi', 'exosapi'):
        module._connection = Connection(module._socket_path)
    elif network_api == 'netconf':
        module._connection = NetconfConnection(module._socket_path)
    else:
        module.fail_json(
            msg='Invalid connection type {0!s}'.format(network_api))

    return module._connection