def pylxd_client_get(remote_addr=None, cert=None, key=None, verify_cert=True):
    '''
    Get an pyxld client, this is not ment to be runned over the CLI.

    remote_addr :
        An URL to a remote Server, you also have to give cert and key if you
        provide remote_addr and its a TCP Address!

        Examples:
            https://myserver.lan:8443
            /var/lib/mysocket.sock

    cert :
        PEM Formatted SSL Certificate.

        Examples:
            ~/.config/lxc/client.crt

    key :
        PEM Formatted SSL Key.

        Examples:
            ~/.config/lxc/client.key

    verify_cert : True
        Wherever to verify the cert, this is by default True
        but in the most cases you want to set it off as LXD
        normaly uses self-signed certificates.

    See the `requests-docs`_ for the SSL stuff.

    .. _requests-docs: http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification

    '''

    pool_key = '|'.join((six.text_type(remote_addr),
                         six.text_type(cert),
                         six.text_type(key),
                         six.text_type(verify_cert),))

    if pool_key in _connection_pool:
        log.debug('Returning the client "%s" from our connection pool', remote_addr)
        return _connection_pool[pool_key]

    try:
        if remote_addr is None or remote_addr == '/var/lib/lxd/unix.socket':
            log.debug('Trying to connect to the local unix socket')
            client = pylxd.Client()
        else:
            if remote_addr.startswith('/'):
                client = pylxd.Client(remote_addr)
            else:
                if cert is None or key is None:
                    raise SaltInvocationError(
                        ('You have to give a Cert and '
                         'Key file for remote endpoints.')
                    )

                cert = os.path.expanduser(cert)
                key = os.path.expanduser(key)

                if not os.path.isfile(cert):
                    raise SaltInvocationError(
                        ('You have given an invalid cert path: "{0}", '
                         'the file does not exists or is not a file.').format(
                            cert
                        )
                    )

                if not os.path.isfile(key):
                    raise SaltInvocationError(
                        ('You have given an invalid key path: "{0}", '
                         'the file does not exists or is not a file.').format(
                            key
                        )
                    )

                log.debug(
                    'Trying to connect to "%s" with cert "%s", key "%s" and '
                    'verify_cert "%s"', remote_addr, cert, key, verify_cert
                )
                client = pylxd.Client(
                    endpoint=remote_addr,
                    cert=(cert, key,),
                    verify=verify_cert
                )
    except pylxd.exceptions.ClientConnectionFailed:
        raise CommandExecutionError(
            "Failed to connect to '{0}'".format(remote_addr)
        )

    except TypeError as e:
        # Happens when the verification failed.
        raise CommandExecutionError(
            ('Failed to connect to "{0}",'
             ' looks like the SSL verification failed, error was: {1}'
             ).format(remote_addr, six.text_type(e))
        )

    _connection_pool[pool_key] = client

    return client
def pylxd_client_get ( remote_addr = None , cert = None , key = None , verify_cert = True ) : pool_key = '|' . join ( ( six . text_type ( remote_addr ) , six . text_type ( cert ) , six . text_type ( key ) , six . text_type ( verify_cert ) , ) ) if pool_key in _connection_pool : log . debug ( 'Returning the client "%s" from our connection pool' , remote_addr ) return _connection_pool [ pool_key ] try : if remote_addr is None or remote_addr == '/var/lib/lxd/unix.socket' : log . debug ( 'Trying to connect to the local unix socket' ) client = pylxd . Client ( ) else : if remote_addr . startswith ( '/' ) : client = pylxd . Client ( remote_addr ) else : if cert is None or key is None : raise SaltInvocationError ( ( 'You have to give a Cert and ' 'Key file for remote endpoints.' ) ) cert = os . path . expanduser ( cert ) key = os . path . expanduser ( key ) if not os . path . isfile ( cert ) : raise SaltInvocationError ( ( 'You have given an invalid cert path: "{0}", ' 'the file does not exists or is not a file.' ) . format ( cert ) ) if not os . path . isfile ( key ) : raise SaltInvocationError ( ( 'You have given an invalid key path: "{0}", ' 'the file does not exists or is not a file.' ) . format ( key ) ) log . debug ( 'Trying to connect to "%s" with cert "%s", key "%s" and ' 'verify_cert "%s"' , remote_addr , cert , key , verify_cert ) client = pylxd . Client ( endpoint = remote_addr , cert = ( cert , key , ) , verify = verify_cert ) except pylxd . exceptions . ClientConnectionFailed : raise CommandExecutionError ( "Failed to connect to '{0}'" . format ( remote_addr ) ) except TypeError as e : raise CommandExecutionError ( ( 'Failed to connect to "{0}",' ' looks like the SSL verification failed, error was: {1}' ) . format ( remote_addr , six . text_type ( e ) ) ) _connection_pool [ pool_key ] = client return client
Get an pyxld client, this is not ment to be runned over the CLI.

    remote_addr :
        An URL to a remote Server, you also have to give cert and key if you
        provide remote_addr and its a TCP Address!

        Examples:
            https://myserver.lan:8443
            /var/lib/mysocket.sock

    cert :
        PEM Formatted SSL Certificate.

        Examples:
            ~/.config/lxc/client.crt

    key :
        PEM Formatted SSL Key.

        Examples:
            ~/.config/lxc/client.key

    verify_cert : True
        Wherever to verify the cert, this is by default True
        but in the most cases you want to set it off as LXD
        normaly uses self-signed certificates.

    See the `requests-docs`_ for the SSL stuff.

    .. _requests-docs: http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification