[Kimchi-devel] [PATCH] bug fix: Set default flags for virDomain.state() function

Sheldon shaohef at linux.vnet.ibm.com
Fri Mar 7 03:04:18 UTC 2014


Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

have checked.
In [34]: dom.state
Type: instancemethod
String Form:<bound method virDomain.state of <libvirt.virDomain object 
at 0x21c8150>>
File: /usr/lib64/python2.7/site-packages/libvirt.py
Definition: dom.state(self, flags=0)
Docstring: Extract domain state.

yes, It is a very common problem for most of libvirt python API.

I have encountered this a several times.

Is there a good way to avoid this?
Guess no one will test on different distros.
or, the developer should read the libvirt doc carefully.
and we should carefully,
it is better to use libvirt defined flags(such as 
libvirt.VIR_DOMAIN_RUNNING.) if possible




On 03/07/2014 10:47 AM, Aline Manera wrote:
> From: Aline Manera <alinefm at br.ibm.com>
>
> Some libvirt versions do not set the default value for flags, so we need to
> explicity set it.
>
> libvirt.virDomain.state = state(self, flags) unbound libvirt.virDomain method
>
> Otherwise, the following error will be raised
>
> [06/Mar/2014:23:40:05] HTTP Traceback (most recent call last):
>    File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond
>      response.body = self.handler()
>    File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__
>      self.body = self.oldhandler(*args, **kwargs)
>    File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__
>      return self.callable(*self.args, **self.kwargs)
>    File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 71, in wrapper
>      ident = fn(*model_args)
>    File "/home/alinefm/kimchi/src/kimchi/model/networks.py", line 214, in deactivate
>      if self._get_vms_attach_to_a_network(name, "running"):
>    File "/home/alinefm/kimchi/src/kimchi/model/networks.py", line 199, in _get_vms_attach_to_a_network
>      state == dom.state()[0]):
>    File "/home/alinefm/kimchi/src/kimchi/model/libvirtconnection.py", line 62, in wrapper
>      ret = f(*args, **kwargs)
> TypeError: state() takes exactly 2 arguments (1 given)
>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   src/kimchi/model/networks.py |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
> index f032875..0d6ccec 100644
> --- a/src/kimchi/model/networks.py
> +++ b/src/kimchi/model/networks.py
> @@ -196,7 +196,7 @@ class NetworkModel(object):
>           for dom in conn.listAllDomains(0):
>               networks = self._vm_get_networks(dom)
>               if network in networks and (state is None or
> -                                        state == dom.state()[0]):
> +                                        state == dom.state(0)[0]):
>                   vms.append(dom.name())
>           return vms
>


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list