當前位置: 首頁>>代碼示例>>Python>>正文


Python libvirt.openAuth方法代碼示例

本文整理匯總了Python中libvirt.openAuth方法的典型用法代碼示例。如果您正苦於以下問題:Python libvirt.openAuth方法的具體用法?Python libvirt.openAuth怎麽用?Python libvirt.openAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在libvirt的用法示例。


在下文中一共展示了libvirt.openAuth方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __enter__

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def __enter__(self):
        try:
            if self.sasl_username and self.sasl_password:

                def request_cred(credentials, user_data):
                    for credential in credentials:
                        if credential[0] == libvirt.VIR_CRED_AUTHNAME:
                            credential[4] = self.sasl_username
                        elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
                            credential[4] = self.sasl_password
                    return 0

                auth = [[libvirt.VIR_CRED_AUTHNAME,
                         libvirt.VIR_CRED_PASSPHRASE], request_cred, None]
                flags = libvirt.VIR_CONNECT_RO if self.readonly else 0
                self.conn = libvirt.openAuth(self.uri, auth, flags)
            elif self.readonly:
                self.conn = libvirt.openReadOnly(self.uri)
            else:
                self.conn = libvirt.open(self.uri)

            return self.conn

        except libvirt.libvirtError as e:
            raise exception.LibvirtConnectionOpenError(uri=self.uri, error=e) 
開發者ID:openstack,項目名稱:virtualbmc,代碼行數:27,代碼來源:utils.py

示例2: getCredentials

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def getCredentials(creds, data):
    """Used as a backup for libvirt.openAuth in order to provide password that came with data,
    not used by the moment
    """
    print "RADclass:getCredentials", creds, data
    for cred in creds:
        print cred[1] + ": ",
        if cred[0] == libvirt.VIR_CRED_AUTHNAME:
            cred[4] = data
        elif cred[0] == libvirt.VIR_CRED_PASSPHRASE:
            cred[4] = data
        else:
            return -1
    return 0 
開發者ID:nfvlabs,項目名稱:openmano,代碼行數:16,代碼來源:RADclass.py

示例3: _global_connect

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def _global_connect(self):
        """Set the single connection handle."""
        try:
            self.auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT], self._auth_callback, None]
            return libvirt.openAuth(self.dsn, self.auth, 0)
        except libvirt.libvirtError as libvex:
            raise CuckooCriticalError("libvirt returned an exception on connection: %s" % libvex) 
開發者ID:phdphuc,項目名稱:mac-a-mal-cuckoo,代碼行數:9,代碼來源:esx.py

示例4: __connect

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def __connect(self):
        """This function establishes a connection to the hypervisor."""
        #create weirdo auth dict
        auth = [
            [libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
            self.retrieve_credentials, None
            ]
        #authenticate
        try:
            self.SESSION = libvirt.openAuth(self.URI, auth, 0)
            if self.SESSION == None:
                raise SessionException("Unable to establish connection to hypervisor!")
        except libvirt.libvirtError as err:
            raise InvalidCredentialsException("Invalid credentials") 
開發者ID:stdevel,項目名稱:katprep,代碼行數:16,代碼來源:LibvirtClient.py

示例5: get_conn

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def get_conn(uri='', username='', password=''):
    """ get connection object from libvirt module
    """
    user_data = [username, password]
    auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
            request_credentials, user_data]
    conn = libvirt.openAuth(uri, auth, 0)
    return conn 
開發者ID:libvirt,項目名稱:libvirt-test-API,代碼行數:10,代碼來源:utils.py

