def power_state_virsh(
self, power_address, power_id, power_pass=None, **kwargs):
"""Return the power state for the VM using virsh."""
# Force password to None if blank, as the power control
# script will send a blank password if one is not set.
if power_pass == '':
power_pass = None
conn = VirshSSH()
logged_in = yield deferToThread(conn.login, power_address, power_pass)
if not logged_in:
raise VirshError('Failed to login to virsh console.')
state = yield deferToThread(conn.get_machine_state, power_id)
if state is None:
raise VirshError('Failed to get domain: %s' % power_id)
try:
return VM_STATE_TO_POWER_STATE[state]
except KeyError:
raise VirshError('Unknown state: %s' % state)
评论列表
文章目录