本文整理汇总了Python中libvirt.VIR_CRED_AUTHNAME属性的典型用法代码示例。如果您正苦于以下问题:Python libvirt.VIR_CRED_AUTHNAME属性的具体用法?Python libvirt.VIR_CRED_AUTHNAME怎么用?Python libvirt.VIR_CRED_AUTHNAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类libvirt
的用法示例。
在下文中一共展示了libvirt.VIR_CRED_AUTHNAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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)
示例2: retrieve_credentials
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [as 别名]
def retrieve_credentials(self, credentials, user_data):
"""
Retrieves the libvirt credentials in a strange format and hand it to
the API in order to communicate with the hypervisor.
To be honest, I have no idea why this has to be done this way. I have
taken this function from the official libvirt documentation.
:param credentials: libvirt credentials object
:param user_data: some data that will never be used
:type user_data: None
"""
#get credentials for libvirt
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
credential[4] = self.USERNAME
if len(credential[4]) == 0:
credential[4] = credential[3]
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
credential[4] = self.PASSWORD
else:
return -1
return 0
示例3: request_credentials
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [as 别名]
def request_credentials(credentials, user_data):
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
# prompt the user to input a authname. display the provided message
credential[4] = "root"
# if the user just hits enter raw_input() returns an empty string.
# in this case return the default result through the last item of
# the list
if len(credential[4]) == 0:
credential[4] = credential[3]
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
# use the getpass module to prompt the user to input a password.
# display the provided message and return the result through the
# last item of the list
credential[4] = "redhat"
else:
return -1
return 0
示例4: getCredentials
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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
示例5: _auth_callback
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [as 别名]
def _auth_callback(self, credentials, user_data):
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
credential[4] = self.options.esx.username
elif credential[0] == libvirt.VIR_CRED_NOECHOPROMPT:
credential[4] = self.options.esx.password
else:
raise CuckooCriticalError("ESX machinery did not recieve an object to inject a username or password into")
return 0
示例6: _global_connect
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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)
示例7: __connect
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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")
示例8: request_credentials
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [as 别名]
def request_credentials(credentials, user_data):
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
credential[4] = user_data[0]
if len(credential[4]) == 0:
credential[4] = credential[3]
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
credential[4] = user_data[1]
else:
return -1
return 0
示例9: get_conn
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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
示例10: hypervisor_connecting_test
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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
示例11: hypervisor_connecting_test
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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
示例12: _connect
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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)
示例13: libvirt_cred_request
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [as 别名]
def libvirt_cred_request(credentials, config):
""" Callback function for requesting credentials from libvirt """
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
credential[4] = config.get('username', None)
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
credential[4] = config.get('password', None)
else:
return -1
return 0
示例14: _connect
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [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
示例15: __libvirt_auth_credentials_callback
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_CRED_AUTHNAME [as 别名]
def __libvirt_auth_credentials_callback(self, credentials, user_data):
for credential in credentials:
if credential[0] == libvirt.VIR_CRED_AUTHNAME:
credential[4] = self.login
if len(credential[4]) == 0:
credential[4] = credential[3]
elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
credential[4] = self.passwd
else:
return -1
return 0