Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def get_connection(module):
    if hasattr(module, "connection"):
        return module.connection

    capabilities = get_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 {0!s}".format(network_api))

    return module.connection
Ejemplo n.º 5
0
def get_connection(module):
    if hasattr(module, 'connection'):
        return module.connection

    capabilities = get_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 {0!s}'.format(network_api))

    return module.connection
Ejemplo n.º 6
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 == "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._connection = Connection(module._socket_path)

    return module._connection
Ejemplo n.º 7
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)
    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