diff options
Diffstat (limited to 'scripts/qmp')
-rwxr-xr-x | scripts/qmp/qemu-ga-client | 10 | ||||
-rwxr-xr-x | scripts/qmp/qmp | 24 | ||||
-rwxr-xr-x | scripts/qmp/qmp-shell | 40 | ||||
-rwxr-xr-x | scripts/qmp/qom-fuse | 11 | ||||
-rwxr-xr-x | scripts/qmp/qom-get | 12 | ||||
-rwxr-xr-x | scripts/qmp/qom-list | 16 | ||||
-rwxr-xr-x | scripts/qmp/qom-set | 10 | ||||
-rwxr-xr-x | scripts/qmp/qom-tree | 16 |
8 files changed, 77 insertions, 62 deletions
diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index 7d2a472094..976e69e05f 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -36,10 +36,12 @@ # See also: https://wiki.qemu.org/Features/QAPI/GuestAgent # +from __future__ import print_function +from __future__ import absolute_import import base64 import random -import qmp +from . import qmp class QemuGuestAgent(qmp.QEMUMonitorProtocol): @@ -135,7 +137,7 @@ class QemuGuestAgentClient: def fsfreeze(self, cmd): if cmd not in ['status', 'freeze', 'thaw']: - raise StandardError('Invalid command: ' + cmd) + raise Exception('Invalid command: ' + cmd) return getattr(self.qga, 'fsfreeze' + '_' + cmd)() @@ -144,7 +146,7 @@ class QemuGuestAgentClient: def suspend(self, mode): if mode not in ['disk', 'ram', 'hybrid']: - raise StandardError('Invalid mode: ' + mode) + raise Exception('Invalid mode: ' + mode) try: getattr(self.qga, 'suspend' + '_' + mode)() @@ -155,7 +157,7 @@ class QemuGuestAgentClient: def shutdown(self, mode='powerdown'): if mode not in ['powerdown', 'halt', 'reboot']: - raise StandardError('Invalid mode: ' + mode) + raise Exception('Invalid mode: ' + mode) try: self.qga.shutdown(mode=mode) diff --git a/scripts/qmp/qmp b/scripts/qmp/qmp index 514b539a6b..33a0d6b73a 100755 --- a/scripts/qmp/qmp +++ b/scripts/qmp/qmp @@ -10,8 +10,10 @@ # This work is licensed under the terms of the GNU GPLv2 or later. # See the COPYING file in the top-level directory. +from __future__ import print_function +from __future__ import absolute_import import sys, os -from qmp import QEMUMonitorProtocol +from .qmp import QEMUMonitorProtocol def print_response(rsp, prefix=[]): if type(rsp) == list: @@ -26,15 +28,15 @@ def print_response(rsp, prefix=[]): print_response(rsp[key], prefix + [key]) else: if len(prefix): - print '%s: %s' % ('.'.join(prefix), rsp) + print('%s: %s' % ('.'.join(prefix), rsp)) else: - print '%s' % (rsp) + print('%s' % (rsp)) def main(args): path = None # Use QMP_PATH if it's set - if os.environ.has_key('QMP_PATH'): + if 'QMP_PATH' in os.environ: path = os.environ['QMP_PATH'] while len(args): @@ -53,21 +55,21 @@ def main(args): elif arg in ['help']: os.execlp('man', 'man', 'qmp') else: - print 'Unknown argument "%s"' % arg + print('Unknown argument "%s"' % arg) args = args[1:] else: break if not path: - print "QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH" + print("QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH") return 1 if len(args): command, args = args[0], args[1:] else: - print 'No command found' - print 'Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"' + print('No command found') + print('Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"') return 1 if command in ['help']: @@ -78,7 +80,7 @@ def main(args): def do_command(srv, cmd, **kwds): rsp = srv.cmd(cmd, kwds) - if rsp.has_key('error'): + if 'error' in rsp: raise Exception(rsp['error']['desc']) return rsp['return'] @@ -93,7 +95,7 @@ def main(args): os.execvp(fullcmd, [fullcmd] + args) except OSError as exc: if exc.errno == 2: - print 'Command "%s" not found.' % (fullcmd) + print('Command "%s" not found.' % (fullcmd)) return 1 raise return 0 @@ -104,7 +106,7 @@ def main(args): arguments = {} for arg in args: if not arg.startswith('--'): - print 'Unknown argument "%s"' % arg + print('Unknown argument "%s"' % arg) return 1 arg = arg[2:] diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index be449de621..26418dab95 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -65,7 +65,9 @@ # which will echo back the properly formatted JSON-compliant QMP that is being # sent to QEMU, which is useful for debugging and documentation generation. -import qmp +from __future__ import print_function +from __future__ import absolute_import +from . import qmp import json import ast import readline @@ -132,7 +134,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): def _fill_completion(self): cmds = self.cmd('query-commands') - if cmds.has_key('error'): + if 'error' in cmds: return for cmd in cmds['return']: self._completer.append(cmd['name']) @@ -153,14 +155,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): # File not found. No problem. pass else: - print "Failed to read history '%s'; %s" % (self._histfile, e) + print("Failed to read history '%s'; %s" % (self._histfile, e)) atexit.register(self.__save_history) def __save_history(self): try: readline.write_history_file(self._histfile) except Exception as e: - print "Failed to save history file '%s'; %s" % (self._histfile, e) + print("Failed to save history file '%s'; %s" % (self._histfile, e)) def __parse_value(self, val): try: @@ -258,15 +260,15 @@ class QMPShell(qmp.QEMUMonitorProtocol): if self._pretty: indent = 4 jsobj = json.dumps(qmp, indent=indent) - print str(jsobj) + print(str(jsobj)) def _execute_cmd(self, cmdline): try: qmpcmd = self.__build_cmd(cmdline) except Exception as e: - print 'Error while parsing command line: %s' % e - print 'command format: <command-name> ', - print '[arg-name1=arg1] ... [arg-nameN=argN]' + print('Error while parsing command line: %s' % e) + print('command format: <command-name> ', end=' ') + print('[arg-name1=arg1] ... [arg-nameN=argN]') return True # For transaction mode, we may have just cached the action: if qmpcmd is None: @@ -275,7 +277,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): self._print(qmpcmd) resp = self.cmd_obj(qmpcmd) if resp is None: - print 'Disconnected' + print('Disconnected') return False self._print(resp) return True @@ -285,12 +287,12 @@ class QMPShell(qmp.QEMUMonitorProtocol): self.__completer_setup() def show_banner(self, msg='Welcome to the QMP low-level shell!'): - print msg + print(msg) if not self._greeting: - print 'Connected' + print('Connected') return version = self._greeting['QMP']['version']['qemu'] - print 'Connected to QEMU %d.%d.%d\n' % (version['major'],version['minor'],version['micro']) + print('Connected to QEMU %d.%d.%d\n' % (version['major'],version['minor'],version['micro'])) def get_prompt(self): if self._transmode: @@ -306,11 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol): try: cmdline = raw_input(prompt) except EOFError: - print + print() return False if cmdline == '': for ev in self.get_events(): - print ev + print(ev) self.clear_events() return True else: @@ -366,24 +368,24 @@ class HMPShell(QMPShell): try: idx = int(cmdline.split()[1]) if not 'return' in self.__cmd_passthrough('info version', idx): - print 'bad CPU index' + print('bad CPU index') return True self.__cpu_index = idx except ValueError: - print 'cpu command takes an integer argument' + print('cpu command takes an integer argument') return True resp = self.__cmd_passthrough(cmdline, self.__cpu_index) if resp is None: - print 'Disconnected' + print('Disconnected') return False assert 'return' in resp or 'error' in resp if 'return' in resp: # Success if len(resp['return']) > 0: - print resp['return'], + print(resp['return'], end=' ') else: # Error - print '%s: %s' % (resp['error']['class'], resp['error']['desc']) + print('%s: %s' % (resp['error']['class'], resp['error']['desc'])) return True def show_banner(self): diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index 5c6754aa63..e524e798fc 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -11,11 +11,12 @@ # the COPYING file in the top-level directory. ## +from __future__ import absolute_import import fuse, stat from fuse import Fuse import os, posix from errno import * -from qmp import QEMUMonitorProtocol +from .qmp import QEMUMonitorProtocol fuse.fuse_python_api = (0, 2) @@ -28,7 +29,7 @@ class QOMFS(Fuse): self.ino_count = 1 def get_ino(self, path): - if self.ino_map.has_key(path): + if path in self.ino_map: return self.ino_map[path] self.ino_map[path] = self.ino_count self.ino_count += 1 @@ -89,7 +90,7 @@ class QOMFS(Fuse): def getattr(self, path): if self.is_link(path): - value = posix.stat_result((0755 | stat.S_IFLNK, + value = posix.stat_result((0o755 | stat.S_IFLNK, self.get_ino(path), 0, 2, @@ -100,7 +101,7 @@ class QOMFS(Fuse): 0, 0)) elif self.is_object(path): - value = posix.stat_result((0755 | stat.S_IFDIR, + value = posix.stat_result((0o755 | stat.S_IFDIR, self.get_ino(path), 0, 2, @@ -111,7 +112,7 @@ class QOMFS(Fuse): 0, 0)) elif self.is_property(path): - value = posix.stat_result((0644 | stat.S_IFREG, + value = posix.stat_result((0o644 | stat.S_IFREG, self.get_ino(path), 0, 1, diff --git a/scripts/qmp/qom-get b/scripts/qmp/qom-get index 0172c69441..a3f5d7660e 100755 --- a/scripts/qmp/qom-get +++ b/scripts/qmp/qom-get @@ -11,9 +11,11 @@ # the COPYING file in the top-level directory. ## +from __future__ import print_function +from __future__ import absolute_import import sys import os -from qmp import QEMUMonitorProtocol +from .qmp import QEMUMonitorProtocol cmd, args = sys.argv[0], sys.argv[1:] socket_path = None @@ -33,7 +35,7 @@ def usage_error(error_msg = "unspecified error"): if len(args) > 0: if args[0] == "-h": - print usage() + print(usage()) exit(0); elif args[0] == "-s": try: @@ -43,7 +45,7 @@ if len(args) > 0: args = args[2:] if not socket_path: - if os.environ.has_key('QMP_SOCKET'): + if 'QMP_SOCKET' in os.environ: socket_path = os.environ['QMP_SOCKET'] else: usage_error("no QMP socket path or address given"); @@ -62,6 +64,6 @@ srv.connect() rsp = srv.command('qom-get', path=path, property=prop) if type(rsp) == dict: for i in rsp.keys(): - print '%s: %s' % (i, rsp[i]) + print('%s: %s' % (i, rsp[i])) else: - print rsp + print(rsp) diff --git a/scripts/qmp/qom-list b/scripts/qmp/qom-list index 1e7cc6cb2d..2ba25e1792 100755 --- a/scripts/qmp/qom-list +++ b/scripts/qmp/qom-list @@ -11,9 +11,11 @@ # the COPYING file in the top-level directory. ## +from __future__ import print_function +from __future__ import absolute_import import sys import os -from qmp import QEMUMonitorProtocol +from .qmp import QEMUMonitorProtocol cmd, args = sys.argv[0], sys.argv[1:] socket_path = None @@ -33,7 +35,7 @@ def usage_error(error_msg = "unspecified error"): if len(args) > 0: if args[0] == "-h": - print usage() + print(usage()) exit(0); elif args[0] == "-s": try: @@ -43,7 +45,7 @@ if len(args) > 0: args = args[2:] if not socket_path: - if os.environ.has_key('QMP_SOCKET'): + if 'QMP_SOCKET' in os.environ: socket_path = os.environ['QMP_SOCKET'] else: usage_error("no QMP socket path or address given"); @@ -52,13 +54,13 @@ srv = QEMUMonitorProtocol(socket_path) srv.connect() if len(args) == 0: - print '/' + print('/') sys.exit(0) for item in srv.command('qom-list', path=args[0]): if item['type'].startswith('child<'): - print '%s/' % item['name'] + print('%s/' % item['name']) elif item['type'].startswith('link<'): - print '@%s/' % item['name'] + print('@%s/' % item['name']) else: - print '%s' % item['name'] + print('%s' % item['name']) diff --git a/scripts/qmp/qom-set b/scripts/qmp/qom-set index 94e2778922..0352668812 100755 --- a/scripts/qmp/qom-set +++ b/scripts/qmp/qom-set @@ -11,9 +11,11 @@ # the COPYING file in the top-level directory. ## +from __future__ import print_function +from __future__ import absolute_import import sys import os -from qmp import QEMUMonitorProtocol +from .qmp import QEMUMonitorProtocol cmd, args = sys.argv[0], sys.argv[1:] socket_path = None @@ -34,7 +36,7 @@ def usage_error(error_msg = "unspecified error"): if len(args) > 0: if args[0] == "-h": - print usage() + print(usage()) exit(0); elif args[0] == "-s": try: @@ -44,7 +46,7 @@ if len(args) > 0: args = args[2:] if not socket_path: - if os.environ.has_key('QMP_SOCKET'): + if 'QMP_SOCKET' in os.environ: socket_path = os.environ['QMP_SOCKET'] else: usage_error("no QMP socket path or address given"); @@ -61,4 +63,4 @@ else: srv = QEMUMonitorProtocol(socket_path) srv.connect() -print srv.command('qom-set', path=path, property=prop, value=value) +print(srv.command('qom-set', path=path, property=prop, value=value)) diff --git a/scripts/qmp/qom-tree b/scripts/qmp/qom-tree index 906fcd2640..32e708a13e 100755 --- a/scripts/qmp/qom-tree +++ b/scripts/qmp/qom-tree @@ -13,9 +13,11 @@ # the COPYING file in the top-level directory. ## +from __future__ import print_function +from __future__ import absolute_import import sys import os -from qmp import QEMUMonitorProtocol +from .qmp import QEMUMonitorProtocol cmd, args = sys.argv[0], sys.argv[1:] socket_path = None @@ -35,7 +37,7 @@ def usage_error(error_msg = "unspecified error"): if len(args) > 0: if args[0] == "-h": - print usage() + print(usage()) exit(0); elif args[0] == "-s": try: @@ -45,7 +47,7 @@ if len(args) > 0: args = args[2:] if not socket_path: - if os.environ.has_key('QMP_SOCKET'): + if 'QMP_SOCKET' in os.environ: socket_path = os.environ['QMP_SOCKET'] else: usage_error("no QMP socket path or address given"); @@ -54,15 +56,15 @@ srv = QEMUMonitorProtocol(socket_path) srv.connect() def list_node(path): - print '%s' % path + print('%s' % path) items = srv.command('qom-list', path=path) for item in items: if not item['type'].startswith('child<'): try: - print ' %s: %s (%s)' % (item['name'], srv.command('qom-get', path=path, property=item['name']), item['type']) + print(' %s: %s (%s)' % (item['name'], srv.command('qom-get', path=path, property=item['name']), item['type'])) except: - print ' %s: <EXCEPTION> (%s)' % (item['name'], item['type']) - print '' + print(' %s: <EXCEPTION> (%s)' % (item['name'], item['type'])) + print('') for item in items: if item['type'].startswith('child<'): list_node((path if (path != '/') else '') + '/' + item['name']) |