示例6: hypervisor_connecting_test

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def hypervisor_connecting_test(uri, auth_tcp, username,
                               password, logger, expected_result):
    """ connect remote server """
    ret = 1
    try:
        if auth_tcp == 'none':
            logger.debug("call libvirt.open()")
            conn = libvirt.open(uri)
        elif auth_tcp == 'sasl':
            user_data = [username, password]
            auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], request_credentials, user_data]
            logger.debug("call libvirt.openAuth()")
            conn = libvirt.openAuth(uri, auth, 0)

        ret = 0
        conn.close()
    except libvirtError as e:
        logger.error("API error message: %s, error code is %s"
                     % (e.get_error_message(), e.get_error_code()))
        ret = 1

    if ret == 0 and expected_result == 'success':
        logger.info("tcp connnection success")
        return 0
    elif ret == 1 and expected_result == 'fail':
        logger.info("tcp connection failed, but that is expected")
        return 0
    elif ret == 0 and expected_result == 'fail':
        logger.error("tcp connection success, but we hope the reverse")
        return 1
    elif ret == 1 and expected_result == 'success':
        logger.error("tcp connection failed")
        return 1

    return 0 
開發者ID:libvirt,項目名稱:libvirt-test-API,代碼行數:37,代碼來源:tcp_setup.py

示例7: hypervisor_connecting_test

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def hypervisor_connecting_test(uri, auth_tls, username,
                               password, logger, expected_result):
    """ connect remote server """
    ret = 0
    try:
        if auth_tls == 'none':
            logger.debug("call libvirt.open()")
            conn = libvirt.open(uri)
        elif auth_tls == 'sasl':
            user_data = [username, password]
            auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], request_credentials, user_data]
            logger.debug("call libvirt.openAuth()")
            conn = libvirt.openAuth(uri, auth, 0)
        conn.close()
    except libvirtError as e:
        logger.error("API error message: %s, error code is %s"
                     % (e.get_error_message(), e.get_error_code()))
        ret = 1

    if ret == 0 and expected_result == 'success':
        logger.info("tls authentication success")
        return 0
    elif ret == 1 and expected_result == 'fail':
        logger.info("tls authentication failed, but that is expected")
        return 0
    elif ret == 0 and expected_result == 'fail':
        logger.error("tls authentication success, but we hope the reverse")
        return 1
    elif ret == 1 and expected_result == 'success':
        logger.error("tls authentication failed")
        return 1

    return 0 
開發者ID:libvirt,項目名稱:libvirt-test-API,代碼行數:35,代碼來源:tls_setup.py

示例8: hypervisor_connecting_test

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def hypervisor_connecting_test(uri, auth_tls, username,
                               password, logger, expected_result):
    """ connect remote server """
    ret = 0
    try:
        if auth_tls == 'none':
            logger.debug("call libvirt.open()")
            conn = libvirt.open(uri)
        elif auth_tls == 'sasl':
            user_data = [username, password]
            auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], domain_common.request_credentials, user_data]
            logger.debug("call libvirt.openAuth()")
            conn = libvirt.openAuth(uri, auth, 0)
        conn.close()
    except libvirtError as e:
        logger.error("API error message: %s, error code is %s"
                     % (e.get_error_message(), e.get_error_code()))
        ret = 1

    if ret == 0 and expected_result == 'success':
        logger.info("tls authentication success")
        return 0
    elif ret == 1 and expected_result == 'fail':
        logger.info("tls authentication failed, but that is expected")
        return 0
    elif ret == 0 and expected_result == 'fail':
        logger.error("tls authentication success, but we hope the reverse")
        return 1
    elif ret == 1 and expected_result == 'success':
        logger.error("tls authentication failed")
        return 1

    return 0 
開發者ID:libvirt,項目名稱:libvirt-test-API,代碼行數:35,代碼來源:tls_setup_new.py

示例9: _connect

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def _connect(self):
        try:
            self.auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT], self._auth_callback, None]
            return libvirt.openAuth(self.dsn, self.auth, 0)
        except libvirt.libvirtError as libvex:
            raise CuckooCriticalError("libvirt returned an exception on connection: %s" % libvex) 
開發者ID:davidoren,項目名稱:CuckooSploit,代碼行數:8,代碼來源:esx.py

示例10: _connect

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def _connect(self):
        url = self.config.get('server', "")
        self.logger.info("Using libvirt url: %s", url if url else '""')
        try:
            if self.config.get('password', None):
                auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], libvirt_cred_request, self.config]
                v = libvirt.openAuth(url, auth, libvirt.VIR_CONNECT_RO)
            else:
                v = libvirt.openReadOnly(url)
        except libvirt.libvirtError as e:
            self.logger.exception("Error in libvirt backend")
            raise VirtError(str(e))
        v.domainEventRegister(self._callback, None)
        v.setKeepAlive(5, 3)
        return v 
