def get_server(self, context, server_id, privileged_user=False, timeout=None): try: return novaclient(context, privileged_user=privileged_user, timeout=timeout).servers.get(server_id) except nova_exceptions.NotFound: raise exception.ServerNotFound(uuid=server_id) except request_exceptions.Timeout: raise exception.APITimeout(service='Nova')
def exec_cmd(self, context, server_id, command, run_as="root", timeout=None): server = self.get_server(context, server_id, timeout=timeout) try: return novaclient(context, timeout=timeout)\ .servers.exec_cmd_by_qga(server, command, run_as) except nova_exceptions.NotFound: raise exception.ServerNotFound(uuid=server_id) except request_exceptions.Timeout: raise exception.APITimeout(service='Nova') except Exception as e: LOG.error(_LE("Run cmd error, %s"), e) raise exception.ExecCmdError()
def set_vm_state(self, context, server_id, vm_state, timeout=None): server = self.get_server(context, server_id, timeout=timeout) try: return novaclient(context, timeout=timeout).servers.reset_state( server, vm_state) except nova_exceptions.NotFound: raise exception.ServerNotFound(uuid=server_id) except request_exceptions.Timeout: raise exception.APITimeout(service='Nova') except Exception as e: if isinstance(e, basestring): errmsg = e else: errmsg = e.message if errmsg.find(NOT_PERMIT_VM_STATE) != -1: raise exception.NotPermitVmState() else: raise
def thaw_filesystem(self, context, server_id, timeout=None): server = self.get_server(context, server_id, timeout=timeout) if server.status in [ "SHUTOFF", "PAUSED", "SUSPENDED", "SHELVED_OFFLOADED" ]: LOG.warn( _LW("VM %(server_id)s is in %(state)s state, do not need" "to thaw filesystem"), { 'server_id': server_id, 'state': server.status }) return try: return novaclient(context, timeout=timeout).servers.thaw_filesystem(server) except nova_exceptions.NotFound: raise exception.ServerNotFound(uuid=server_id) except request_exceptions.Timeout: raise exception.APITimeout(service='Nova') except nova_exceptions.Conflict as e: if isinstance(e, basestring): errmsg = e else: errmsg = e.message LOG.warn( _LW('vm %(server_id)s freeze fs meet error,' 'error message is %(message)s'), { 'server_id': server_id, 'message': e.message }) if errmsg.find(QEMU_GA_NOT_ENABLE) != -1: raise exception.QemuGANotEnable() elif errmsg.find(QEMU_GA_NOT_AVAILABLE) != -1: raise exception.QemuGANotAvailable() elif errmsg.find(QEMU_GA_REPEAT_THAW) != -1: raise exception.QemuGARepeatThaw() else: raise