qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax


From: Daniel P. Berrange
Subject: Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Date: Tue, 19 May 2015 15:16:51 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

On Wed, May 13, 2015 at 02:14:53PM +0200, Martin Cerveny wrote:
> Add network syntax parsing (ip address, port) to qom-* scripts.
> 
> Signed-off-by: Martin Cerveny <address@hidden>
> ---
>  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(-)
> 
> diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse
> index 5c6754a..d49f36d 100755
> --- a/scripts/qmp/qom-fuse
> +++ b/scripts/qmp/qom-fuse
> @@ -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)

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
-- 
|: 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 :|



reply via email to

[Prev in Thread] Current Thread [Next in Thread]