開發者ID:candlepin,項目名稱:virt-who,代碼行數:17,代碼來源:libvirtd.py

示例11: __connect_tcp

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def __connect_tcp(self):
        flags = [libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE]
        auth = [flags, self.__libvirt_auth_credentials_callback, None]
        uri = 'qemu+tcp://%s/system' % self.host

        try:
            return libvirt.openAuth(uri, auth, 0)
        except libvirtError as e:
            self.last_error = 'Connection Failed: ' + str(e)
            self.connection = None 
開發者ID:welliamcao,項目名稱:VManagePlatform,代碼行數:12,代碼來源:vMConUtils.py

示例12: __connect_tls

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def __connect_tls(self):
        flags = [libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE]
        auth = [flags, self.__libvirt_auth_credentials_callback, None]
        uri = 'qemu+tls://%s@%s/system' % (self.login, self.host)

        try:
            return libvirt.openAuth(uri, auth, 0)
        except libvirtError as e:
            self.last_error = 'Connection Failed: ' + str(e)
            self.connection = None 
開發者ID:welliamcao,項目名稱:VManagePlatform,代碼行數:12,代碼來源:vMConUtils.py

示例13: hypervisor_connecting_test

# 需要導入模塊: import libvirt [as 別名]
# 或者: from libvirt import openAuth [as 別名]
def hypervisor_connecting_test(uri, unix_sock_group, auth_unix_ro, auth_unix_rw, logger):
    """connect to hypervisor"""
    logger.info("connect to hypervisor")
    orginal_user = os.geteuid()
    testing_user_id = getpwnam(TESTING_USER)[2]
    logger.info("the testing_user id is %d" % testing_user_id)

    logger.info("set euid to %d" % testing_user_id)
    os.seteuid(testing_user_id)

    if utils.version_compare("libvirt", 3, 2, 0, logger):
        cmd = "klist -A | grep 'Ticket cache: FILE:' | awk '{print $3}'"
        ret, out = utils.exec_cmd(cmd, shell=True)
        if ret:
            logger.error("get ticket cache file failed.")
            logger.error("cmd: %s" % cmd)
            logger.error("out: %s" % out)
            return 1

        TICKET_CACHE = out[0].split(':')[1]
        cmd = "chown %s:%s %s" % (TESTING_USER, unix_sock_group, TICKET_CACHE)
        ret, out = utils.exec_cmd(cmd, shell=True)
        if ret:
            logger.error("change %s owner failed." % TICKET_CACHE)
            return 1

    try:
        if auth_unix_ro == 'none':
            conn = libvirt.openReadOnly(uri)
        elif auth_unix_ro == 'sasl':
            user_data = [TESTING_USER, TESTING_USER]
            auth = [[libvirt.VIR_CRED_AUTHNAME,
                     libvirt.VIR_CRED_PASSPHRASE],
                    request_credentials, user_data]
            conn = libvirt.openAuth(uri, auth, 0)

        if auth_unix_rw == 'none':
            conn = libvirt.open(uri)
        elif auth_unix_rw == 'sasl':
            user_data = [TESTING_USER, TESTING_USER]
            auth = [[libvirt.VIR_CRED_AUTHNAME,
                     libvirt.VIR_CRED_PASSPHRASE],
                    request_credentials, user_data]
            conn = libvirt.openAuth(uri, auth, 0)
        conn.close()
    except libvirtError as e:
        logger.error("API error message: %s, error code is %s"
                     % (e.get_error_message(), e.get_error_code()))
        logger.info("set euid back to %d" % orginal_user)
        os.seteuid(orginal_user)
        conn.close()
        return 1

    logger.info("set euid back to %d" % orginal_user)
    os.seteuid(orginal_user)
    return 0 
開發者ID:libvirt,項目名稱:libvirt-test-API,代碼行數:58,代碼來源:unix_perm_sasl.py


注:本文中的libvirt.openAuth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。