All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Martin Cerveny <M.Cerveny@computer.org>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Date: Tue, 19 May 2015 15:16:51 +0100	[thread overview]
Message-ID: <20150519141651.GA8535@redhat.com> (raw)
In-Reply-To: <1431519294-8873-2-git-send-email-M.Cerveny@computer.org>

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 <M.Cerveny@computer.org>
> ---
>  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 :|


WARNING: multiple messages have this Message-ID (diff)
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Martin Cerveny <M.Cerveny@computer.org>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] scripts: qom-*: add network syntax
Date: Tue, 19 May 2015 15:16:51 +0100	[thread overview]
Message-ID: <20150519141651.GA8535@redhat.com> (raw)
In-Reply-To: <1431519294-8873-2-git-send-email-M.Cerveny@computer.org>

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 <M.Cerveny@computer.org>
> ---
>  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 :|

  parent reply	other threads:[~2015-05-19 14:17 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13 12:14 [Qemu-trivial] [PATCH 0/2] Some fixes to qom scripts Martin Cerveny
2015-05-13 12:14 ` [Qemu-devel] " Martin Cerveny
2015-05-13 12:14 ` [Qemu-trivial] [PATCH 1/2] scripts: qom-*: add network syntax Martin Cerveny
2015-05-13 12:14   ` [Qemu-devel] " Martin Cerveny
2015-05-19 12:51   ` [Qemu-trivial] " Andreas Färber
2015-05-19 12:51     ` Andreas Färber
2015-05-19 13:56     ` [Qemu-trivial] " Eric Blake
2015-05-19 13:56       ` Eric Blake
2015-05-19 14:12       ` [Qemu-trivial] " Martin Cerveny
2015-05-19 14:12         ` Martin Cerveny
2015-05-19 14:17         ` [Qemu-trivial] " Eric Blake
2015-05-19 14:17           ` Eric Blake
2015-05-19 14:23           ` [Qemu-trivial] " Andreas Färber
2015-05-19 14:23             ` Andreas Färber
2015-05-19 14:16   ` Daniel P. Berrange [this message]
2015-05-19 14:16     ` Daniel P. Berrange
2015-05-13 12:14 ` [Qemu-trivial] [PATCH 2/2] scripts: qom-tree: add support of path as argument Martin Cerveny
2015-05-13 12:14   ` [Qemu-devel] " Martin Cerveny
2015-05-14 10:00   ` [Qemu-trivial] " Paolo Bonzini
2015-05-14 10:00     ` [Qemu-devel] " Paolo Bonzini
2015-05-14 11:41     ` [Qemu-trivial] " Martin Cerveny
2015-05-14 11:41       ` [Qemu-devel] " Martin Cerveny
2015-05-14 11:47       ` [Qemu-trivial] " Paolo Bonzini
2015-05-14 11:47         ` [Qemu-devel] " Paolo Bonzini
2015-05-19 12:47         ` [Qemu-trivial] " Andreas Färber
2015-05-19 12:47           ` Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150519141651.GA8535@redhat.com \
    --to=berrange@redhat.com \
    --cc=M.Cerveny@computer.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.