Some fixes to qom scripts
cover Some fixes to qom scripts
Hi all.
I found some minor problems with qom scripts.
Martin Cerveny
Martin Cerveny (2):
scripts: qom-*: add network syntax
scripts: qom-tree: add support of path as argument
scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 21 ++++++++++++++++++--- 5 files changed, 63 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.4.1
PATCH 1/2 scripts: qom-*: add network syntax
Add network syntax parsing (ip address, port) to qom-* scripts.
--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)
scripts/qmp/qom-fuse +12 -1
@@ -134,5 +134,16 @@ class QOMFS(Fuse): if __name__ == '__main__': import sys, os - fs = QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET'])) + socket_path = os.environ['QMP_SOCKET'] + connection = socket_path.split(':') + if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) + else: + connection = socket_path + + fs = QOMFS(QEMUMonitorProtocol(connection)) fs.main(sys.argv)
scripts/qmp/qom-get +11 -1
@@ -56,7 +56,17 @@ if len(args) > 0: else: usage_error("not enough arguments") -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() rsp = srv.command('qom-get', path=path, property=prop)
scripts/qmp/qom-list +11 -1
@@ -48,7 +48,17 @@ if not socket_path: else: usage_error("no QMP socket path or address given"); -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() if len(args) == 0:
scripts/qmp/qom-set +11 -1
@@ -58,7 +58,17 @@ if len(args) > 1: else: usage_error("not enough arguments") -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() print srv.command('qom-set', path=path, property=prop, value=sys.argv[2])
scripts/qmp/qom-tree +11 -1
@@ -50,7 +50,17 @@ if not socket_path: else: usage_error("no QMP socket path or address given"); -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() def list_node(path):
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Am 13.05.2015 um 14:14 schrieb Martin Cerveny:
Quoted 10 lines
Add network syntax parsing (ip address, port) to qom-* scripts.
Signed-off-by Martin Cerveny <[email protected]>--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)
Could some Python guru please take a look at this?
Martin, could you clarify what this fixes or adds exactly so that we can extend the commit message accordingly?
Thanks,
Andreas
Quoted 116 lines
scripts/qmp/qom-fuse +12
-1@@ -134,5 +134,16 @@ class QOMFS(Fuse): if __name__ == '__main__': import sys, os - fs = QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET'])) + socket_path = os.environ['QMP_SOCKET'] + connection = socket_path.split(':') + if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) + else: + connection = socket_path + + fs = QOMFS(QEMUMonitorProtocol(connection)) fs.main(sys.argv)scripts/qmp/qom-get +11
-1@@ -56,7 +56,17 @@ if len(args) > 0: else: usage_error("not enough arguments") -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() rsp = srv.command('qom-get', path=path, property=prop)scripts/qmp/qom-list +11
-1@@ -48,7 +48,17 @@ if not socket_path: else: usage_error("no QMP socket path or address given"); -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() if len(args) == 0:scripts/qmp/qom-set +11
-1@@ -58,7 +58,17 @@ if len(args) > 1: else: usage_error("not enough arguments") -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() print srv.command('qom-set', path=path, property=prop, value=sys.argv[2])scripts/qmp/qom-tree +11
-1@@ -50,7 +50,17 @@ if not socket_path: else: usage_error("no QMP socket path or address given"); -srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) +else: + connection = socket_path + +srv = QEMUMonitorProtocol(connection) srv.connect() def list_node(path):
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Quoted 12 lines · Andreas Färber
Am 13.05.2015 um 14:14 schrieb Martin Cerveny:
Quoted 10 lines
Add network syntax parsing (ip address, port) to qom-* scripts.
Signed-off-by Martin Cerveny <[email protected]>--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)
Quoted 1 line
Could some Python guru please take a look at this?
That disqualifies me (still a python newbie), but I still see something questionable:
Quoted 9 lines
scripts/qmp/qom-get if len(args) > 0: · line 65
Quoted 9 lines
scripts/qmp/qom-get +7
-1-srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port )
Won't that mishandle IPv6 connections, such as something like [::1]:8000 for connecting to port 8000 on localhost, since it splits into more than 2 pieces when splitting on :?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Hello.
Quoted 19 lines · Eric Blake
Quoted 12 lines · Andreas Färber
Am 13.05.2015 um 14:14 schrieb Martin Cerveny:
Quoted 10 lines
Add network syntax parsing (ip address, port) to qom-* scripts.
Signed-off-by Martin Cerveny <[email protected]>--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)Quoted 1 line
Could some Python guru please take a look at this?
That disqualifies me (still a python newbie), but I still see something questionable:
Quoted 1 line
Quoted 1 line
Quoted 12 lines
Quoted 8 lines
scripts/qmp/qom-get if len(args) > 0: · line 65
Quoted 8 lines
scripts/qmp/qom-get +7
-1-srv = QEMUMonitorProtocol(socket_path) +connection = socket_path.split(':') +if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port )Won't that mishandle IPv6 connections, such as something like [::1]:8000 for connecting to port 8000 on localhost, since it splits into more than 2 pieces when splitting on :?
Yes, this is problem, but I copy-paste the same construct from scripts/qmp/qmp-shell to be compatible. Is the IPv6 support for utilities mandatory ?
If yes I can make V2.
M.C>
Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Quoted 25 lines · Martin Cerveny
Hello.
Quoted 22 lines · Eric Blake
Quoted 20 lines · Andreas Färber
Am 13.05.2015 um 14:14 schrieb Martin Cerveny:
Quoted 10 lines
Add network syntax parsing (ip address, port) to qom-* scripts.
Signed-off-by Martin Cerveny <[email protected]>--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)Could some Python guru please take a look at this?
Quoted 6 lines
scripts/qmp/qom-fuse +6
-0+if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port )
Quoted 6 lines
Quoted 3 lines
Won't that mishandle IPv6 connections, such as something like [::1]:8000 for connecting to port 8000 on localhost, since it splits into more than 2 pieces when splitting on :?
Yes, this is problem, but I copy-paste the same construct from
scripts/qmp/qmp-shellto be compatible.
Might be worth mentioning that, as justification in the commit message.
Quoted 1 line
Is the IPv6 support for utilities mandatory ?
I don't have any strong feelings about it (I'm okay if you don't). But others might.
Quoted 1 line
If yes I can make V2.
If so, it would be good to fix qmp-shell, too - which makes it sound like it would be a separate commit.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Am 19.05.2015 um 16:17 schrieb Eric Blake:
Quoted 37 lines · Martin Cerveny
Quoted 25 lines
Hello.
Quoted 22 lines · Eric Blake
Quoted 20 lines · Andreas Färber
Am 13.05.2015 um 14:14 schrieb Martin Cerveny:
Quoted 10 lines
Add network syntax parsing (ip address, port) to qom-* scripts.
Signed-off-by Martin Cerveny <[email protected]>--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)Could some Python guru please take a look at this?
Quoted 6 lines
scripts/qmp/qom-fuse +6
-0+if len(connection) == 2: + try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port )Quoted 6 lines
Quoted 3 lines
Won't that mishandle IPv6 connections, such as something like [::1]:8000 for connecting to port 8000 on localhost, since it splits into more than 2 pieces when splitting on :?
Yes, this is problem, but I copy-paste the same construct from
scripts/qmp/qmp-shellto be compatible.Might be worth mentioning that, as justification in the commit message.
Quoted 1 line
Is the IPv6 support for utilities mandatory ?
Quoted 7 lines
I don't have any strong feelings about it (I'm okay if you don't). But others might.
Quoted 1 line
If yes I can make V2.
If so, it would be good to fix qmp-shell, too - which makes it sound like it would be a separate commit.
Is there a chance this can be fixed in a way that we don't need to replicate that code? :)
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
In reply to Martin CervenyQuoted 23 lines · Martin Cerveny
Add network syntax parsing (ip address, port) to qom-* scripts.
Signed-off-by Martin Cerveny <[email protected]>--- scripts/qmp/qom-fuse | 13 ++++++++++++- scripts/qmp/qom-get | 12 +++++++++++- scripts/qmp/qom-list | 12 +++++++++++- scripts/qmp/qom-set | 12 +++++++++++- scripts/qmp/qom-tree | 12 +++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)scripts/qmp/qom-fuse +3
-1@@ -134,5 +134,16 @@ class QOMFS(Fuse): if __name__ == '__main__': import sys, os - fs = QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET'])) + socket_path = os.environ['QMP_SOCKET'] + connection = socket_path.split(':') + if len(connection) == 2:
scripts/qmp/qom-fuse class QOMFS(Fuse): · line 149
Quoted 10 lines
scripts/qmp/qom-fuse +9
-0+ try: + port = int(connection[1]) + except ValueError: + raise QMPBadPort + connection = ( connection[0], port ) + else: + connection = socket_path + + fs = QOMFS(QEMUMonitorProtocol(connection)) fs.main(sys.argv)
Rather than duplicate this code in every single command line tool I think it'd be better to add a static method to QEMUMonitorProtocol eg
@staticmethod
def from_address_string(addr_string):
connection = socket_path.split(':')
if len(connection) == 2:
try:
port = int(connection[1])
except ValueError:
raise QMPBadPort
connection = ( connection[0], port )
else:
connection = addr_string
return QEMUMonitorProtocol(connection)
Then each script can just do
srv = QEMUMonitorProtocol.from_address_string(
os.environ['QMP_SOCKET'])
Really the from_address_string should check for None eg
if addr_string is None:
print >>sys.stderr "Address string is required" sys.exit(1)
And as Eric says, splitting on ':' doesn't work with IPv6
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
PATCH 2/2 scripts: qom-tree: add support of path as argument
In reply to Martin CervenyAdd processing of optional argument path as "tree base".
--- scripts/qmp/qom-tree | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
scripts/qmp/qom-tree +7 -2
@@ -75,6 +75,11 @@ def list_node(path): print '' for item in items: if item['type'].startswith('child<'): - list_node(path + '/' + item['name']) + list_node((path if (path != '/') else '') + '/' + item['name']) -list_node('/machine') +if len(args) == 0: + path = '/' +else: + path = args[0] + +list_node(path)
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 2/2] scripts: qom-tree: add support of path as argument
scripts/qmp/qom-tree def list_node(path): · line 78
Quoted 4 lines · Martin Cerveny
for item in items:
if item['type'].startswith('child<'):scripts/qmp/qom-tree +1
-1- list_node(path + '/' + item['name']) + list_node((path if (path != '/') else '') + '/' + item['name'])
I'm not sure which Python version introduced if...else. The more traditional idiom would be
path != '/' and path or ''
Can you use it, and move the expression out of the 'for item in items' loop into a variable?
Paolo
Re: [Qemu-devel] [PATCH 2/2] scripts: qom-tree: add support of path as argument
Hello.
Ternary/if/else >= python 2.5 (I use the same coding as in scripts/qmp/qemu-ga-client). "import json" >= python 2.6 (scripts/qmp/qmp.py)
"import argparse" >= python 2.7 (scripts/analyze-migration.py, scripts/vmstate-static-checker.py) "import optparse" < python 2.7 (deprecated, scripts/qmp/qemu-ga-client)
....
Of course there is no problem to use traditional syntax.
(My platform (centos5.10) has python2.4, I must also replace json imports:
try:
import json
except ImportError:
import simplejson as json
)
Which version of python is officialy minimum supported ?
Thanks for explanation of python status.
M.C>
Quoted 18 lines · Paolo Bonzini
scripts/qmp/qom-tree def list_node(path): · line 78
Quoted 4 lines · Martin Cerveny
for item in items:
if item['type'].startswith('child<'):scripts/qmp/qom-tree +1
-1- list_node(path + '/' + item['name']) + list_node((path if (path != '/') else '') + '/' + item['name'])I'm not sure which Python version introduced if...else. The more traditional idiom would be
path != '/' and path or ''Can you use it, and move the expression out of the 'for item in items' loop into a variable?
Paolo
Re: [Qemu-devel] [PATCH 2/2] scripts: qom-tree: add support of path as argument
Quoted 4 lines · Martin Cerveny
Hello.
Ternary/if/else >= python 2.5 (I use the same coding as in
scripts/qmp/qemu-ga-client).
Oh, that's old. Shows my knowledge of Python.
Then your patch is okay---thanks for enduring with me. :)
Paolo
Quoted 19 lines
"import json" >= python 2.6 (
scripts/qmp/qmp.py)
"import argparse" >= python 2.7 (scripts/analyze-migration.py,scripts/vmstate-static-checker.py)
"import optparse" < python 2.7 (deprecated,scripts/qmp/qemu-ga-client)
....Of course there is no problem to use traditional syntax.
(My platform (centos5.10) has python2.4, I must also replace json imports:
try:
import json
except ImportError:
import simplejson as json
)Which version of python is officialy minimum supported ?
Thanks for explanation of python status.
M.C>
Andreas Färber
AppliedRe: [Qemu-devel] [PATCH 2/2] scripts: qom-tree: add support of path as argument
Am 14.05.2015 um 13:47 schrieb Paolo Bonzini:
Quoted 9 lines · Martin Cerveny
Quoted 4 lines
Hello.
Ternary/if/else >= python 2.5 (I use the same coding as in
scripts/qmp/qemu-ga-client).Oh, that's old. Shows my knowledge of Python.
Then your patch is okay---thanks for enduring with me. :)
Thanks, applied to qom-next then:
https://github.com/afaerber/qemu-cpu/commits/qom-next
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)