Ejemplo n.º 1
0
def _connect(**kwargs):
    '''
    Initialise netscaler connection
    '''
    connargs = dict()

    # Shamelessy ripped from the mysql module
    def __connarg(name, key=None, default=None):
        '''
        Add key to connargs, only if name exists in our kwargs or as
        netscaler.<name> in __opts__ or __pillar__ Evaluate in said order - kwargs,
        opts then pillar. To avoid collision with other functions, kwargs-based
        connection arguments are prefixed with 'netscaler_' (i.e.
        'netscaler_host', 'netscaler_user', etc.).
        '''
        if key is None:
            key = name
        if name in kwargs:
            connargs[key] = kwargs[name]
        else:
            prefix = 'netscaler_'
            if name.startswith(prefix):
                try:
                    name = name[len(prefix):]
                except IndexError:
                    return
            val = __salt__['config.option']('netscaler.{0}'.format(name), None)
            if val is not None:
                connargs[key] = val
            elif default is not None:
                connargs[key] = default

    __connarg('netscaler_host', 'host')
    __connarg('netscaler_user', 'user')
    __connarg('netscaler_pass', 'pass')
    __connarg('netscaler_useSSL', 'useSSL', True)

    nitro = NSNitro(connargs['host'], connargs['user'], connargs['pass'],
                    connargs['useSSL'])
    try:
        nitro.login()
    except NSNitroError as error:
        log.debug(
            'netscaler module error - NSNitro.login() failed: {0}'.format(
                error))
        return None
    return nitro
Ejemplo n.º 2
0
def _connect(**kwargs):
    """
    Initialise netscaler connection
    """
    connargs = dict()

    # Shamelessy ripped from the mysql module
    def __connarg(name, key=None, default=None):
        """
        Add key to connargs, only if name exists in our kwargs or as
        netscaler.<name> in __opts__ or __pillar__ Evaluate in said order - kwargs,
        opts then pillar. To avoid collision with other functions, kwargs-based
        connection arguments are prefixed with 'netscaler_' (i.e.
        'netscaler_host', 'netscaler_user', etc.).
        """
        if key is None:
            key = name
        if name in kwargs:
            connargs[key] = kwargs[name]
        else:
            prefix = "netscaler_"
            if name.startswith(prefix):
                try:
                    name = name[len(prefix) :]
                except IndexError:
                    return
            val = __salt__["config.option"]("netscaler.{}".format(name), None)
            if val is not None:
                connargs[key] = val
            elif default is not None:
                connargs[key] = default

    __connarg("netscaler_host", "host")
    __connarg("netscaler_user", "user")
    __connarg("netscaler_pass", "pass")
    __connarg("netscaler_useSSL", "useSSL", True)

    nitro = NSNitro(
        connargs["host"], connargs["user"], connargs["pass"], connargs["useSSL"]
    )
    try:
        nitro.login()
    except NSNitroError as error:
        log.debug("netscaler module error - NSNitro.login() failed: %s", error)
        return None
    return nitro