Ejemplo n.º 1
0
def connect(module):
    """
    Connects to CVP device using user provided credentials from playbook.

    Parameters
    ----------
    module : AnsibleModule
        Ansible module.

    Returns
    -------
    CvpClient
        CvpClient object with connection instantiated.
    """
    client = CvpClient()
    connection = Connection(module._socket_path)
    host = connection.get_option("host")
    port = connection.get_option("port")
    user = connection.get_option("remote_user")
    pswd = connection.get_option("password")
    try:
        client.connect(
            [host],
            user,
            pswd,
            protocol="https",
            port=port,
        )
    except CvpLoginError as e:
        module.fail_json(msg=str(e))
    return client
Ejemplo n.º 2
0
def connect(module, debug=False):
    ''' Connects to CVP device using user provided credentials from playbook.
    :param module: Ansible module with parameters and client connection.
    :return: CvpClient object with connection instantiated.
    '''
    client = CvpClient()
    connection = Connection(module._socket_path)
    host = connection.get_option("host")
    port = connection.get_option("port")
    user = connection.get_option("remote_user")
    pswd = connection.get_option("password")
    if debug:
        logging.debug('*** Connecting to CVP')
    try:
        client.connect([host],
                       user,
                       pswd,
                       protocol="https",
                       port=port,
                       )
    except CvpLoginError as e:
        module.fail_json(msg=str(e))

    if debug:
        logging.debug('*** Connected to CVP')

    return client
Ejemplo n.º 3
0
def connect(module):
    """
    Create a connection to CVP server to use API

    Parameters
    ----------
    module : AnsibleModule
        Object representing Ansible module structure with a CvpClient connection

    Returns
    -------
    CvpClient
        CvpClient object to manager API calls.
    """
    client = CvpClient()
    connection = Connection(module._socket_path)
    host = connection.get_option("host")
    port = connection.get_option("port")
    user = connection.get_option("remote_user")
    pswd = connection.get_option("password")
    try:
        client.connect(
            [host],
            user,
            pswd,
            protocol="https",
            port=port,
        )
    except CvpLoginError as e:
        module.fail_json(msg=str(e))

    return client