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

From: Aline Manera <alinefm@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@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 -- 1.7.10.4

Reviewed-by: ShaoHe Feng <shaohef@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@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@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@linux.vnet.ibm.com> IBM Linux Technology Center

于 2014/3/7 11:04, Sheldon 写道:
Reviewed-by: ShaoHe Feng <shaohef@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?
One solution would be we can wrap all the buggy methods in dom objects and set the default flags in the methods. See the wrapper code in libvirtconnection.py there and it is easy to tweak the code there to support that.
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@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@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

Reviewed-by: Royce Lv<lvroyce@linux.vnet.ibm.com> On 2014年03月07日 10:47, Aline Manera wrote:
From: Aline Manera <alinefm@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@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
participants (4)
-
Aline Manera
-
Royce Lv
-
Sheldon
-
Shu Ming