Pure Python binding?

2023-09-05 Thread Philipp Hahn

Hello,

"pip install libvirt-python" does not work in several cases as that 
requires the low-level C library, compilers, tools, and Python header 
files to be installed. This prevents the use of "libvirt" in scenarios, 
where "root" privileges are not available to install these dependencies, 
e.g. running "libvirt" inside a JupyterHub notebook for gathering 
statistics. This also breaks the adoption on Windows, see 
<https://gitlab.com/libvirt/libvirt-python/-/issues/7> and 
<https://gitlab.com/libvirt/libvirt-python/-/issues/6>


Looking at <https://libvirt.org/bindings.html> and 
<https://gitlab.com/libvirt> I only see "bindings" for the low-level C 
library.


Does someone know of a "pure Python binding" for talking to a remote 
"libvirtd", either via "+ssh" or "+tls"?


Or is there another "trick" to talk to libvirtd? And no, parsing the 
output of subprocess.run("ssh ... virsh ...") is not an option ;-)


Philipp
--
Philipp Hahn
Open Source Software Engineer

Univention GmbH
Mary-Somerville-Str. 1
28359 Bremen
Germany | Deutschland
Phone: +49 (0)421 22232-0 | E-Mail: i...@univention.de

https://www.univention.de | https://www.univention.com

Managing Directors: Peter H. Ganten, Stefan Gohmann
Local court: Amtsgericht Bremen
HRB 20755 | Ust-ID: DE220051310



[python-libvirt] RFC:PEP 484 type annotation - how to continue

2020-10-05 Thread Philipp Hahn
Hello,

currently my Merge Quests
<https://gitlab.com/libvirt/libvirt-python/-/merge_requests/9> is stuck
because there are some open technical discussions:

1. The Python binding consists of two layers:
   - libvirtmod* is the low-level C-like API, which mostly is just a
thin wrapper around the C-library. It is generated from the API.xml files
  - The high-level libvirt* modules, providing an object oriented API,
which is also generated from the API.xml files.
  In both cases there are many exceptions defines via
libvirt*-override-api.xml or coded in generator.py:
  - skip_impl: Generate Python code, but skip C implementation
  - custom_function: Generate neither C nor Python code - hand crafted code
  - skip_function: Generate neither C nor Python code - not used at all
  - function_skip_python_impl: Generate C code, but skip python impl

Previously the functions listed in "skip_impl" were also duplicated in
the "libvirt-*override-api.xml" files, which is somehow hard to
maintain. With d19699e48ce9c17481f94b4dc0715e18e05d5adb I removed all
those names from "skip_impl", which are also listed in the overrides and
added code to add them back when "generator.py" is invoked.
For this to work I had to change several "files" attributes to start
with "python", which looks okay to me, but still would like to get verified.

2. The low-level library works mostly with bytes, but the high-level
Python API uses nested Lists, Tuples and Dicts. To get most out of the
Python static type annotations the input and output parameters should be
modled in as much detail as possible.
This requires to store those types somewhere. My current
46592e28124858ed863bceba65c3dafa2bbb02cd adds some often used types to
generator.py and then references them from the overrides.xml:

> +'PyListSecret': ('', 'List["virSecret"]', '', ''),
> +'PyDictAny': ('', 'Dict[str, Any]', '', ''),

> +  

This still is very painful as there are many "used-once" types, which
still must be declared and used in two places.
So far the "return" type was used for the "C" type and currently I
mis-use it for referencing it for my Python types. This doesn't look
right, so I would prefer adding a new attribute which can be used to
override the Python type.
This also would probably nicely fit with functions like
"virDomainOpenConsole", when "dev_name" is optional and can be "None",
which the current type hint requires a "string".

Is extending the libvirt*-override-api.xml files okay or must this be
coordinated with the other parts of the project?


Thank you for your time
Philipp Hahn
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen

 +49-421-22232-57
 +49-421-22232-99

✉️ h...@univention.de
 https://www.univention.de/

Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876




Re: Please revert f4be03b3 (libvirtaio: Drop object(*args, **kwargs)) for theoretical reasons

2020-08-28 Thread Philipp Hahn
Hello,

Am 20.08.20 um 11:20 schrieb Daniel P. Berrangé:
> On Wed, Aug 19, 2020 at 11:32:10PM +0200, Wojtek Porczyk wrote:
>> Hi Philipp,
>> (Cc: Daniel, because IIUC you reviewed !16 which got this merged),
>>
>> I'm sorry I didn't notice this earlier, but the commit f4be03b3 dated
>> 2020-04-20 [0] is wrong. The super().__init__(*args, **kwargs) in
>> Callback.__init__ was there on purpose, because of how Python's inheritance 
>> in
>> new-style classes works.
>>
>> Let me explain this a bit, because it is not obvious.
...
Thank you for that excellent explanation - I learned something new.
Sorry for the noise.

>> I don't think this breaks anything (I very much doubt anyone would need to
>> write code that would trigger this), nevertheless, as the commit is both
>> pointless and wrong, and as the original author of libvirtaio I'd like to ask
>> for this commit to be reverted. If this breaks some static analysis tool,
>> could you just suppress it for this particular line?

I've reverted my change and instead added a `  # type: ignore` comment
to silence mypy.

> Could you open a merge request providing the revert along with your
> description of why the change was wrong and I'll review & approve it.

Done: 

Sorry for the delay, but I was on vaccation and my first week back at
work was quiet busy. Have a nice weekend.

Philipp

PS: I will continue with the next chunk of changed for type annotations
when !19 is merged.




libvirt-python: Extending libvirt-*override-api.xml?

2020-07-27 Thread Philipp Hahn
Hello,

Am 25.07.20 um 23:45 schrieb Philipp Hahn:
> Am 27.04.20 um 15:44 schrieb Philipp Hahn:
>> I'm working on adding PEP 484 type hints
>> <https://www.python.org/dev/peps/pep-0484/> to the Python binding of
>> libvirt.
...
> I just opened a merge request
> <https://gitlab.com/libvirt/libvirt-python/-/merge_requests/9> for my
> code at <https://gitlab.com/pmhahn/libvirt-python/-/tree/typing>.

While working on that I stumbled over two issues:

1. generator.skip_impl contained a list of the function names, which
were also defined in `libvirt-override-api.xml`. Adding an override
requires adding it in *two* locations.
With
<https://gitlab.com/libvirt/libvirt-python/-/merge_requests/9/diffs?commit_id=96e7414e488af84f7be04a50f5cd7457142c898d>
it took the liberty to remove the list from generator.py and to extends
it by parsing "api.xml" where file="python*".

2. Historically "api*.xml" used "char *" to indicate some custom Python
type. Mapping this to "str" is obviously wrong, so I had to review them
and changed many of them to "Any" or more specific types with
<https://gitlab.com/libvirt/libvirt-python/-/merge_requests/9/diffs?commit_id=c3b26fccfc5e4e23ad93db51a41a85275f0ea5b5>.
As that information is both used to generate the low-level "C-to-Python"
mapping for "libvirtmod" but also the high-level Python module
"libvirt", changing `type` to something other then a C-type might breaks
the C-level wrapper.
Using a Python-type there which must be declared in "generator.py" is
also somehow cumbersome as there are many types which are used only once.
So I would like to extend this file with a new attribute like "pytype",
which then can be used to overwrite the type used by generator.py.

> 
>   Extract information about virtual CPUs of domain, store it in info 
> array and also in cpumaps.
>   
>   
>   
> 

Is that okay?

Philipp




libvirt-python: API change List → (Named)Tuple?

2020-07-27 Thread Philipp Hahn
Hello,

Am 25.07.20 um 23:45 schrieb Philipp Hahn:
> Am 27.04.20 um 15:44 schrieb Philipp Hahn:
>> I'm working on adding PEP 484 type hints
>> <https://www.python.org/dev/peps/pep-0484/> to the Python binding of
>> libvirt.
...
> I just opened a merge request
> <https://gitlab.com/libvirt/libvirt-python/-/merge_requests/9> for my
> code at <https://gitlab.com/pmhahn/libvirt-python/-/tree/typing>.

While working on that I stumbled over some annoyances in the current
Python API: There are many methods which return a List[int], for example:
  virDomainGetInfo
  virDomainGetState
  virDomainGetControlInfo
  virDomainGetBlockInfo
  virDomainGetJobInfo
  virStoragePoolGetInfo
  virStorageVolGetInfo
  virStorageVolGetInfoFlags

There are more function returning similar information as plain List:
  virNodeGetSecurityModel
  virNodeGetSecurityModel
  virDomainGetSecurityLabelList
  virDomainBlockStats
  virDomainInterfaceStats
  virDomainGetVcpus
  virNodeGetCPUMap

The worst offender is `virNodeGetInfo`, which returns `Tuple[str,
int*7]`: The problem for type annotation is that `List` is unlimited in
the number of elements, that is you cannot specify the number of entries
the list must or will contain.
Also all elements of a list must have the same (super-)type; for "str"
and "int" of "virNodeGetInfo()" that would be "Any", which is not very
useful here.

A better type for those `List`s would be `Tuple`, which has a fixed
length and can have different types for each position.

But that would be an API change: In most cases users of those functions
should not notice the difference as indexing tuples or lists is the same.
It would break code where someone would do something like this:
  ret = virFunction_returning_list()
  ret += [1, 2, 3]
which breaks if that function would return a `Tuple` in the future:

> $ python -c '() + []'
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: can only concatenate tuple (not "list") to tuple

Even better then plain `Tuple`s would be
<https://docs.python.org/3/library/collections.html#collections.namedtuple>,
which would allow us to use the return value of `virNodeGetInfo()` as this:

> from collections import namedtuple
> import  libvirt
> virNodeInfo = namedtuple("virNodeInfo", ["model", "memory", "cpus", "mhz", 
> "nodes", "sockets", "cores", "threads"])
> c = libvirt.open('test:///default')
> info = virNodeInfo(*c.getInfo())
> print(info.model)
> print(info)
> # virNodeInfo(model='i686', memory=3072, cpus=16, mhz=1400, nodes=2, 
> sockets=2, cores=2, threads=2)

<https://libvirt.org/html/libvirt-libvirt-host.html#virNodeInfo>

This could be improved even more by using
<https://mypy.readthedocs.io/en/stable/kinds_of_types.html?highlight=NamedTuple#named-tuples>,
which allows to add type information:

> from typing import NamedTuple
> virNodeInfo = NamedTuple("virNodeInfo", [("model", str), ("memory", int), 
> ("cpus", int), ("mhz", int), ("nodes", int), ("sockets", int), ("cores", 
> int), ("threads", int)])

or with Python 3.6 the more readable form

> class virNodeInfo(NamedTuple):
>   model: str
>   memory: int
>   cpus: int
>   mhz: int
>   nodes: int
>   sockets: int
>   cores: int
>   threads: int

IMHO that would be a real usability improvement as I have to lookup that
information every time I have to use those functions myself.
Indexing with `namedtuple` and `NamedTuple` still works, so you can
still use `info[0]` above to get the model.

What do you think of that?
When would be a good time to make such a change?

Philipp




Re: [PATCH libvirt-python 0/5] Fixes from adding type annotation

2020-07-25 Thread Philipp Hahn
Hello,

Am 27.04.20 um 15:44 schrieb Philipp Hahn:
> as announced a long time ago with
> <https://www.redhat.com/archives/libvir-list/2018-November/msg00291.html>
> and recently refreshed with
> <https://www.redhat.com/archives/libvir-list/2020-April/msg00892.html>
> I'm working on adding PEP 484 type hints
> <https://www.python.org/dev/peps/pep-0484/> to the Python binding of
> libvirt.
> 
> I have finished this work now and have a working version at
> <https://github.com/univention/libvirt-python/tree/typing> which
> consists of 90 patches in total as I has to go over evry file to
> understand and fix all things.

I just opened a merge request
<https://gitlab.com/libvirt/libvirt-python/-/merge_requests/9> for my
code at <https://gitlab.com/pmhahn/libvirt-python/-/tree/typing>.

This also unearthed severl bugs where C-pointer point to the wrong
types, which lead to strange crashes. The fixes for them are at the
start of my current branch, except
<https://gitlab.com/pmhahn/libvirt-python/-/commit/9fdf8e9ece4b6695bcddaeb2f998bc11f57e2735>
which is more tricky.

If you want to fast-pache them I can try to extract those patches into a
separate branch, which can be merged without my other work.

Philipp



[PATCH libvirt-python 5/5] libvirtaio: Fix return types of callback

2020-04-27 Thread Philipp Hahn
libvirt defines the signature for the callback functions, e.g. the
functions for remove() must return -1 on error and 0 on success. Raising
an exception violates that contract.

_remove_timeout() did not explicitly handle a double-remove and
implicitly passed on the exception.

update() expects no return value, so remove the pointless return to pass
on None.

Signed-off-by: Philipp Hahn 
---
 libvirtaio.py | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libvirtaio.py b/libvirtaio.py
index 328e6f2..f1811c1 100644
--- a/libvirtaio.py
+++ b/libvirtaio.py
@@ -370,13 +370,13 @@ class virEventAsyncIOImpl(object):
 
https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateHandleFunc
 '''
 self.log.debug('update_handle(watch=%d, event=%d)', watch, event)
-return self.callbacks[watch].update(event=event)
+self.callbacks[watch].update(event=event)
 
 def _remove_handle(self, watch):
 '''Unregister a callback from a file handle.
 
 :param int watch: file descriptor watch to stop listening on
-:returns: None (see source for explanation)
+:returns: -1 on error, 0 on success
 
 .. seealso::
 
https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveHandleFunc
@@ -386,12 +386,13 @@ class virEventAsyncIOImpl(object):
 callback = self.callbacks.pop(watch)
 except KeyError as err:
 self.log.warning('remove_handle(): no such handle: %r', 
err.args[0])
-raise
+return -1
 fd = callback.descriptor.fd
 assert callback is self.descriptors[fd].remove_handle(watch)
 if len(self.descriptors[fd].callbacks) == 0:
 del self.descriptors[fd]
 callback.close()
+return 0
 
 def _add_timeout(self, timeout, cb, opaque):
 '''Register a callback for a timer event
@@ -425,20 +426,25 @@ class virEventAsyncIOImpl(object):
 
https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateTimeoutFunc
 '''
 self.log.debug('update_timeout(timer=%d, timeout=%d)', timer, timeout)
-return self.callbacks[timer].update(timeout=timeout)
+self.callbacks[timer].update(timeout=timeout)
 
 def _remove_timeout(self, timer):
 '''Unregister a callback for a timer
 
 :param int timer: the timer to remove
-:returns: None (see source for explanation)
+:returns: -1 on error, 0 on success
 
 .. seealso::
 
https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeoutFunc
 '''
 self.log.debug('remove_timeout(timer=%d)', timer)
-callback = self.callbacks.pop(timer)
+try:
+callback = self.callbacks.pop(timer)
+except KeyError as err:
+self.log.warning('remove_timeout(): no such timeout: %r', 
err.args[0])
+return -1
 callback.close()
+return 0
 
 
 _current_impl = None
-- 
2.20.1




[PATCH libvirt-python 1/5] generator: Fix undefined variables file

2020-04-27 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 generator.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/generator.py b/generator.py
index 426f007..7f4ae1f 100755
--- a/generator.py
+++ b/generator.py
@@ -928,7 +928,7 @@ def buildStubs(module, api_xml):
 parser.close()
 except IOError:
 msg = sys.exc_info()[1]
-print(file, ":", msg)
+print(api_xml, ":", msg)
 sys.exit(1)
 
 n = len(list(funcs.keys()))
@@ -948,7 +948,7 @@ def buildStubs(module, api_xml):
 parser.close()
 except IOError:
 msg = sys.exc_info()[1]
-print(file, ":", msg)
+print(override_api_xml, ":", msg)
 
 if not quiet:
 # XXX: This is not right, same function already in @functions
-- 
2.20.1




[PATCH libvirt-python 2/5] generator: Fix string formatting

2020-04-27 Thread Philipp Hahn
remove excessive arguments.

Signed-off-by: Philipp Hahn 
---
 generator.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/generator.py b/generator.py
index 7f4ae1f..a14 100755
--- a/generator.py
+++ b/generator.py
@@ -766,7 +766,7 @@ def print_function_wrapper(module, name, output, export, 
include):
 if file == "python_accessor":
 if args[1][1] == "char *":
 c_call = "\nVIR_FREE(%s->%s);\n" % (
- args[0][0], args[1][0], args[0][0], 
args[1][0])
+ args[0][0], args[1][0])
 c_call = c_call + "%s->%s = (%s)strdup((const xmlChar 
*)%s);\n" % (args[0][0],
  args[1][0], args[1][1], args[1][0])
 else:
-- 
2.20.1




[PATCH libvirt-python 3/5] generator: Fix domainSnapshot.listAllChildren()

2020-04-27 Thread Philipp Hahn
virDomainSnapshot(dom, _obj)
expects a reference to the virDomain as its first argument, but
virDomainSnapshot.listAllChildren()
passes `self` instead:

libvirt.py:6459: error: Argument 1 to "virDomainSnapshot" has incompatible type 
"virDomainSnapshot"; expected "virDomain"

>>> import libvirt
>>> con = libvirt.open('test:///default')
>>> dom = con.lookupByName("test")
>>> first = 
>>> dom.snapshotCreateXML("""First""")
>>> second = 
>>> dom.snapshotCreateXML("""Second""")
>>> child, == first.listAllChildren()
>>> second.domain()

 ^
>>> child.domain()

 ^

Signed-off-by: Philipp Hahn 
---
 libvirt-override-virDomainSnapshot.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt-override-virDomainSnapshot.py 
b/libvirt-override-virDomainSnapshot.py
index ec53358..87eac86 100644
--- a/libvirt-override-virDomainSnapshot.py
+++ b/libvirt-override-virDomainSnapshot.py
@@ -14,6 +14,6 @@
 
 retlist = list()
 for snapptr in ret:
-retlist.append(virDomainSnapshot(self, _obj=snapptr))
+retlist.append(virDomainSnapshot(self.domain(), _obj=snapptr))
 
 return retlist
-- 
2.20.1




[PATCH libvirt-python 4/5] qemu-api: Fix return type

2020-04-27 Thread Philipp Hahn
The API XML description uses "C types": "str *" is not valid.

Signed-off-by: Philipp Hahn 
---
 libvirt-qemu-override-api.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libvirt-qemu-override-api.xml b/libvirt-qemu-override-api.xml
index ca0dae9..b280a88 100644
--- a/libvirt-qemu-override-api.xml
+++ b/libvirt-qemu-override-api.xml
@@ -3,14 +3,14 @@
   
   
 Send an arbitrary monitor command through qemu monitor of 
domain
-
+
 
 
 
   
   
 Send a Guest Agent command to domain
-
+
 
 
 
-- 
2.20.1




[PATCH libvirt-python 0/5] Fixes from adding type annotation

2020-04-27 Thread Philipp Hahn
Hello,

as announced a long time ago with
<https://www.redhat.com/archives/libvir-list/2018-November/msg00291.html>
and recently refreshed with
<https://www.redhat.com/archives/libvir-list/2020-April/msg00892.html>
I'm working on adding PEP 484 type hints
<https://www.python.org/dev/peps/pep-0484/> to the Python binding of
libvirt.

I have finished this work now and have a working version at
<https://github.com/univention/libvirt-python/tree/typing> which
consists of 90 patches in total as I has to go over evry file to
understand and fix all things.

As that patch bomb is quiet large I'm going to submit them in smaller
chunks to make them more reviewable. Today I start with the first round
consisting of "real" bugs in the current code:

Philipp Hahn (5):
  generator: Fix undefined variables file
  generator: Fix string formatting
  generator: Fix domainSnapshot.listAllChildren()
  qemu-api: Fix return type
  libvirtaio: Fix return types of callback


 generator.py  |  6 +++---
 libvirt-override-virDomainSnapshot.py |  2 +-
 libvirt-qemu-override-api.xml |  4 ++--
 libvirtaio.py | 18 --
 4 files changed, 18 insertions(+), 12 deletions(-)


After that I plan to continue with:

2. fix examples/ to work with Python 3
3. Cleanup code tree-wide
4. Cleanup generator.py
5. Cleanup sanitytest.py
6. Teach generator.py to add PEP 484 annotation
7. Assorted cleanups

(the order and chunking is not final yet)

> examples/domipaddrs: Convert to python 3 print()
> examples/domipaddrs: Fix Python 2 dict.iteritems()
> examples/*: Remove stray semicolon
> example/dhcp*: Fix None comparison
> examples/event-test: Remove unneeded global statement
> examples/event-test: Work with old version of python-libvirt
> examples/event-test: Use atexit for Python 3
> examples/esxlist: Fix Python 2 raw_input()
> examples/consolecallback: Add var to save callback
> examples/consolecallback: Fix assorted errors
> examples: Add missing return values

> libvirtaio: Drop object(*args, **kwargs)
> libvirtaio: Fix return type
> libvirtaio: assert callback type

> Do not use bare except
> Cleanup imports
> Fix white space
> Remove legacy libvirtError arguments

> stream: Fix exception traceback handling
> override: Simplify exception handling
> generator: Simplify exception handling
> generator: Change type of quiet to bool
> generator: Remove unneeded line continuation
> generator: Convert to 'not in' and 'is not'
> generator: Remove dead variable assignments
> generator: Remove skipped_modules
> generator: Remove useless sort key
> generator: Fix return type on failure
> generator: Merge now identical if-elif-else cases
> generator: Use more string formatting
> generator: Simplify string concatentaion
> generator: Use enumerate()
> generator: Use increment assignment
> generator: Use string concatenation
> generator: Remove global declarations
> generator: Initialize function_classes directly
> generator: Check contained in hash
> generator: Use dict.item() to walk keys and values
> generator: Walk only the values
> generator: Directly get dict length
> generator: Just walk the dict
> generator: Use splitlines()
> generator: Open file with context manager
> generator: Refactor parser creation
> generator: Remove unused SAX content handler methods
> generator: Use SAX method names
> generator: Use string formatting
> generator: Convert in_function to boolean
> generator: Simplify XML attribute fetching
> generator: Initialize with empty strings
> generator: Expand tuple to names in for loop
> generator: Store arguments and return as tuple
> generator: Fixed writing cached=None
> generator: Simplify sorting
> generator: Simplify loop break
> generator: Simplify boolean condition
> generator: Convert dict() to set()
> generator: Converto to defaultdict()
> generator: Add PEP 484 type annotations
> override: Add manual PEP 484 type annotations
> sanitytest: Skip type annotations
> stream: Simplify boolean condition
> domain: Fix None comparison
> stream: no type change
> stream: Convert type() to isinstance()
> stream: Return None from callback
> connect: Just clear all event handlers
> override: no type change
> sanitytest: Do not re-declare set
> sanitytest: Drop else:pass
> sanitytest: Drop Python 2 compatibility
> sanitytest: Add PEP 484 type annotations
> sanitytest: Use 3-tuple for basicklassmap
> sanitytest: Use 3-tuple for finalklassmap
> sanitytest: Use set for tracking used functions
> sanitytest: Use str.startswith() instead of str[0]
> generator: Generate PEP 484 type annotation
> override: Catch type error
> generator: Special handling for virStoragePool.listAllVolumes
> generator: Merge code

[PATCH libvirt-python] examples: Fix connection error handling 2

2020-04-27 Thread Philipp Hahn
Fix two more cases in examples as
libvirt.open*() does not return None but raises an exception

Fixes: 283e2bc693746164b6e14d6fe3ccd38a07bf
Signed-off-by: Philipp Hahn 
---
 examples/dhcpleases.py | 5 +++--
 examples/domipaddrs.py | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/examples/dhcpleases.py b/examples/dhcpleases.py
index f394541..6f80fd5 100755
--- a/examples/dhcpleases.py
+++ b/examples/dhcpleases.py
@@ -22,8 +22,9 @@ else:
 usage()
 sys.exit(2)
 
-conn = libvirt.open(uri)
-if conn == None:
+try:
+conn = libvirt.open(uri)
+except libvirt.libvirtError:
 print("Unable to open connection to libvirt")
 sys.exit(1)
 
diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py
index bda308c..e893995 100755
--- a/examples/domipaddrs.py
+++ b/examples/domipaddrs.py
@@ -21,8 +21,9 @@ else:
 usage()
 sys.exit(2)
 
-conn = libvirt.open(uri)
-if conn == None:
+try:
+conn = libvirt.open(uri)
+except libvirt.libvirtError:
 print "Unable to open connection to libvirt"
 sys.exit(1)
 
-- 
2.20.1




Re: [libvirt-python PATCH v2] setup: require python >= 3.5 to build

2020-04-21 Thread Philipp Hahn
Am 20.04.20 um 15:57 schrieb Daniel P. Berrangé:
> Pytjon 3.5 is the oldest Python version available across our supported
> build platforms.
> 
> Signed-off-by: Daniel P. Berrangé 

Reviewed-by: Philipp Hahn 

> ---
>  setup.py | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/setup.py b/setup.py
> index 56b6eea..39a07de 100755
> --- a/setup.py
> +++ b/setup.py
> @@ -17,8 +17,8 @@ import re
>  import shutil
>  import time
>  
> -if sys.version_info[0] != 3:
> -print("libvirt-python requires Python 3.x to build")
> +if sys.version_info < (3, 5):
> +print("libvirt-python requires Python >= 3.5 to build")
>  sys.exit(1)
>  
>  MIN_LIBVIRT = "0.9.11"
> @@ -368,5 +368,9 @@ of recent versions of Linux (and other OSes).''',
>"License :: OSI Approved :: GNU Lesser General Public License v2 
> or later (LGPLv2+)",
>"Programming Language :: Python",
>"Programming Language :: Python :: 3",
> +  "Programming Language :: Python :: 3.5",
> +  "Programming Language :: Python :: 3.6",
> +  "Programming Language :: Python :: 3.7",
> +  "Programming Language :: Python :: 3.8",
>]
>  )
> 




Re: [libvirt-python PATCH] setup: require python >= 3.5 to build

2020-04-20 Thread Philipp Hahn
Hello Daniel,

Am 20.04.20 um 15:02 schrieb Daniel P. Berrangé:
> On Mon, Apr 20, 2020 at 02:59:38PM +0200, Philipp Hahn wrote:
>> Am 20.04.20 um 14:47 schrieb Daniel P. Berrangé:
>>> Pytjon 3.5 is the oldest Python version available across our supported
...
>>> -if sys.version_info[0] != 3:
>>> -print("libvirt-python requires Python 3.x to build")
>>> +if sys.version_info[0] != 3 or sys.version_info[1] < 5:
>>
>> if sys.version_info < (3, 5):
> 
> IIUC, that would not reject  Python 4.x, which I presume would be
> a backwards incompatible version bump. 

Yes, that would not reject 4. But lets wait until Python 4 is started to
decide if we then want to disable libvirt for it - assume the best and
hope it will be (mostly) backward compatible. (many Python 2 program
even work with Python 3 and having to change each of them just to
while-list the version bump would be a pain.)

That would be the "Pythonic" way of doing things.

>> plus maybe this:
>>
>>> diff --git a/setup.py b/setup.py
>>> index 56b6eea..e20b7b3 100755
>>> --- a/setup.py
>>> +++ b/setup.py
>>> @@ -368,5 +368,9 @@ of recent versions of Linux (and other OSes).''',
>>>"License :: OSI Approved :: GNU Lesser General Public License v2 
>>> or later (LGPLv2+)",
>>>"Programming Language :: Python",
>>>"Programming Language :: Python :: 3",
>>> +  "Programming Language :: Python :: 3.5",
>>> +  "Programming Language :: Python :: 3.6",
>>> +  "Programming Language :: Python :: 3.7",
>>> +  "Programming Language :: Python :: 3.8",
> 
> Are these used for any functional purpose, or just really a documentation
> thing ?  This does introduce the issue of someone having to remember to
> add  3.9, 3.10, etc as they arrive. I'm confident we'll forget that.

Those are the "Trove clasifiers" <https://pypi.org/classifiers/>, which
are for example displayed on PyPi
<https://pypi.org/project/libvirt-python/>. It helps to know that
someone tested it with those versions.

As there is not "does not work with 3.4 or older" I chose to explicitly
list the versions which we support currently (contradicting my words above).

Philipp




[PATCH v2] doc/python: Update to Python 3

2020-04-20 Thread Philipp Hahn
Convert the simple example to Python 3 syntax:
- print() is a function
- do not use bare except
- libvirt.open*() does not return None but raises an exception

The referenced source for the example was removed with
5bb2a245abbde4c0a407f631660e2f2c81bc4c02

Signed-off-by: Philipp Hahn 
---
 docs/python.html.in | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/docs/python.html.in b/docs/python.html.in
index e6e8cfade9..0f804da8c3 100644
--- a/docs/python.html.in
+++ b/docs/python.html.in
@@ -38,24 +38,24 @@ specificities in their argument conversions:
 is replaced by virDomain::info() which returns a list of
 state: one of the state values (virDomainState)maxMemory: 
the maximum memory used by the domainmemory: the current amount of 
memory used by the domainnbVirtCPU: the number of virtual 
CPUcpuTime: the time used by the domain in nanoseconds
 
-So let's look at a simple example inspired from the 
basic.py
-test found in python/tests/ in the source tree:
+So let's look at a simple example:
 import libvirt
 import sys
 
-conn = libvirt.openReadOnly(None)
-if conn == None:
-print 'Failed to open connection to the hypervisor'
+try:
+conn = libvirt.openReadOnly(None)
+except libvirt.libvirtError:
+print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
 try:
 dom0 = conn.lookupByName("Domain-0")
-except:
-print 'Failed to find the main domain'
+except libvirt.libvirtError:
+print('Failed to find the main domain')
 sys.exit(1)
 
-print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())
-print dom0.info()
+print("Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType()))
+print(dom0.info())
 There is not much to comment about it, it really is a straight mapping
 from the C API, the only points to notice are:
 
-- 
2.20.1




Re: [libvirt-python PATCH] setup: require python >= 3.5 to build

2020-04-20 Thread Philipp Hahn
Hello Daniel.

2 nits:

Am 20.04.20 um 14:47 schrieb Daniel P. Berrangé:
> Pytjon 3.5 is the oldest Python version available across our supported
 ^ h
> build platforms.
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  setup.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/setup.py b/setup.py
> index 56b6eea..b3e418e 100755
> --- a/setup.py
> +++ b/setup.py
> @@ -17,8 +17,8 @@ import re
>  import shutil
>  import time
>  
> -if sys.version_info[0] != 3:
> -print("libvirt-python requires Python 3.x to build")
> +if sys.version_info[0] != 3 or sys.version_info[1] < 5:

if sys.version_info < (3, 5):

> +print("libvirt-python requires Python 3 >= 3.5 to build")
>  sys.exit(1)
>  
>  MIN_LIBVIRT = "0.9.11"
> 

plus maybe this:

> diff --git a/setup.py b/setup.py
> index 56b6eea..e20b7b3 100755
> --- a/setup.py
> +++ b/setup.py
> @@ -368,5 +368,9 @@ of recent versions of Linux (and other OSes).''',
>"License :: OSI Approved :: GNU Lesser General Public License v2 
> or later (LGPLv2+)",
>"Programming Language :: Python",
>"Programming Language :: Python :: 3",
> +  "Programming Language :: Python :: 3.5",
> +  "Programming Language :: Python :: 3.6",
> +  "Programming Language :: Python :: 3.7",
> +  "Programming Language :: Python :: 3.8",
>]
>  )


Philipp




[PATCH libvirt-python] examples: Fix connection error handling

2020-04-20 Thread Philipp Hahn
libvirt.open*() does not return None but raises an exception

Signed-off-by: Philipp Hahn 
---
 examples/dominfo.py| 5 +++--
 examples/domrestore.py | 5 +++--
 examples/domsave.py| 5 +++--
 examples/domstart.py   | 5 +++--
 examples/esxlist.py| 6 +++---
 5 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/examples/dominfo.py b/examples/dominfo.py
index 0a39f4c..fcfb8ed 100755
--- a/examples/dominfo.py
+++ b/examples/dominfo.py
@@ -34,8 +34,9 @@ if len(sys.argv) != 2:
 name = sys.argv[1]
 
 # Connect to libvirt
-conn = libvirt.openReadOnly(None)
-if conn is None:
+try:
+conn = libvirt.openReadOnly(None)
+except libvirt.libvirtError:
 print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
diff --git a/examples/domrestore.py b/examples/domrestore.py
index 96f4955..7fd5c8e 100755
--- a/examples/domrestore.py
+++ b/examples/domrestore.py
@@ -20,8 +20,9 @@ if len(sys.argv) != 2:
 dir = sys.argv[1]
 imgs = os.listdir(dir)
 
-conn = libvirt.open(None)
-if conn is None:
+try:
+conn = libvirt.open(None)
+except libvirt.libvirtError:
 print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
diff --git a/examples/domsave.py b/examples/domsave.py
index 4940cce..f8922d6 100755
--- a/examples/domsave.py
+++ b/examples/domsave.py
@@ -18,8 +18,9 @@ if len(sys.argv) != 2:
 
 dir = sys.argv[1]
 
-conn = libvirt.open(None)
-if conn is None:
+try:
+conn = libvirt.open(None)
+except libvirt.libvirtError:
 print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
diff --git a/examples/domstart.py b/examples/domstart.py
index 7ff6cb9..f342e95 100755
--- a/examples/domstart.py
+++ b/examples/domstart.py
@@ -32,8 +32,9 @@ if len(sys.argv) != 2:
 
 (name, xmldesc) = read_domain(sys.argv[1])
 
-conn = libvirt.open(None)
-if conn is None:
+try:
+conn = libvirt.open(None)
+except libvirt.libvirtError:
 print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
diff --git a/examples/esxlist.py b/examples/esxlist.py
index d86e064..caeced1 100755
--- a/examples/esxlist.py
+++ b/examples/esxlist.py
@@ -97,9 +97,9 @@ uri = "esx://%s/?no_verify=1" % hostname
 # in order to log into the vCenter
 auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT],
 request_credentials, None]
-conn = libvirt.openAuth(uri, auth, 0)
-
-if conn is None:
+try:
+conn = libvirt.openAuth(uri, auth, 0)
+except libvirt.libvirtError:
 print("Failed to open connection to %s" % hostname)
 sys.exit(1)
 
-- 
2.20.1




[PATCH] doc/python: Update to Python 3

2020-04-20 Thread Philipp Hahn
Convert the simple example to Python 3 syntax:
- print() is a function
- do not use bare except
- libvirt.open*() does not return None but raises an exception

The referenced source for the example was removed with
5bb2a245abbde4c0a407f631660e2f2c81bc4c02
---
 docs/python.html.in | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/docs/python.html.in b/docs/python.html.in
index e6e8cfade9..0f804da8c3 100644
--- a/docs/python.html.in
+++ b/docs/python.html.in
@@ -38,24 +38,24 @@ specificities in their argument conversions:
 is replaced by virDomain::info() which returns a list of
 state: one of the state values (virDomainState)maxMemory: 
the maximum memory used by the domainmemory: the current amount of 
memory used by the domainnbVirtCPU: the number of virtual 
CPUcpuTime: the time used by the domain in nanoseconds
 
-So let's look at a simple example inspired from the 
basic.py
-test found in python/tests/ in the source tree:
+So let's look at a simple example:
 import libvirt
 import sys
 
-conn = libvirt.openReadOnly(None)
-if conn == None:
-print 'Failed to open connection to the hypervisor'
+try:
+conn = libvirt.openReadOnly(None)
+except libvirt.libvirtError:
+print('Failed to open connection to the hypervisor')
 sys.exit(1)
 
 try:
 dom0 = conn.lookupByName("Domain-0")
-except:
-print 'Failed to find the main domain'
+except libvirt.libvirtError:
+print('Failed to find the main domain')
 sys.exit(1)
 
-print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())
-print dom0.info()
+print("Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType()))
+print(dom0.info())
 There is not much to comment about it, it really is a straight mapping
 from the C API, the only points to notice are:
 
-- 
2.20.1




Re: [python] WIP-FYI: mypy annotations for libvirt-python and cleanup for generator.py

2020-04-19 Thread Philipp Hahn
Hello,

Am 08.11.18 um 11:11 schrieb Philipp Hahn:
> Maybe you already have heard about mypy <http://mypy-lang.org/>, which
> "is an experimental optional static type checker for Python that aims to
> combine the benefits of dynamic (or "duck") typing and static typing".
> 
> I started to write a manual annotation file for the Python binding of
> libvirt. I've attached my current version, so others can benefit from
> it, too. It is far from complete, but it already helped my to find some
> errors in my code.
> (My latest version is also available at
> <https://github.com/univention/typeshed/blob/libvirt/third_party/2and3/libvirt.pyi>)
> 
> Long-term it probably would be better to teach the Python binding
> "generator.py" to add the type information (PEP 484
> <https://www.python.org/dev/peps/pep-0484/>) directly into the generated
> "libvirt.py" file, but that's for another day.
> If someone else is interested in helping with that, please feel free to
> get in contact.

This project got postponed for a long time, but I have a first working
version in my git branch at
<https://github.com/univention/libvirt-python/tree/typing>.
It is not perfect and ready for merging yet, but generated a first
working version. Here's an example:

> def qemuMonitorEventRegister(conn,  # type: virConnect
>  dom,  # type: virDomain
>  event,  # type: str
>  cb,  # type: Callable[[virConnect, virDomain, 
> str, int, int, str, _T], None]
>  opaque,  # type: _T
>  flags=0  # type: int
>  ):  # type: (...) -> int

1. There are 2 mypy syntax's for doing the typing annotation: This first
one adds special comments and also works with Python 2:

> def function(name, age):  # type: (str, int) -> bool

The second version only works since python 3.5:

> def function(name: str, age: int) -> bool:

As Python 2 is EOL, "generator.py" already uses Python 3 and Python 2
support was already removed, what is the minimum version of Python 3
required by libvirt-python? That is, should I use the old "comment"
variant or directly the new "inline" variant?


2. Actually the branch contains many cleanup patches and even some error
fixes, which could go into master right now. How can I best accomplish
that? Build a 2nd branch with only those fixes and send the patch queue
to the mailing list?


Thank you and stay healthy
Philipp




[libvirt] [PATCH go-xml 2/4] doc: Variable is already defined

2019-11-21 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 doc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc.go b/doc.go
index f97f2eb..d1f94b2 100644
--- a/doc.go
+++ b/doc.go
@@ -55,7 +55,7 @@
 //  xmldoc, err := dom.GetXMLDesc(0)
 //
 //  domcfg := {}
-//  err := domcfg.Unmarshal(xmldoc)
+//  err = domcfg.Unmarshal(xmldoc)
 //
 //  fmt.Printf("Virt type %s", domcfg.Type)
 //
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH go-xml 3/4] doc: Add missing newline

2019-11-21 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 doc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc.go b/doc.go
index d1f94b2..c4ce0dd 100644
--- a/doc.go
+++ b/doc.go
@@ -57,6 +57,6 @@
 //  domcfg := {}
 //  err = domcfg.Unmarshal(xmldoc)
 //
-//  fmt.Printf("Virt type %s", domcfg.Type)
+//  fmt.Printf("Virt type %s\n", domcfg.Type)
 //
 package libvirtxml
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH go-xml 1/4] doc: Handle conn.LookupDomainByName() error

2019-11-21 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 doc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc.go b/doc.go
index 2886c79..f97f2eb 100644
--- a/doc.go
+++ b/doc.go
@@ -51,7 +51,7 @@
 //  )
 //
 //  conn, err := libvirt.NewConnect("qemu:///system")
-//  dom := conn.LookupDomainByName("demo")
+//  dom, err := conn.LookupDomainByName("demo")
 //  xmldoc, err := dom.GetXMLDesc(0)
 //
 //  domcfg := {}
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH go-xml 4/4] doc: Make examples a complete program

2019-11-21 Thread Philipp Hahn
Add `package main` and declare a `main()` function.

Signed-off-by: Philipp Hahn 
---
 doc.go | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/doc.go b/doc.go
index c4ce0dd..25bc1d5 100644
--- a/doc.go
+++ b/doc.go
@@ -33,30 +33,38 @@
 //
 // Example creating a domain XML document from configuration:
 //
+//  package main
+//
 //  import (
 //   "github.com/libvirt/libvirt-go-xml"
 //  )
 //
-//  domcfg := {Type: "kvm", Name: "demo",
-//   UUID: "8f99e332-06c4-463a-9099-330fb244e1b3",
-//   }
-//  xmldoc, err := domcfg.Marshal()
+//  func main() {
+//domcfg := {Type: "kvm", Name: "demo",
+// UUID: 
"8f99e332-06c4-463a-9099-330fb244e1b3",
+// }
+//xmldoc, err := domcfg.Marshal()
+//  }
 //
 // Example parsing a domainXML document, in combination with libvirt-go
 //
+//  package main
+//
 //  import (
 //"github.com/libvirt/libvirt-go"
 //"github.com/libvirt/libvirt-go-xml"
 //"fmt"
 //  )
 //
-//  conn, err := libvirt.NewConnect("qemu:///system")
-//  dom, err := conn.LookupDomainByName("demo")
-//  xmldoc, err := dom.GetXMLDesc(0)
+//  func main() {
+//conn, err := libvirt.NewConnect("qemu:///system")
+//dom, err := conn.LookupDomainByName("demo")
+//xmldoc, err := dom.GetXMLDesc(0)
 //
-//  domcfg := {}
-//  err = domcfg.Unmarshal(xmldoc)
+//domcfg := {}
+//err = domcfg.Unmarshal(xmldoc)
 //
-//  fmt.Printf("Virt type %s\n", domcfg.Type)
+//fmt.Printf("Virt type %s\n", domcfg.Type)
+//  }
 //
 package libvirtxml
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH go-xml 0/4] Update documentation

2019-11-21 Thread Philipp Hahn
Hello,

as requested here are my proposed changes from
<https://www.berrange.com/posts/2017/01/05/announce-new-libvirt-project-go-xml-parser-model/>
for libvirt-go-xml/doc.go.

Philipp Hahn (4):
  doc: Handle conn.LookupDomainByName() error
  doc: Variable is already defined
  doc: Add missing newline
  doc: Make examples a complete program

 doc.go | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 3/6] Adapt to API change for dom.Devices.{Serials, Console}

2019-11-15 Thread Philipp Hahn
Follow
> commit d44fdf9badbb798949ab9f82ef516a2fd36d8b55
> Author: Daniel P. Berrange 
> Date:   Tue Nov 28 11:50:06 2017 +
>
> Generalize protocol handling for chardev sources

Signed-off-by: Philipp Hahn 
---
 cmd/virtconsoleresolveradm/cmd/enable.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/virtconsoleresolveradm/cmd/enable.go 
b/cmd/virtconsoleresolveradm/cmd/enable.go
index 1a4a12d..ebad497 100644
--- a/cmd/virtconsoleresolveradm/cmd/enable.go
+++ b/cmd/virtconsoleresolveradm/cmd/enable.go
@@ -174,14 +174,14 @@ func doEnable(cmd *cobra.Command, args []string) {
}
 
for idx, chardev := range domcfg.Devices.Serials {
-   if chardev.Type == "tcp" {
+   if chardev.Source.TCP != nil {
meta.Consoles = append(meta.Consoles,
createConsole("serial", idx, conn, domname, 
domuuid))
}
}
 
for idx, chardev := range domcfg.Devices.Consoles {
-   if chardev.Type == "tcp" {
+   if chardev.Source.TCP != nil {
meta.Consoles = append(meta.Consoles,
createConsole("console", idx, conn, domname, 
domuuid))
}
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 6/6] virtconsoleresolveradm: Fix -c handling

2019-11-15 Thread Philipp Hahn
-c / --connect  does not work:
> $ build/virtconsoleresolveradm -c qemu:///session enable $VM
> Error: unknown shorthand flag: 'c' in -c

<https://github.com/spf13/cobra#persistent-flags>

Signed-off-by: Philipp Hahn 
---
 cmd/virtconsoleresolveradm/cmd/root.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/virtconsoleresolveradm/cmd/root.go 
b/cmd/virtconsoleresolveradm/cmd/root.go
index 7aaca47..d4001e4 100644
--- a/cmd/virtconsoleresolveradm/cmd/root.go
+++ b/cmd/virtconsoleresolveradm/cmd/root.go
@@ -42,5 +42,5 @@ var (
 )
 
 func init() {
-   RootCmd.Flags().StringVarP(, "connect", "c", "qemu:///system", 
"Libvirt connection URI")
+   RootCmd.PersistentFlags().StringVarP( ,"connect", "c", 
"qemu:///system", "Libvirt connection URI")
 }
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 1/6] Adapt to API change for dom.Devices.Graphics

2019-11-15 Thread Philipp Hahn
Follow
> commit 4772b681e87a8d0dcee011b8e43813e851e4f934
> Author: Daniel P. Berrange 
> Date:   Fri Nov 24 16:15:30 2017 +
>
> Add remaining graphics configuration options

Signed-off-by: Philipp Hahn 
---
 cmd/virtconsoleresolveradm/cmd/enable.go |  6 ++
 pkg/resolver/server.go   | 26 
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/cmd/virtconsoleresolveradm/cmd/enable.go 
b/cmd/virtconsoleresolveradm/cmd/enable.go
index 04ca80b..dd95e9e 100644
--- a/cmd/virtconsoleresolveradm/cmd/enable.go
+++ b/cmd/virtconsoleresolveradm/cmd/enable.go
@@ -164,15 +164,13 @@ func doEnable(cmd *cobra.Command, args []string) {
meta = {}
 
for _, graphics := range domcfg.Devices.Graphics {
-   switch graphics.Type {
-   case "spice":
+   if graphics.Spice != nil {
meta.Consoles = append(meta.Consoles,
createConsole("spice", 0, conn, domname, 
domuuid))
-   case "vnc":
+   } else if graphics.VNC != nil {
meta.Consoles = append(meta.Consoles,
createConsole("vnc", 0, conn, domname, domuuid))
}
-
}
 
for idx, chardev := range domcfg.Devices.Serials {
diff --git a/pkg/resolver/server.go b/pkg/resolver/server.go
index 115d75d..eefdad7 100644
--- a/pkg/resolver/server.go
+++ b/pkg/resolver/server.go
@@ -86,13 +86,19 @@ type ConsoleServer struct {
 
 const tokenpath = "/consoleresolver/token/"
 
+func isListenAddress(listen string) bool {
+   return listen != "" && listen != "0.0.0.0" && listen != "::"
+}
+
 func getListener(dom libvirtxml.Domain, gtype string, insecure bool, 
consoleHost, defaultHost string) (string, error) {
if dom.Devices == nil {
return "", errors.New("No devices present")
}
 
for _, graphics := range dom.Devices.Graphics {
-   if graphics.Type != gtype {
+   if gtype == "vnc" && graphics.VNC != nil {
+   } else if gtype == "spice" && graphics.Spice != nil {
+   } else {
continue
}
 
@@ -100,21 +106,25 @@ func getListener(dom libvirtxml.Domain, gtype string, 
insecure bool, consoleHost
if consoleHost != "" {
host = consoleHost
} else {
-   if graphics.Listen != "" && graphics.Listen != 
"0.0.0.0" && graphics.Listen != "::" {
-   host = graphics.Listen
+   if graphics.VNC != nil && 
isListenAddress(graphics.VNC.Listen) {
+   host = graphics.VNC.Listen
+   } else if graphics.Spice != nil && 
isListenAddress(graphics.Spice.Listen) {
+   host = graphics.Spice.Listen
} else {
host = defaultHost
}
}
 
var port int
-   if graphics.Type == "spice" && !insecure {
-   port = graphics.TLSPort
-   } else {
-   port = graphics.Port
+   if graphics.Spice != nil && !insecure {
+   port = graphics.Spice.TLSPort
+   } else if graphics.Spice != nil {
+   port = graphics.Spice.Port
+   } else if graphics.VNC != nil {
+   port = graphics.VNC.Port
}
glog.V(1).Infof("Got port %d\n", port)
-   if graphics.Port == 0 || graphics.Port == -1 {
+   if port == 0 || port == -1 {
return "", errors.New("Missing port for graphics")
}
 
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 4/6] virtconsoleresolveradm: Require sub-command

2019-11-15 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 cmd/virtconsoleresolveradm/cmd/root.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cmd/virtconsoleresolveradm/cmd/root.go 
b/cmd/virtconsoleresolveradm/cmd/root.go
index 76e1203..7aaca47 100644
--- a/cmd/virtconsoleresolveradm/cmd/root.go
+++ b/cmd/virtconsoleresolveradm/cmd/root.go
@@ -34,6 +34,7 @@ var RootCmd = {
Short: "Libvirt console resolver admin",
Long:  "Libvirt console resolver administration tool",
Run:   func(cmd *cobra.Command, args []string) {},
+   Args: cobra.MinimumNArgs(1),
 }
 
 var (
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 2/6] Adapt to uuid API change

2019-11-15 Thread Philipp Hahn
> commit 0ef6afb2f6cdd6cdaeee3885a95099c63f18fc8c
> Author: Maxim Bublis 
> Date:   Wed Jan 3 16:02:28 2018 +
>
> Return enthropy errors from UUID generation.
>
> This commit changes signature for `NewV1`, `NewV2` and `NewV4` functions
> which from now will return `(UUID, error)` instead of `UUID`.
> To emulate old behavior of panicking on enthropy errors one can wrap
> a call into `Must` helper similar to:
> ```
> u := uuid.Must(uuid.NewV4())

Signed-off-by: Philipp Hahn 
---
 cmd/virtconsoleresolveradm/cmd/enable.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/virtconsoleresolveradm/cmd/enable.go 
b/cmd/virtconsoleresolveradm/cmd/enable.go
index dd95e9e..1a4a12d 100644
--- a/cmd/virtconsoleresolveradm/cmd/enable.go
+++ b/cmd/virtconsoleresolveradm/cmd/enable.go
@@ -49,8 +49,8 @@ var (
 )
 
 func createConsole(ctype string, index int, conn *libvirt.Connect, domname, 
domuuid string) resolver.ConsoleServerProxyMetadataConsole {
-   tokenID := uuid.NewV4()
-   tokenValue := uuid.NewV4()
+   tokenID := uuid.Must(uuid.NewV4())
+   tokenValue := uuid.Must(uuid.NewV4())
console := resolver.ConsoleServerProxyMetadataConsole{
Token:tokenID.String(),
Type: ctype,
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 5/6] virtconsoleresolveradm: Simplify argument parsing

2019-11-15 Thread Philipp Hahn
Use ExactArgs(1) to check for exactly one positional argument.

<https://github.com/spf13/cobra#positional-and-custom-arguments>

Signed-off-by: Philipp Hahn 
---
 cmd/virtconsoleresolveradm/cmd/disable.go | 6 +-
 cmd/virtconsoleresolveradm/cmd/enable.go  | 6 +-
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/cmd/virtconsoleresolveradm/cmd/disable.go 
b/cmd/virtconsoleresolveradm/cmd/disable.go
index 2d41874..aab3047 100644
--- a/cmd/virtconsoleresolveradm/cmd/disable.go
+++ b/cmd/virtconsoleresolveradm/cmd/disable.go
@@ -40,14 +40,10 @@ var disableCmd = {
Short: "Disable consoles for a domain",
Long:  "Disable access to consoles for a domain",
Run:   doDisable,
+   Args: cobra.ExactArgs(1),
 }
 
 func doDisable(cmd *cobra.Command, args []string) {
-   if len(args) != 1 {
-   fmt.Fprintln(os.Stderr, "Missing domain name/uuid")
-   os.Exit(1)
-   }
-
conn, err := libvirt.NewConnect(connect)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot connect to hypervisor '%s': 
%s\n",
diff --git a/cmd/virtconsoleresolveradm/cmd/enable.go 
b/cmd/virtconsoleresolveradm/cmd/enable.go
index ebad497..49897ef 100644
--- a/cmd/virtconsoleresolveradm/cmd/enable.go
+++ b/cmd/virtconsoleresolveradm/cmd/enable.go
@@ -43,6 +43,7 @@ var (
Short: "Enable consoles for a domain",
Long:  "Enable consoles for a domain",
Run:   doEnable,
+   Args: cobra.ExactArgs(1),
}
insecure *bool
host *string
@@ -99,11 +100,6 @@ func createConsole(ctype string, index int, conn 
*libvirt.Connect, domname, domu
 }
 
 func doEnable(cmd *cobra.Command, args []string) {
-   if len(args) != 1 {
-   fmt.Fprintln(os.Stderr, "Missing domain name/uuid")
-   os.Exit(1)
-   }
-
conn, err := libvirt.NewConnect(connect)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot connect to hypervisor '%s': 
%s\n",
-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH console-proxy 0/6] libvirt-go-xml and libvirt-console-proxy ?

2019-11-15 Thread Philipp Hahn
Hello Daniel,

I regularly visit your blog and stumbled over
<https://www.berrange.com/posts/2017/01/05/announce-new-libvirt-project-go-xml-parser-model/>,
which seems to contains some small errors - I'm a "go"-newby, so I had
to spend some time to understand your example and to make it go:

> import (
>   libvirt "github.com/libvirt/libvirt-go"
>   libvirtxml "github.com/libvirt/libvirt-go-xml"
>   "encoding/xml"
>   "fmt"
> )
>
> conn, err := libvirt.NewConnect("qemu:///system")
> dom := conn.LookupDomainByName("demo")

This also returns a tuple (dom, err), so should look like:

dom, err := conn.LookupDomainByName("demo")

> xmldoc, err := dom.GetXMLDesc(0)
>
> domcfg := {}
> err := xml.Unmarshal([]byte(xmldocC), domcfg)

This fails as "err" is already defined. Should be '=' instead of ':=':

err = xml.Unmarshal([]byte(xmldocC), domcfg)

>
> fmt.Printf("Virt type %s", domcfg.Type)

Maybe add an "\n" at the end?

And maybe also add the wrapper
> package main
...
> func main() {
...
> }
to make the example complete?


Second is
<https://www.berrange.com/posts/2017/01/26/announce-new-libvirt-console-proxy-project/>:
Do you (or someone else) still work on libvirt-console-proxy? It no
longer compiles after several API changed in libvirt-go-xml and uuid.
I have attached several patches, which at least allow compiling again,
I only tested is briefly.

Philipp

Philipp Hahn (6):
  Adapt to API change for dom.Devices.Graphics
  Adapt to uuid API change
  Adapt to API change for dom.Devices.{Serials,Console}
  virtconsoleresolveradm: Require sub-command
  virtconsoleresolveradm: Simplify argument parsing
  virtconsoleresolveradm: Fix -c handling

 cmd/virtconsoleresolveradm/cmd/disable.go |  6 +-
 cmd/virtconsoleresolveradm/cmd/enable.go  | 20 ++---
 cmd/virtconsoleresolveradm/cmd/root.go|  3 ++-
 pkg/resolver/server.go| 26 ---
 4 files changed, 28 insertions(+), 27 deletions(-)

-- 
2.20.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



Re: [libvirt] [PATCH] virt-xml-validate: Allow input to be read from stdin

2019-05-21 Thread Philipp Hahn
Hello,

Am 21.05.19 um 09:35 schrieb Johannes Holmberg:
> On Tue, 2019-05-21 at 07:36 +0200, Philipp Hahn wrote:
>> Am 20.05.19 um 13:57 schrieb Johannes Holmberg:
>>> diff --git a/tools/virt-xml-validate.in b/tools/virt-xml-validate.in
...
>>> +if [ "$XMLFILE" = "-" ]; then
>>> +TMPFILE=`mktemp --tmpdir virt-xml.`
...
>> Quoting
> 
> Good point(s). I can only imagine I skipped the quoting because TMPFILE
> is known to contain a safe string,

No, it's not guaranteed, as it honors TMPDIR:

> $ LANG=C TMPDIR='/tmp/un safe' mktemp --tmpdir virt-xml.
> mktemp: failed to create file via template '/tmp/un safe/virt-xml.': ...

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] virt-xml-validate: Allow input to be read from stdin

2019-05-21 Thread Philipp Hahn
Hello,

Some nits:

Am 20.05.19 um 13:57 schrieb Johannes Holmberg:
> diff --git a/tools/virt-xml-validate.in b/tools/virt-xml-validate.in
> index 64ae33..2d2afb74ec 100644
> --- a/tools/virt-xml-validate.in
> +++ b/tools/virt-xml-validate.in
> @@ -16,6 +16,16 @@
>  
>  set -e
>  
> +TMPFILE=
> +
> +cleanup() {
> +  if [ $TMPFILE ]; then

Missing Quoting.
Better also give "-n"

> +rm -f $TMPFILE

Quoting

> +  fi
> +}
> +
> +trap cleanup EXIT
> +
>  case $1 in

Not your fault, but also missing quoting.

>-h | --h | --he | --hel | --help)
>  cat < @@ -34,7 +44,7 @@ $0 (libvirt) @VERSION@
>  EOF
>  exit ;;
>--) shift ;;
> -  -*)
> +  -?*)
>  echo "$0: unrecognized option '$1'" >&2
>  exit 1 ;;
>  esac
> @@ -42,18 +52,27 @@ esac
>  XMLFILE="$1"
>  TYPE="$2"
>  
> -if [ -z "$XMLFILE" ]; then
> -  echo "syntax: $0 XMLFILE [TYPE]" >&2
> -  exit 1
> -fi
> +if [ "$XMLFILE" = "-" ]; then
> +TMPFILE=`mktemp --tmpdir virt-xml.`> +cat > $TMPFILE

Quoting

> +else
> +  if [ -z "$XMLFILE" ]; then
> +echo "syntax: $0 XMLFILE [TYPE]" >&2
> +exit 1
> +  fi
>  
> -if [ ! -f "$XMLFILE" ]; then
> -  echo "$0: document $XMLFILE does not exist" >&2
> -  exit 2
> +  if [ ! -f "$XMLFILE" ]; then
> +echo "$0: document $XMLFILE does not exist" >&2
> +exit 2
> +  fi
>  fi
>  
>  if [ -z "$TYPE" ]; then
> -  ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk 
> '{ print $3 }'`
> +  if [ $TMPFILE ]; then
> +ROOT=`xmllint --stream --debug - < "$TMPFILE" 2>/dev/null | grep "^0 1 " 
> | awk '{ print $3 }'`
> +  else
> +ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | 
> awk '{ print $3 }'`
> +  fi
>case "$ROOT" in
>   *domainsnapshot*) # Must come first, since *domain* is a substring
>  TYPE="domainsnapshot"
> @@ -101,6 +120,9 @@ if [ ! -f "$SCHEMA" ]; then
>exit 4
>  fi
>  
> -xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
> -
> +if [ $TMPFILE ]; then

Quoting
"-n"

> +  xmllint --noout --relaxng "$SCHEMA" - < "$TMPFILE"
> +else
> +  xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
> +fi
>  exit

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH libvirt-python] virNodeInfo.memory is in KiB

2018-12-05 Thread Philipp Hahn
Hello Daniel,


Am 05.12.18 um 13:10 schrieb Daniel P. Berrangé:
> On Wed, Dec 05, 2018 at 01:01:13PM +0100, Philipp Hahn wrote:
>> but the Python library does an extra left shift of 10 bits returning MiB
>> instead:
...
>>> # ./a.out
>>> 4041088
>>
>>> # python -c 'import 
>>> libvirt;c=libvirt.open("qemu:///system");print(c.getInfo()[1])'
>>> 3946
>>
>> Fixes: 197153c6
> 
> Not sure why you're quoting that commit has as it is unrelated.
> 
> This use of MB is from pretty much day 1 in 506fb7d8

Yes, you're right, that was the wrong commit hash and 506fb7d8 is the
correct one.

>> Signed-off-by: Philipp Hahn 
>> ---
>>  libvirt-override.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libvirt-override.c b/libvirt-override.c
>> index f7b2f6b..616fa1c 100644
>> --- a/libvirt-override.c
>> +++ b/libvirt-override.c
>> @@ -2740,7 +2740,7 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED,
>>  VIR_PY_LIST_SET_GOTO(py_retval, 0,
>>   libvirt_constcharPtrWrap([0]), error);
>>  VIR_PY_LIST_SET_GOTO(py_retval, 1,
>> - libvirt_longWrap((long) info.memory >> 10), error);
>> + libvirt_longWrap((long) info.memory), error);
> 
> We can't change this as it would break every single existing user of this
> API which have been written to expect this to be a MB value.

Okay. This is already documented in libvirt-override-api.xml:

> 102 
>   
>
> 103   Extract hardware information about the Node. Note that the 
> memory size is reported in MiB instead of KiB.

I was only looking at the C-API documentation.
So my patch can go to >/dev/null.

Sorry for the noise.

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH libvirt-python] virNodeInfo.memory is in KiB

2018-12-05 Thread Philipp Hahn
but the Python library does an extra left shift of 10 bits returning MiB
instead:

> # cat y.c
> #include 
> #include 
> #include 
> int main(void) {
> virConnectPtr conn = virConnectOpen("qemu:///system");
> virNodeInfo info;
> int rv = virNodeGetInfo(conn, );
> printf("%ld\n", info.memory);
> return rv;
> }
> # gcc y.c -I/usr/include/libvirt -lvirt
> # ./a.out
> 4041088

> # python -c 'import 
> libvirt;c=libvirt.open("qemu:///system");print(c.getInfo()[1])'
> 3946

Fixes: 197153c6
Signed-off-by: Philipp Hahn 
---
 libvirt-override.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index f7b2f6b..616fa1c 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -2740,7 +2740,7 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED,
 VIR_PY_LIST_SET_GOTO(py_retval, 0,
  libvirt_constcharPtrWrap([0]), error);
 VIR_PY_LIST_SET_GOTO(py_retval, 1,
- libvirt_longWrap((long) info.memory >> 10), error);
+ libvirt_longWrap((long) info.memory), error);
 VIR_PY_LIST_SET_GOTO(py_retval, 2, libvirt_intWrap((int) info.cpus), 
error);
 VIR_PY_LIST_SET_GOTO(py_retval, 3, libvirt_intWrap((int) info.mhz), error);
 VIR_PY_LIST_SET_GOTO(py_retval, 4, libvirt_intWrap((int) info.nodes), 
error);
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [BUG][PATCH][RRFC][libvirt-python] libvirtError(..., conn=, dom=. vol=, pool=, snap=)

2018-11-27 Thread Philipp Hahn
Hello,

Am 27.11.18 um 15:29 schrieb Daniel P. Berrangé:
> On Mon, Nov 26, 2018 at 05:12:06PM +0100, Philipp Hahn wrote:
>> Am 26.11.18 um 16:28 schrieb Michal Privoznik:
>>> On 11/21/18 8:17 AM, Philipp Hahn wrote:
>>>> while working on the Python type annotations for the Python libvirt
>>>> binding I noticed the following code in
>>>> libvirt-override-virDomainSnapshot.py:
...
>>>> Compare that with the declaration of libvirtError in libvirt-override.py:
>>>>
>>>>> class libvirtError(Exception):
>>>>> def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, 
>>>>> vol=None):
>>>>
>>>> Looking further at the implementation of that method only "defmsg" is
>>>> used; all other references are not accessed and never stored in an
>>>> instance variable.
...
>> The fields have been deprecated with
>> git:f60dc0bc09f09c6817d6706a9edb1579a3e2b2b8 in "libvirt" and there is
>> this warning in include/libvirt/virterror.h:
>>
>>> 142 /**
>>> 143  * virError:
>>> 144  *
>>> 145  * A libvirt Error instance.
>>> 146  *
>>> 147  * The conn, dom and net fields should be used with extreme care.
>>> 148  * Reference counts are not incremented so the underlying objects
>>> 149  * may be deleted without notice after the error has been delivered.
>>> 150  */
>>
>> The variables are not used anywhere in the Python code.
> 
> This is referring to the C level virError struct and is related to a
> historical mistake a very long time ago. Essentially it was created
> when we only have virDomain / virConnect objects. We mistakenly 
> changed ABI when we added virNetwork object to it. At at the time
> we decided to stop adding extra objects to the C level virError
> struct. It also has the problem with reference counting mentioned
> here tough that isn't fatal if the C code is being very careful
> in how it uses the virError object.
> 
> This deprecation at the C level, however, should not have any
> bearing on what we do at the Python level. We are passing in the
> python wrapped objects to libvirtError(), so don't suffer from
> the reference counting problems.>
> So I don't see a compelling reason to remove these python object
> arguments. We should just fix the usage to actually pass in the
> correct objects & add parameters for the missing object types.


Quoting from libvirt-override.py:
>  20 # The root of all libvirt errors.
>21 class libvirtError(Exception):  
>   
>   
>  
>22 def __init__(self, defmsg, conn=None, dom=None, net=None, 
> pool=None, vol=None):
>23 
>24 # Never call virConnGetLastError().
>25 # virGetLastError() is now thread local
>26 err = libvirtmod.virGetLastError()
>27 if err is None:
>28 msg = defmsg
>29 else:
>30 msg = err[2]
>31 
>32 Exception.__init__(self, msg)
>33 
>34 self.err = err

conn, dom, net, pool, vol are arguments to the __init__() function, but
they are *nowhere* referenced in that function. There is *no* code like

  self.conn = conn
  self.dom = dom
  self.net = net
  self.pool = pool
  self.vol = vol

so the function arguments are *not* used at all!

There is no other class inheriting from libvirtError and the generated
code should be the only one "raising libvirtError" directly.

So why do we pass those information if we don't need them?

And we already have broken code passing instances of the wrong type (see
original email with those 3 patches). I only found then when adding type
annotations and the question remains, if we should add new unused
arguments or if we should delete them now and be done with them.

I find it very confusing to pass the object, where the error occurred,
and to not have an accessor to get that information back.

I'm also not keen to add new arguments for each new vir* type like
- virNodeDevice
- virSecret
- virNWFilterBinding
- virStream
- virDomainSnapshot

I would prefer to document the existing arguments as "unused" and to
never add any new arguments for new types.

Just my 2¢

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [BUG][PATCH][RRFC][libvirt-python] libvirtError(..., conn=, dom=. vol=, pool=, snap=)

2018-11-26 Thread Philipp Hahn
Hello,

Am 26.11.18 um 16:28 schrieb Michal Privoznik:
> On 11/21/18 8:17 AM, Philipp Hahn wrote:
>> while working on the Python type annotations for the Python libvirt
>> binding I noticed the following code in
>> libvirt-override-virDomainSnapshot.py:
>>
>>> def listAllChildren(self, flags=0):
>>> """List all child snapshots and returns a list of snapshot 
>>> objects"""
>> ...
>>> raise libvirtError("..., conn=self)
>>
>> "self" is an instance of virDomainSnapshot here.
>>
>> I found two similar cases where "conn" was not a "virConnect" instance
>> in listAllSnapshots() and listAllVolumes().
>>
>> Compare that with the declaration of libvirtError in libvirt-override.py:
>>
>>> class libvirtError(Exception):
>>> def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, 
>>> vol=None):
>>
>> Looking further at the implementation of that method only "defmsg" is
>> used; all other references are not accessed and never stored in an
>> instance variable.
>>
>> Should I add a new "snap" argument to libvirtError.__init__() or should
>> we stop passing those references to the constructor altogether?
> 
> I think we should pass whatever object the error occurred on. Your patch
> #2 demonstrates this beautifully - with the current code conn will point
> to something that is not instance of virConnect rather than virDomain class.

The fields have been deprecated with
git:f60dc0bc09f09c6817d6706a9edb1579a3e2b2b8 in "libvirt" and there is
this warning in include/libvirt/virterror.h:

> 142 /**
> 143  * virError:
> 144  *
> 145  * A libvirt Error instance.
> 146  *
> 147  * The conn, dom and net fields should be used with extreme care.
> 148  * Reference counts are not incremented so the underlying objects
> 149  * may be deleted without notice after the error has been delivered.
> 150  */

The variables are not used anywhere in the Python code.

So I'm included to instead remove the arguments completely from the
Python binding as well - see attached patch - that would break code
where a user raises libvirtError() by itself outside the library binding
code, but IMHO no-one should do that anyway.

>> Patch 2 and 3 might be applied to the current branch already, patch 1
>> currently depends on my other work.
> 
> ACK to them, do you want me to apply them now or should I wait (e.g.
> will you send them in some series?)

For now please hold off and let's discuss the removal first.

Philipp
From 973f5a5a8dc909a7ebca66cae8a2b87ae13431df Mon Sep 17 00:00:00 2001
Message-Id: <973f5a5a8dc909a7ebca66cae8a2b87ae13431df.1543248488.git.h...@univention.de>
From: Philipp Hahn 
Date: Wed, 21 Nov 2018 07:55:57 +0100
Subject: [PATCH libvirt-python] *: Remove legacy libvirtError arguments
To: libvir-list@redhat.com

The fields have been deprecated with
git:f60dc0bc09f09c6817d6706a9edb1579a3e2b2b8
The are not used anywhere in the Python code.

sed -i '/raise libvirtError/s/, \w\+=self//' *.py

Signed-off-by: Philipp Hahn 
---
 generator.py  | 38 -
 libvirt-override-virConnect.py| 52 +--
 libvirt-override-virDomain.py | 12 
 libvirt-override-virDomainSnapshot.py |  2 +-
 libvirt-override-virStoragePool.py|  2 +-
 libvirt-override.py   |  7 +
 6 files changed, 54 insertions(+), 59 deletions(-)

diff --git a/generator.py b/generator.py
index d854d48..cea9f79 100755
--- a/generator.py
+++ b/generator.py
@@ -1603,31 +1603,31 @@ def buildWrappers(module  # type: str
 else:
 if classname == "virConnect":
 classes.write(
-"if ret is None:raise libvirtError('%s() failed', conn=self)\n" %
+"if ret is None:raise libvirtError('%s() failed')\n" %
 (name))
 elif classname == "virDomain":
 classes.write(
-"if ret is None:raise libvirtError('%s() failed', dom=self)\n" %
+"if ret is None:raise libvirtError('%s() failed')\n" %
 (name))
 elif classname == "virNetwork":
 classes.write(
-"if ret is None:raise libvirtError('%s() failed', net=self)\n" %
+  

[libvirt] [BUG][PATCH][RRFC][libvirt-python] libvirtError(..., conn=, dom=. vol=, pool=, snap=)

2018-11-20 Thread Philipp Hahn
Hi,

while working on the Python type annotations for the Python libvirt
binding I noticed the following code in
libvirt-override-virDomainSnapshot.py:

> def listAllChildren(self, flags=0):
> """List all child snapshots and returns a list of snapshot objects"""
...
> raise libvirtError("..., conn=self)

"self" is an instance of virDomainSnapshot here.

I found two similar cases where "conn" was not a "virConnect" instance
in listAllSnapshots() and listAllVolumes().

Compare that with the declaration of libvirtError in libvirt-override.py:

> class libvirtError(Exception):
> def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, 
> vol=None):

Looking further at the implementation of that method only "defmsg" is
used; all other references are not accessed and never stored in an
instance variable.

Should I add a new "snap" argument to libvirtError.__init__() or should
we stop passing those references to the constructor altogether?

Patch 2 and 3 might be applied to the current branch already, patch 1
currently depends on my other work.

Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen
Tel.: +49 421 22232-0
Fax : +49 421 22232-99
h...@univention.de

http://www.univention.de/
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876
From b58456ac8cab8d84c40f8ac8222832b0ecbd6771 Mon Sep 17 00:00:00 2001
Message-Id: 
From: Philipp Hahn 
Date: Wed, 21 Nov 2018 07:55:57 +0100
Subject: [PATCH libvirt-python 1/3] snap: pass snapshot reference to exception
To: libvir-list@redhat.com

instead of passing it as a connection reference.

Signed-off-by: Philipp Hahn 
---
 libvirt-override-virDomainSnapshot.py | 2 +-
 libvirt-override.py   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libvirt-override-virDomainSnapshot.py b/libvirt-override-virDomainSnapshot.py
index 722cee3..ce59b09 100644
--- a/libvirt-override-virDomainSnapshot.py
+++ b/libvirt-override-virDomainSnapshot.py
@@ -12,7 +12,7 @@
 """List all child snapshots and returns a list of snapshot objects"""
 ret = libvirtmod.virDomainSnapshotListAllChildren(self._o, flags)
 if ret is None:
-raise libvirtError("virDomainSnapshotListAllChildren() failed", conn=self)
+raise libvirtError("virDomainSnapshotListAllChildren() failed", snap=self)
 
 retlist = list()
 for snapptr in ret:
diff --git a/libvirt-override.py b/libvirt-override.py
index c0c61eb..9c18d58 100644
--- a/libvirt-override.py
+++ b/libvirt-override.py
@@ -29,7 +29,8 @@ class libvirtError(Exception):
  dom=None,  # type: Optional[virDomain]
  net=None,  # type: Optional[virNetwork]
  pool=None,  # type: Optional[virStoragePool]
- vol=None  # type: Optional[virStorageVol]
+ vol=None,  # type: Optional[virStorageVol]
+ snap=None  # type: Optional[virDomainSnapshot]
  ):
 
 # Never call virConnGetLastError().
-- 
2.11.0

From 7ccc762b5f44d6c1b613852092fc747675a3936a Mon Sep 17 00:00:00 2001
Message-Id: <7ccc762b5f44d6c1b613852092fc747675a3936a.1542784226.git.h...@univention.de>
In-Reply-To: 
References: 
From: Philipp Hahn 
Date: Wed, 21 Nov 2018 08:07:23 +0100
Subject: [PATCH libvirt-python 2/3] snap: pass domain reference to exception
To: libvir-list@redhat.com

instead of passing it as a connection reference.

Signed-off-by: Philipp Hahn 
---
 libvirt-override-virDomain.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt-override-virDomain.py b/libvirt-override-virDomain.py
index 590d5c0..fb3f305 100644
--- a/libvirt-override-virDomain.py
+++ b/libvirt-override-virDomain.py
@@ -4,7 +4,7 @@
 """List all snapshots and returns a list of snapshot objects"""
 ret = libvirtmod.virDomainListAllSnapshots(self._o, flags)
 if ret is None:
-raise libvirtError("virDomainListAllSnapshots() failed", conn=self)
+raise libvirtError("virDomainListAllSnapshots() failed", dom=self)
 
 retlist = list()
 for snapptr in ret:
-- 
2.11.0

From cccf432d1bdbe625c88b91695e124deca7dd1c11 Mon Sep 17 00:00:00 2001
Message-Id: 
In-Reply-To: 
References: 
From: Philipp Hahn 
Date: Wed, 21 Nov 2018 08:09:15 +0100
Subject: [PATCH libvirt-python 3/3] snap: pass pool reference to exception
To: libvir-list@redhat.com

instead of passing it as a connection reference.

Signed-off-by: Philipp Hahn 
---
 libvirt-override-virStoragePool.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt-override-virStoragePool.py b/libvirt-override-virStoragePool.py

[libvirt] [PATCH libvirt-python] Add daemon to list of shutdown reasons

2018-11-15 Thread Philipp Hahn
Add the support to work with libvirt commit 66a85cb13.

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 709277b..81ebfc1 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -489,7 +489,7 @@ DOM_EVENTS = Description(
 ("Started", ("Booted", "Migrated", "Restored", "Snapshot", "Wakeup")),
 ("Suspended", ("Paused", "Migrated", "IOError", "Watchdog", "Restored", 
"Snapshot", "API error", "Postcopy", "Postcopy failed")),
 ("Resumed", ("Unpaused", "Migrated", "Snapshot", "Postcopy")),
-("Stopped", ("Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", 
"Failed", "Snapshot")),
+("Stopped", ("Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", 
"Failed", "Snapshot", "Daemon")),
 ("Shutdown", ("Finished", "On guest request", "On host request")),
 ("PMSuspended", ("Memory", "Disk")),
 ("Crashed", ("Panicked",)),
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [python] WIP-FYI: mypy annotations for libvirt-python

2018-11-08 Thread Philipp Hahn
Hello,

Maybe you already have heads about mypy <http://mypy-lang.org/>, which
"is an experimental optional static type checker for Python that aims to
combine the benefits of dynamic (or "duck") typing and static typing".

I started to write a manual annotation file for the Python binding of
libvirt. I've attached my current version, so others can benefit from
it, too. It is far from complete, but it already helped my to find some
errors in my code.
(My latest version is also available at
<https://github.com/univention/typeshed/blob/libvirt/third_party/2and3/libvirt.pyi>)

Long-term it probably would be better to teach the Python binding
"generator.py" to add the type information (PEP 484
<https://www.python.org/dev/peps/pep-0484/>) directly into the generated
"libvirt.py" file, but that's for another day.
If someone else is interested in helping with that, please feel free to
get in contact.

Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen
Tel.: +49 421 22232-0
Fax : +49 421 22232-99
h...@univention.de

http://www.univention.de/
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876
# Stubs for libvirt (Python 2)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Any, Callable, Dict, List, Optional

lib_e: Any
cyg_e: Any

class libvirtError(Exception):
err: Any = ...
def __init__(self, defmsg: str, conn: Optional[virConnect] = ..., dom: 
Optional[virDomain] = ..., net: Optional[virNetwork] = ..., pool: 
Optional[virStoragePool] = ..., vol: Optional[virStorageVol] = ...) -> None: ...
def get_error_code(self) -> int: ...
def get_error_domain(self): ...
def get_error_message(self) -> str: ...
def get_error_level(self) -> int: ...
def get_str1(self) -> str: ...
def get_str2(self) -> str: ...
def get_str3(self) -> str: ...
def get_int1(self) -> int: ...
def get_int2(self) -> int: ...

def registerErrorHandler(f: Any, ctx: Any): ...
def openAuth(uri: str, auth: Any, flags: int = ...) -> virConnect: ...
def getVersion(name: Optional[Any] = ...): ...
def virEventAddHandle(fd: Any, events: Any, cb: Callable, opaque: Any): ...
def virEventAddTimeout(timeout: Any, cb: Callable, opaque: Any): ...
def open(name: Optional[str] = ...) -> virConnect: ...
def openReadOnly(name: Optional[str] = ...) -> virConnect: ...
def virEventRegisterDefaultImpl(): ...
def virEventRegisterImpl(addHandle: Any, updateHandle: Any, removeHandle: Any, 
addTimeout: Any, updateTimeout: Any, removeTimeout: Any) -> None: ...
def virEventRemoveHandle(watch: Any): ...
def virEventRemoveTimeout(timer: Any): ...
def virEventRunDefaultImpl(): ...
def virEventUpdateHandle(watch: Any, events: Any) -> None: ...
def virEventUpdateTimeout(timer: Any, timeout: Any) -> None: ...
def virGetLastError() -> libvirtError: ...
def virGetLastErrorMessage(): ...
def virInitialize(): ...
def virResetLastError() -> None: ...

class virDomain:
def __init__(self, conn: virConnect, _obj: Optional[Any] = ...) -> None: ...
def __del__(self) -> None: ...
def connect(self) -> virConnect: ...
def c_pointer(self) -> int: ...
def ID(self) -> int: ...
def OSType(self) -> str: ...
def UUID(self) -> bytes: ...
def UUIDString(self) -> str: ...
def XMLDesc(self, flags: int = ...) -> str: ...
def abortJob(self): ...
def addIOThread(self, iothread_id: Any, flags: int = ...): ...
def attachDevice(self, xml: str): ...
def attachDeviceFlags(self, xml: str, flags: int = ...): ...
def autostart(self): ...
def blkioParameters(self, flags: int = ...): ...
def blockCommit(self, disk: Any, base: Any, top: Any, bandwidth: int = ..., 
flags: int = ...): ...
def blockCopy(self, disk: Any, destxml: str, params: Optional[Any] = ..., 
flags: int = ...): ...
def blockInfo(self, path: Any, flags: int = ...): ...
def blockIoTune(self, disk: Any, flags: int = ...): ...
def blockJobAbort(self, disk: Any, flags: int = ...): ...
def blockJobInfo(self, path: Any, flags: int = ...): ...
def blockJobSetSpeed(self, disk: Any, bandwidth: Any, flags: int = ...): ...
def blockPeek(self, disk: Any, offset: Any, size: Any, flags: int = ...): 
...
def blockPull(self, disk: Any, bandwidth: int = ..., flags: int = ...): ...
def blockRebase(self, disk: Any, base: Any, bandwidth: int = ..., flags: 
int = ...): ...
def blockResize(self, disk: Any, size: Any, flags: int = ...): ...
def blockStats(self, path: Any): ...
def blockStatsFlags(self, path: Any, flags: int = ...): ...
def controlInfo(self, flags: int = ...): ...
def coreDump(self, to: Any, flags: int = ...): ...
def coreDumpWithFormat(self, to: Any, dumpformat: Any, flags: int = ...): 
...
def create(se

[libvirt] [PATCH libvirt-python] event-test.py: Report ERROR events

2018-11-01 Thread Philipp Hahn
VIR_DOMAIN_EVENT_ID_IO_ERROR and VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
callbacks receive the same 'action' parameter, so also translate that
numeric action to a descriptive text for the first callback.

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index dabf4b0..709277b 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -526,8 +526,8 @@ def myDomainEventWatchdogCallback(conn, dom, action, 
opaque):
 
 
 def myDomainEventIOErrorCallback(conn, dom, srcpath, devalias, action, opaque):
-print("myDomainEventIOErrorCallback: Domain %s(%s) %s %s %d" % (
-dom.name(), dom.ID(), srcpath, devalias, action))
+print("myDomainEventIOErrorCallback: Domain %s(%s) %s %s %s" % (
+dom.name(), dom.ID(), srcpath, devalias, ERROR_EVENTS[action]))
 
 
 def myDomainEventIOErrorReasonCallback(conn, dom, srcpath, devalias, action, 
reason, opaque):
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python] event-test.py: Fix ERROR event

2018-11-01 Thread Philipp Hahn
ERROR_EVENTS translates the numeric 'action' argument to a description,
not the 'reason' argument which already contains a descriptive string
like 'enospc'.

> Traceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4661, in 
> _dispatchDomainEventIOErrorReasonCallback
> reason, opaque)
>   File "libvirt-python/examples/event-test.py", line 536, in 
> myDomainEventIOErrorReasonCallback
> dom.name(), dom.ID(), srcpath, devalias, action, ERROR_EVENTS[reason]))
>   File "libvirt-python/examples/event-test.py", line 474, in __getitem__
> data = self.args[item]
> TypeError: tuple indices must be integers, not str

Fixes: f5928c6711654f1496707ca77f626b3192843d57
Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index eeb2777..dabf4b0 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -531,8 +531,8 @@ def myDomainEventIOErrorCallback(conn, dom, srcpath, 
devalias, action, opaque):
 
 
 def myDomainEventIOErrorReasonCallback(conn, dom, srcpath, devalias, action, 
reason, opaque):
-print("myDomainEventIOErrorReasonCallback: Domain %s(%s) %s %s %d %s" % (
-dom.name(), dom.ID(), srcpath, devalias, action, ERROR_EVENTS[reason]))
+print("myDomainEventIOErrorReasonCallback: Domain %s(%s) %s %s %s %s" % (
+dom.name(), dom.ID(), srcpath, devalias, ERROR_EVENTS[action], reason))
 
 
 def myDomainEventGraphicsCallback(conn, dom, phase, localAddr, remoteAddr, 
authScheme, subject, opaque):
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] RFC: "Determine if the domain has been updated."?

2018-10-30 Thread Philipp Hahn
Hello,

<https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsUpdated> 
states:

> int   virDomainIsUpdated  (virDomainPtr dom)
>
> Determine if the domain has been updated.
> 
> dom: pointer to the domain object
> Returns: 1 if updated, 0 if not, -1 on error

Not very enlightening :-(
So what's the meaning of "updated" here: "inactive XML got changed but
the currently running VM was started from a different XML"?

Only very few drivers seem to mention it at all and they seem to mean
different things. Any nobody seems to update the variable, only 4 readers:

> $ git grep -ne '->updated'
> libxl/libxl_driver.c:4844:ret = vm->updated;
> lxc/lxc_driver.c:343:ret = obj->updated;
> qemu/qemu_driver.c:1628:ret = obj->updated;
> uml/uml_driver.c:1456:ret = obj->updated;

Thank you for the clarification.
Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen
Tel.: +49 421 22232-0
Fax : +49 421 22232-99
h...@univention.de

http://www.univention.de/
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH libvirt-python v2 07/22] event-test.py: Simplify event ID lists

2018-09-21 Thread Philipp Hahn
by directly building the list with the IDs instead of appending them
explicitly.

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 87 ++
 1 file changed, 46 insertions(+), 41 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 2dcdee3..91a7cb7 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -722,47 +722,52 @@ def main():
 
 #Add 2 lifecycle callbacks to prove this works with more than just one
 vc.domainEventRegister(myDomainEventCallback, 1)
-domcallbacks = []
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, myDomainEventCallback, 2))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_REBOOT, myDomainEventRebootCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE, myDomainEventRTCChangeCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR, myDomainEventIOErrorCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON, 
myDomainEventIOErrorReasonCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_CONTROL_ERROR, myDomainEventControlErrorCallback, 
None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_JOB, myDomainEventBlockJobCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE, myDomainEventDiskChangeCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_TRAY_CHANGE, myDomainEventTrayChangeCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_PMWAKEUP, myDomainEventPMWakeupCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND, myDomainEventPMSuspendCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE, myDomainEventBalloonChangeCallback, 
None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK, myDomainEventPMSuspendDiskCallback, 
None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED, myDomainEventDeviceRemovedCallback, 
None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2, myDomainEventBlockJob2Callback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_TUNABLE, myDomainEventTunableCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE, 
myDomainEventAgentLifecycleCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_ADDED, myDomainEventDeviceAddedCallback, 
None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION, 
myDomainEventMigrationIteration, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_JOB_COMPLETED, myDomainEventJobCompletedCallback, 
None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, 
myDomainEventDeviceRemovalFailedCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, 
myDomainEventMetadataChangeCallback, None))
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, 
myDomainEventBlockThresholdCallback, None))
-
-netcallbacks = []
-netcallbacks.append(vc.networkEventRegisterAny(None, 
libvirt.VIR_NETWORK_EVENT_ID_LIFECYCLE, myNetworkEventLifecycleCallback, None))
-
-poolcallbacks = []
-poolcallbacks.append(vc.storagePoolEventRegisterAny(None, 
libvirt.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE, 
myStoragePoolEventLifecycleCallback, None))
-poolcallbacks.append(vc.storagePoolEventRegisterAny(None, 
libvirt.VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEventRefreshCallback, 
None))
-
-devcallbacks = []
-devcallbacks.append(vc.nodeDeviceEventRegisterAny(None, 
libvirt.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE, myNodeDeviceEventLifecycleCallback, 
None))
-devcallbacks.append(vc.nodeDeviceEventRegisterAny(None, 
libvirt.VIR_NODE_DEVICE_EVENT_ID_UPDATE, myNodeDeviceEventUpdateCallback, None))
-
-seccallbacks = []
-seccallbacks.append(vc.secretEventRegisterAny(None

[libvirt] [PATCH libvirt-python v2 21/22] event-test.py: Convert CONNECTION events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 5e3b884..1e94838 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -677,15 +677,16 @@ def mySecretEventValueChanged(conn, secret, opaque):
 ##
 
 run = True
+CONNECTION_EVENTS = Description("Error", "End-of-file", "Keepalive", "Client")
+
 
 def myConnectionCloseCallback(conn, reason, opaque):
-reasonStrings = (
-"Error", "End-of-file", "Keepalive", "Client",
-)
-print("myConnectionCloseCallback: %s: %s" % (conn.getURI(), 
reasonStrings[reason]))
+print("myConnectionCloseCallback: %s: %s" % (
+conn.getURI(), CONNECTION_EVENTS[reason]))
 global run
 run = False
 
+
 def usage():
 print("usage: %s [-hdl] [uri]" % (os.path.basename(__file__),))
 print("   uri will default to qemu:///system")
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 22/22] event-test.py: Fix blanks

2018-09-21 Thread Philipp Hahn
Closer to pep8

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 97 --
 1 file changed, 71 insertions(+), 26 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 1e94838..540bf9b 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -30,11 +30,14 @@ import threading
 event_impl = "poll"
 
 do_debug = False
+
+
 def debug(msg):
 global do_debug
 if do_debug:
 print(msg)
 
+
 #
 # This general purpose event loop will support waiting for file handle
 # I/O and errors events, as well as scheduling repeatable timers with
@@ -100,7 +103,6 @@ class virEventLoopPoll:
 self.cb(self.timer,
 self.opaque)
 
-
 def __init__(self):
 self.poll = select.poll()
 self.pipetrick = os.pipe()
@@ -126,10 +128,9 @@ class virEventLoopPoll:
 # with the event loop for input events. When we need to force
 # the main thread out of a poll() sleep, we simple write a
 # single byte of data to the other end of the pipe.
-debug("Self pipe watch %d write %d" %(self.pipetrick[0], 
self.pipetrick[1]))
+debug("Self pipe watch %d write %d" % (self.pipetrick[0], 
self.pipetrick[1]))
 self.poll.register(self.pipetrick[0], select.POLLIN)
 
-
 # Calculate when the next timeout is due to occur, returning
 # the absolute timestamp for the next timeout, or 0 if there is
 # no timeout due
@@ -159,7 +160,6 @@ class virEventLoopPoll:
 return h
 return None
 
-
 # This is the heart of the event loop, performing one single
 # iteration. It asks when the next timeout is due, and then
 # calculates the maximum amount of time it is able to sleep
@@ -235,7 +235,6 @@ class virEventLoopPoll:
 finally:
 self.runningPoll = False
 
-
 # Actually run the event loop forever
 def run_loop(self):
 self.quit = False
@@ -247,7 +246,6 @@ class virEventLoopPoll:
 self.pendingWakeup = True
 os.write(self.pipetrick[1], 'c'.encode("UTF-8"))
 
-
 # Registers a new file handle 'fd', monitoring  for 'events' (libvirt
 # event constants), firing the callback  cb() when an event occurs.
 # Returns a unique integer identier for this handle, that should be
@@ -301,7 +299,7 @@ class virEventLoopPoll:
 h.set_interval(interval)
 self.interrupt()
 
-debug("Update timer %d interval %d"  % (timerID, interval))
+debug("Update timer %d interval %d" % (timerID, interval))
 break
 
 # Stop monitoring for events on the file handle
@@ -383,26 +381,32 @@ def virEventAddHandleImpl(fd, events, cb, opaque):
 global eventLoop
 return eventLoop.add_handle(fd, events, cb, opaque)
 
+
 def virEventUpdateHandleImpl(handleID, events):
 global eventLoop
 return eventLoop.update_handle(handleID, events)
 
+
 def virEventRemoveHandleImpl(handleID):
 global eventLoop
 return eventLoop.remove_handle(handleID)
 
+
 def virEventAddTimerImpl(interval, cb, opaque):
 global eventLoop
 return eventLoop.add_timer(interval, cb, opaque)
 
+
 def virEventUpdateTimerImpl(timerID, interval):
 global eventLoop
 return eventLoop.update_timer(timerID, interval)
 
+
 def virEventRemoveTimerImpl(timerID):
 global eventLoop
 return eventLoop.remove_timer(timerID)
 
+
 # This tells libvirt what event loop implementation it
 # should use
 def virEventLoopPollRegister():
@@ -413,20 +417,24 @@ def virEventLoopPollRegister():
  virEventUpdateTimerImpl,
  virEventRemoveTimerImpl)
 
+
 # Directly run the event loop in the current thread
 def virEventLoopPollRun():
 global eventLoop
 eventLoop.run_loop()
 
+
 def virEventLoopAIORun(loop):
 import asyncio
 asyncio.set_event_loop(loop)
 loop.run_forever()
 
+
 def virEventLoopNativeRun():
 while True:
 libvirt.virEventRunDefaultImpl()
 
+
 # Spawn a background thread to run the event loop
 def virEventLoopPollStart():
 global eventLoopThread
@@ -435,6 +443,7 @@ def virEventLoopPollStart():
 eventLoopThread.setDaemon(True)
 eventLoopThread.start()
 
+
 def virEventLoopAIOStart():
 global eventLoopThread
 import libvirtaio
@@ -445,6 +454,7 @@ def virEventLoopAIOStart():
 eventLoopThread.setDaemon(True)
 eventLoopThread.start()
 
+
 def virEventLoopNativeStart():
 global eventLoopThread
 libvirt.virEventRegisterDefaultImpl()
@@ -509,10 +519,13 @@ def myDomainEventCallback(conn, dom, event, detail, 
opaque):
 
 
 def myDomainEventRebootCallback(conn, dom, opaque):
-print("myDomainEventRebootCallback: Domain %s(%s)" % (dom.name(), 
dom.ID()))
+print("myDomainEventRebootCallback: Domain %s(%s)" % (
+dom

[libvirt] [PATCH libvirt-python v2 13/22] event-test.py: Convert AGENT events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 4a801b7..b559ede 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -496,14 +496,8 @@ BLOCK_JOB_TYPES = Description("unknown", "Pull", "Copy", 
"Commit", "ActiveCommit
 BLOCK_JOB_STATUS = Description("Completed", "Failed", "Canceled", "Ready")
 WATCHDOG_ACTIONS = Description("none", "Pause", "Reset", "Poweroff", 
"Shutdown", "Debug", "Inject NMI")
 ERROR_EVENTS = Description("None", "Pause", "Report")
-
-def agentLifecycleStateToString(state):
-agentStates = ( "unknown", "connected", "disconnected", )
-return agentStates[state]
-
-def agentLifecycleReasonToString(reason):
-agentReasons = ( "unknown", "domain started", "channel event", )
-return agentReasons[reason]
+AGENT_STATES = Description("unknown", "connected", "disconnected")
+AGENT_REASONS = Description("unknown", "domain started", "channel event")
 
 
 def myDomainEventCallback(conn, dom, event, detail, opaque):
@@ -572,8 +566,13 @@ def myDomainEventBlockJob2Callback(conn, dom, disk, type, 
status, opaque):
 
 def myDomainEventTunableCallback(conn, dom, params, opaque):
 print("myDomainEventTunableCallback: Domain %s(%s) %s" % (dom.name(), 
dom.ID(), params))
+
+
 def myDomainEventAgentLifecycleCallback(conn, dom, state, reason, opaque):
-print("myDomainEventAgentLifecycleCallback: Domain %s(%s) %s %s" % 
(dom.name(), dom.ID(), agentLifecycleStateToString(state), 
agentLifecycleReasonToString(reason)))
+print("myDomainEventAgentLifecycleCallback: Domain %s(%s) %s %s" % (
+dom.name(), dom.ID(), AGENT_STATES[state], AGENT_REASONS[reason]))
+
+
 def myDomainEventDeviceAddedCallback(conn, dom, dev, opaque):
 print("myDomainEventDeviceAddedCallback: Domain %s(%s) device added: %s" % 
(
 dom.name(), dom.ID(), dev))
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 08/22] event-test.py: Add class for event descriptions

2018-09-21 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 25 +
 1 file changed, 25 insertions(+)

diff --git a/examples/event-test.py b/examples/event-test.py
index 91a7cb7..d2d2c60 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -456,6 +456,31 @@ def virEventLoopNativeStart():
 ##
 # Everything that now follows is a simple demo of domain lifecycle events
 ##
+class Description(object):
+__slots__ = ('desc', 'args')
+
+def __init__(self, *args, **kwargs):
+self.desc = kwargs.get('desc')
+self.args = args
+
+def __str__(self):  # type: () -> str
+return self.desc
+
+def __getitem__(self, item):  # type: (int) -> str
+try:
+data = self.args[item]
+except IndexError:
+return self.__class__(desc=str(item))
+
+if isinstance(data, str):
+return self.__class__(desc=data)
+elif isinstance(data, (list, tuple)):
+desc, args = data
+return self.__class__(*args, desc=desc)
+
+raise TypeError(args)
+
+
 def domEventToString(event):
 domEventStrings = ( "Defined",
  "Undefined",
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 16/22] event-test.py: Convert TRAY events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 218103d..5426ecd 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -500,6 +500,7 @@ AGENT_STATES = Description("unknown", "connected", 
"disconnected")
 AGENT_REASONS = Description("unknown", "domain started", "channel event")
 GRAPHICS_PHASES = Description("Connect", "Initialize", "Disconnect")
 DISK_EVENTS = Description("Change missing on start", "Drop missing on start")
+TRAY_EVENTS = Description("Opened", "Closed")
 
 
 def myDomainEventCallback(conn, dom, event, detail, opaque):
@@ -549,7 +550,9 @@ def myDomainEventDiskChangeCallback(conn, dom, oldSrcPath, 
newSrcPath, devAlias,
 
 def myDomainEventTrayChangeCallback(conn, dom, devAlias, reason, opaque):
 print("myDomainEventTrayChangeCallback: Domain %s(%s) tray change 
devAlias: %s reason: %s" % (
-dom.name(), dom.ID(), devAlias, reason))
+dom.name(), dom.ID(), devAlias, TRAY_EVENTS[reason]))
+
+
 def myDomainEventPMWakeupCallback(conn, dom, reason, opaque):
 print("myDomainEventPMWakeupCallback: Domain %s(%s) system pmwakeup" % (
 dom.name(), dom.ID()))
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 12/22] event-test.py: Convert ERROR events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 004a263..4a801b7 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -495,6 +495,7 @@ DOM_EVENTS = Description(
 BLOCK_JOB_TYPES = Description("unknown", "Pull", "Copy", "Commit", 
"ActiveCommit")
 BLOCK_JOB_STATUS = Description("Completed", "Failed", "Canceled", "Ready")
 WATCHDOG_ACTIONS = Description("none", "Pause", "Reset", "Poweroff", 
"Shutdown", "Debug", "Inject NMI")
+ERROR_EVENTS = Description("None", "Pause", "Report")
 
 def agentLifecycleStateToString(state):
 agentStates = ( "unknown", "connected", "disconnected", )
@@ -524,8 +525,13 @@ def myDomainEventWatchdogCallback(conn, dom, action, 
opaque):
 
 def myDomainEventIOErrorCallback(conn, dom, srcpath, devalias, action, opaque):
 print("myDomainEventIOErrorCallback: Domain %s(%s) %s %s %d" % 
(dom.name(), dom.ID(), srcpath, devalias, action))
+
+
 def myDomainEventIOErrorReasonCallback(conn, dom, srcpath, devalias, action, 
reason, opaque):
-print("myDomainEventIOErrorReasonCallback: Domain %s(%s) %s %s %d %s" % 
(dom.name(), dom.ID(), srcpath, devalias, action, reason))
+print("myDomainEventIOErrorReasonCallback: Domain %s(%s) %s %s %d %s" % (
+dom.name(), dom.ID(), srcpath, devalias, action, ERROR_EVENTS[reason]))
+
+
 def myDomainEventGraphicsCallback(conn, dom, phase, localAddr, remoteAddr, 
authScheme, subject, opaque):
 print("myDomainEventGraphicsCallback: Domain %s(%s) %d %s" % (dom.name(), 
dom.ID(), phase, authScheme))
 def myDomainEventControlErrorCallback(conn, dom, opaque):
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 14/22] event-test.py: Convert GRAPHICS events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index b559ede..d8ba8c9 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -498,6 +498,7 @@ WATCHDOG_ACTIONS = Description("none", "Pause", "Reset", 
"Poweroff", "Shutdown",
 ERROR_EVENTS = Description("None", "Pause", "Report")
 AGENT_STATES = Description("unknown", "connected", "disconnected")
 AGENT_REASONS = Description("unknown", "domain started", "channel event")
+GRAPHICS_PHASES = Description("Connect", "Initialize", "Disconnect")
 
 
 def myDomainEventCallback(conn, dom, event, detail, opaque):
@@ -527,7 +528,10 @@ def myDomainEventIOErrorReasonCallback(conn, dom, srcpath, 
devalias, action, rea
 
 
 def myDomainEventGraphicsCallback(conn, dom, phase, localAddr, remoteAddr, 
authScheme, subject, opaque):
-print("myDomainEventGraphicsCallback: Domain %s(%s) %d %s" % (dom.name(), 
dom.ID(), phase, authScheme))
+print("myDomainEventGraphicsCallback: Domain %s(%s) %s %s" % (
+dom.name(), dom.ID(), GRAPHICS_PHASES[phase], authScheme))
+
+
 def myDomainEventControlErrorCallback(conn, dom, opaque):
 print("myDomainEventControlErrorCallback: Domain %s(%s)" % (dom.name(), 
dom.ID()))
 
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 02/22] event-test.py: Remove extra parenthesis

2018-09-21 Thread Philipp Hahn
Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index c17d2bb..a7c7054 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -224,7 +224,7 @@ class virEventLoopPoll:
 want = t.get_last_fired() + interval
 # Deduct 20ms, since scheduler timeslice
 # means we could be ever so slightly early
-if now >= (want-20):
+if now >= want - 20:
 debug("Dispatch timer %d now %s want %s" % (t.get_id(), 
str(now), str(want)))
 t.set_last_fired(now)
 t.dispatch()
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 15/22] event-test.py: Convert DISK events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index d8ba8c9..218103d 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -499,6 +499,7 @@ ERROR_EVENTS = Description("None", "Pause", "Report")
 AGENT_STATES = Description("unknown", "connected", "disconnected")
 AGENT_REASONS = Description("unknown", "domain started", "channel event")
 GRAPHICS_PHASES = Description("Connect", "Initialize", "Disconnect")
+DISK_EVENTS = Description("Change missing on start", "Drop missing on start")
 
 
 def myDomainEventCallback(conn, dom, event, detail, opaque):
@@ -543,7 +544,9 @@ def myDomainEventBlockJobCallback(conn, dom, disk, type, 
status, opaque):
 
 def myDomainEventDiskChangeCallback(conn, dom, oldSrcPath, newSrcPath, 
devAlias, reason, opaque):
 print("myDomainEventDiskChangeCallback: Domain %s(%s) disk change 
oldSrcPath: %s newSrcPath: %s devAlias: %s reason: %s" % (
-dom.name(), dom.ID(), oldSrcPath, newSrcPath, devAlias, reason))
+dom.name(), dom.ID(), oldSrcPath, newSrcPath, devAlias, 
DISK_EVENTS[reason]))
+
+
 def myDomainEventTrayChangeCallback(conn, dom, devAlias, reason, opaque):
 print("myDomainEventTrayChangeCallback: Domain %s(%s) tray change 
devAlias: %s reason: %s" % (
 dom.name(), dom.ID(), devAlias, reason))
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 00/22] event-test.py fixes

2018-09-21 Thread Philipp Hahn
Am 21.09.18 um 13:14 schrieb Michal Privoznik:
> On 09/20/2018 08:10 AM, Philipp Hahn wrote:
>> event-test.py is bad at handling newer livecycle events.
>> Attached are two patches to improve that.
>>
>> Philipp Hahn (2):
>>   event-test.py: Sync list of domain lifecycle events
>>   event-test.py: Future proof lifecycle event handling
>>
>>  examples/event-test.py | 18 --
>>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> ACK to the first patch, no doubt about that. However, the second one -
> I'm torn. One one hand it makes the code more future proof, on the other
> - seeing a traceback (which is easy to spot) might inspire users to post
> patches (because we are obviously not doing a good job in keeping
> event-test.py in sync with libvirt). What do you think?

Yes, I can understand it, but each time I use event-test.py (spaced months
apart) I get the next crash. So I really would like it to be more future poof.
If the number is annoying enough, any interested user is free so send a patch
to improve it.

As the pattern of printing some details is quiet common in that script, I did a
v2 and added a somehow hacky class 'Description' to simplify writing those
descriptive texts. Please have a look at the following series as an alternative.

I also found some other issues I fixed along the way.

Philipp Hahn (22):
  event-test.py: Handle closed connection
  event-test.py: Remove extra parenthesis
  event-test.py: Remove dead assignment
  event-test.py: Add missing globale statement
  event-test.py: Use __file__
  event-test.py: Merge livecycle callbacks
  event-test.py: Simplify event ID lists
  event-test.py: Add class for event descriptions
  event-test.py: Convert LIVECYCLE events
  event-test.py: Convert BLOCKJOB events
  event-test.py: Convert WATCHDOG events
  event-test.py: Convert ERROR events
  event-test.py: Convert AGENT events
  event-test.py: Convert GRAPHICS events
  event-test.py: Convert DISK events
  event-test.py: Convert TRAY events
  event-test.py: Convert NETWORK events
  event-test.py: Convert STORAGE events
  event-test.py: Convert DEVICE events
  event-test.py: Convert SECRET events
  event-test.py: Convert CONNECTION events
  event-test.py: Fix blanks

 examples/event-test.py | 446 +
 1 file changed, 262 insertions(+), 184 deletions(-)

-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 17/22] event-test.py: Convert NETWORK events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 5426ecd..2436827 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -604,27 +604,18 @@ def myDomainEventBlockThresholdCallback(conn, dom, dev, 
path, threshold, excess,
 ##
 # Network events
 ##
-def netEventToString(event):
-netEventStrings = ( "Defined",
- "Undefined",
- "Started",
- "Stopped",
-)
-return netEventStrings[event]
-
-def netDetailToString(event, detail):
-netEventStrings = (
-( "Added", ),
-( "Removed", ),
-( "Started", ),
-( "Stopped", ),
-)
-return netEventStrings[event][detail]
+NET_EVENTS = Description(
+("Defined", ("Added",)),
+("Undefined", ("Removed",)),
+("Started", ("Started",)),
+("Stopped", ("Stopped",)),
+)
+
 
 def myNetworkEventLifecycleCallback(conn, net, event, detail, opaque):
-print("myNetworkEventLifecycleCallback: Network %s %s %s" % (net.name(),
- 
netEventToString(event),
- 
netDetailToString(event, detail)))
+print("myNetworkEventLifecycleCallback: Network %s %s %s" % (
+net.name(), NET_EVENTS[event], NET_EVENTS[event][detail]))
+
 
 ##
 # Storage pool events
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 18/22] event-test.py: Convert STORAGE events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 2436827..499f434 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -620,20 +620,20 @@ def myNetworkEventLifecycleCallback(conn, net, event, 
detail, opaque):
 ##
 # Storage pool events
 ##
-def storageEventToString(event):
-storageEventStrings = ( "Defined",
-"Undefined",
-"Started",
-"Stopped",
-"Created",
-"Deleted",
-)
-return storageEventStrings[event]
+STORAGE_EVENTS = Description(
+("Defined", ()),
+("Undefined", ()),
+("Started", ()),
+("Stopped", ()),
+("Created", ()),
+("Deleted", ()),
+)
+
 
 def myStoragePoolEventLifecycleCallback(conn, pool, event, detail, opaque):
-print("myStoragePoolEventLifecycleCallback: Storage pool %s %s %d" % 
(pool.name(),
-  
storageEventToString(event),
-  
detail))
+print("myStoragePoolEventLifecycleCallback: Storage pool %s %s %s" % (
+pool.name(), STORAGE_EVENTS[event], STORAGE_EVENTS[event][detail]))
+
 
 def myStoragePoolEventRefreshCallback(conn, pool, opaque):
 print("myStoragePoolEventRefreshCallback: Storage pool %s" % pool.name())
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 06/22] event-test.py: Merge livecycle callbacks

2018-09-21 Thread Philipp Hahn
Registering the same function twice using the old domainEventRegister()
interface would not work, as the function reference is used for
un-registering.

But it is not a problem with the new interface domainEventRegisterAn(),
as that returns a unique ID.

While at it also demonstrate the 'opaque' mechanism.

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index ab1da4a..2dcdee3 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -499,15 +499,11 @@ def agentLifecycleReasonToString(reason):
 agentReasons = ( "unknown", "domain started", "channel event", )
 return agentReasons[reason]
 
-def myDomainEventCallback1 (conn, dom, event, detail, opaque):
-print("myDomainEventCallback1 EVENT: Domain %s(%s) %s %s" % (dom.name(), 
dom.ID(),
- 
domEventToString(event),
- 
domDetailToString(event, detail)))
 
-def myDomainEventCallback2 (conn, dom, event, detail, opaque):
-print("myDomainEventCallback2 EVENT: Domain %s(%s) %s %s" % (dom.name(), 
dom.ID(),
- 
domEventToString(event),
- 
domDetailToString(event, detail)))
+def myDomainEventCallback(conn, dom, event, detail, opaque):
+print("myDomainEventCallback%d EVENT: Domain %s(%s) %s %s" % (
+opaque, dom.name(), dom.ID(), domEventToString(event), 
domDetailToString(event, detail)))
+
 
 def myDomainEventRebootCallback(conn, dom, opaque):
 print("myDomainEventRebootCallback: Domain %s(%s)" % (dom.name(), 
dom.ID()))
@@ -725,9 +721,9 @@ def main():
 vc.registerCloseCallback(myConnectionCloseCallback, None)
 
 #Add 2 lifecycle callbacks to prove this works with more than just one
-vc.domainEventRegister(myDomainEventCallback1,None)
+vc.domainEventRegister(myDomainEventCallback, 1)
 domcallbacks = []
-domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, myDomainEventCallback2, None))
+domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE, myDomainEventCallback, 2))
 domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_REBOOT, myDomainEventRebootCallback, None))
 domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_RTC_CHANGE, myDomainEventRTCChangeCallback, None))
 domcallbacks.append(vc.domainEventRegisterAny(None, 
libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback, None))
@@ -784,7 +780,7 @@ def main():
 if not run:
 return
 
-vc.domainEventDeregister(myDomainEventCallback1)
+vc.domainEventDeregister(myDomainEventCallback)
 
 for id in seccallbacks:
 vc.secretEventDeregisterAny(id)
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 05/22] event-test.py: Use __file__

2018-09-21 Thread Philipp Hahn
instead of sys.argv[0]

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 646ce50..ab1da4a 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -667,7 +667,7 @@ def myConnectionCloseCallback(conn, reason, opaque):
 run = False
 
 def usage():
-print("usage: "+os.path.basename(sys.argv[0])+" [-hdl] [uri]")
+print("usage: %s [-hdl] [uri]" % (os.path.basename(__file__),))
 print("   uri will default to qemu:///system")
 print("   --help, -h   Print this help message")
 print("   --debug, -d  Print debug output")
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 09/22] event-test.py: Convert LIVECYCLE events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 42 ++
 1 file changed, 14 insertions(+), 28 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index d2d2c60..493828f 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -481,32 +481,18 @@ class Description(object):
 raise TypeError(args)
 
 
-def domEventToString(event):
-domEventStrings = ( "Defined",
- "Undefined",
- "Started",
- "Suspended",
- "Resumed",
- "Stopped",
- "Shutdown",
- "PMSuspended",
- "Crashed",
-)
-return domEventStrings[event]
-
-def domDetailToString(event, detail):
-domEventStrings = (
-( "Added", "Updated", "Renamed", "Snapshot" ),
-( "Removed", "Renamed", ),
-( "Booted", "Migrated", "Restored", "Snapshot", "Wakeup" ),
-( "Paused", "Migrated", "IOError", "Watchdog", "Restored", "Snapshot", 
"API error", "Postcopy", "Postcopy failed" ),
-( "Unpaused", "Migrated", "Snapshot", "Postcopy" ),
-( "Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", "Failed", 
"Snapshot"),
-( "Finished", "On guest request", "On host request"),
-( "Memory", "Disk" ),
-( "Panicked", ),
-)
-return domEventStrings[event][detail]
+DOM_EVENTS = Description(
+("Defined", ("Added", "Updated", "Renamed", "Snapshot")),
+("Undefined", ("Removed", "Renamed")),
+("Started", ("Booted", "Migrated", "Restored", "Snapshot", "Wakeup")),
+("Suspended", ("Paused", "Migrated", "IOError", "Watchdog", "Restored", 
"Snapshot", "API error", "Postcopy", "Postcopy failed")),
+("Resumed", ("Unpaused", "Migrated", "Snapshot", "Postcopy")),
+("Stopped", ("Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", 
"Failed", "Snapshot")),
+("Shutdown", ("Finished", "On guest request", "On host request")),
+("PMSuspended", ("Memory", "Disk")),
+("Crashed", ("Panicked",)),
+)
+
 
 def blockJobTypeToString(type):
 blockJobTypes = ( "unknown", "Pull", "Copy", "Commit", "ActiveCommit", )
@@ -526,8 +512,8 @@ def agentLifecycleReasonToString(reason):
 
 
 def myDomainEventCallback(conn, dom, event, detail, opaque):
-print("myDomainEventCallback%d EVENT: Domain %s(%s) %s %s" % (
-opaque, dom.name(), dom.ID(), domEventToString(event), 
domDetailToString(event, detail)))
+print("myDomainEventCallback%s EVENT: Domain %s(%s) %s %s" % (
+opaque, dom.name(), dom.ID(), DOM_EVENTS[event], 
DOM_EVENTS[event][detail]))
 
 
 def myDomainEventRebootCallback(conn, dom, opaque):
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 19/22] event-test.py: Convert DEVICE events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 499f434..0a1d06d 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -641,16 +641,16 @@ def myStoragePoolEventRefreshCallback(conn, pool, opaque):
 ##
 # Node device events
 ##
-def nodeDeviceEventToString(event):
-nodeDeviceEventStrings = ( "Created",
-   "Deleted",
-)
-return nodeDeviceEventStrings[event]
+DEVICE_EVENTS = Description(
+("Created", ()),
+("Deleted", ()),
+)
+
 
 def myNodeDeviceEventLifecycleCallback(conn, dev, event, detail, opaque):
-print("myNodeDeviceEventLifecycleCallback: Node device  %s %s %d" % 
(dev.name(),
-  
nodeDeviceEventToString(event),
-  
detail))
+print("myNodeDeviceEventLifecycleCallback: Node device  %s %s %s" % (
+dev.name(), DEVICE_EVENTS[event], DEVICE_EVENTS[event][detail]))
+
 
 def myNodeDeviceEventUpdateCallback(conn, dev, opaque):
 print("myNodeDeviceEventUpdateCallback: Node device %s" % dev.name())
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 20/22] event-test.py: Convert SECRET events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 0a1d06d..5e3b884 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -658,16 +658,16 @@ def myNodeDeviceEventUpdateCallback(conn, dev, opaque):
 ##
 # Secret events
 ##
-def secretEventToString(event):
-secretEventStrings = ( "Defined",
-   "Undefined",
-)
-return secretEventStrings[event]
+SECRET_EVENTS = Description(
+("Defined", ()),
+("Undefined", ()),
+)
+
 
 def mySecretEventLifecycleCallback(conn, secret, event, detail, opaque):
-print("mySecretEventLifecycleCallback: Secret %s %s %d" % 
(secret.UUIDString(),
-   
secretEventToString(event),
-   detail))
+print("mySecretEventLifecycleCallback: Secret %s %s %s" % (
+secret.UUIDString(), SECRET_EVENTS[event], 
SECRET_EVENTS[event][detail]))
+
 
 def mySecretEventValueChanged(conn, secret, opaque):
 print("mySecretEventValueChanged: Secret %s" % secret.UUIDString())
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 10/22] event-test.py: Convert BLOCKJOB events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 493828f..46a8db8 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -492,15 +492,8 @@ DOM_EVENTS = Description(
 ("PMSuspended", ("Memory", "Disk")),
 ("Crashed", ("Panicked",)),
 )
-
-
-def blockJobTypeToString(type):
-blockJobTypes = ( "unknown", "Pull", "Copy", "Commit", "ActiveCommit", )
-return blockJobTypes[type]
-
-def blockJobStatusToString(status):
-blockJobStatus = ( "Completed", "Failed", "Canceled", "Ready", )
-return blockJobStatus[status]
+BLOCK_JOB_TYPES = Description("unknown", "Pull", "Copy", "Commit", 
"ActiveCommit")
+BLOCK_JOB_STATUS = Description("Completed", "Failed", "Canceled", "Ready")
 
 def agentLifecycleStateToString(state):
 agentStates = ( "unknown", "connected", "disconnected", )
@@ -533,8 +526,13 @@ def myDomainEventGraphicsCallback(conn, dom, phase, 
localAddr, remoteAddr, authS
 print("myDomainEventGraphicsCallback: Domain %s(%s) %d %s" % (dom.name(), 
dom.ID(), phase, authScheme))
 def myDomainEventControlErrorCallback(conn, dom, opaque):
 print("myDomainEventControlErrorCallback: Domain %s(%s)" % (dom.name(), 
dom.ID()))
+
+
 def myDomainEventBlockJobCallback(conn, dom, disk, type, status, opaque):
-print("myDomainEventBlockJobCallback: Domain %s(%s) %s on disk %s %s" % 
(dom.name(), dom.ID(), blockJobTypeToString(type), disk, 
blockJobStatusToString(status)))
+print("myDomainEventBlockJobCallback: Domain %s(%s) %s on disk %s %s" % (
+dom.name(), dom.ID(), BLOCK_JOB_TYPES[type], disk, 
BLOCK_JOB_STATUS[status]))
+
+
 def myDomainEventDiskChangeCallback(conn, dom, oldSrcPath, newSrcPath, 
devAlias, reason, opaque):
 print("myDomainEventDiskChangeCallback: Domain %s(%s) disk change 
oldSrcPath: %s newSrcPath: %s devAlias: %s reason: %s" % (
 dom.name(), dom.ID(), oldSrcPath, newSrcPath, devAlias, reason))
@@ -555,8 +553,13 @@ def myDomainEventPMSuspendDiskCallback(conn, dom, reason, 
opaque):
 def myDomainEventDeviceRemovedCallback(conn, dom, dev, opaque):
 print("myDomainEventDeviceRemovedCallback: Domain %s(%s) device removed: 
%s" % (
 dom.name(), dom.ID(), dev))
+
+
 def myDomainEventBlockJob2Callback(conn, dom, disk, type, status, opaque):
-print("myDomainEventBlockJob2Callback: Domain %s(%s) %s on disk %s %s" % 
(dom.name(), dom.ID(), blockJobTypeToString(type), disk, 
blockJobStatusToString(status)))
+print("myDomainEventBlockJob2Callback: Domain %s(%s) %s on disk %s %s" % (
+dom.name(), dom.ID(), BLOCK_JOB_TYPES[type], disk, 
BLOCK_JOB_STATUS[status]))
+
+
 def myDomainEventTunableCallback(conn, dom, params, opaque):
 print("myDomainEventTunableCallback: Domain %s(%s) %s" % (dom.name(), 
dom.ID(), params))
 def myDomainEventAgentLifecycleCallback(conn, dom, state, reason, opaque):
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 03/22] event-test.py: Remove dead assignment

2018-09-21 Thread Philipp Hahn
variable is unused

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index a7c7054..1f34930 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -207,7 +207,7 @@ class virEventLoopPoll:
 # the data just continue
 if fd == self.pipetrick[0]:
 self.pendingWakeup = False
-data = os.read(fd, 1)
+os.read(fd, 1)
 continue
 
 h = self.get_handle_by_fd(fd)
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 04/22] event-test.py: Add missing globale statement

2018-09-21 Thread Philipp Hahn
to fix loop termination on exit.

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/event-test.py b/examples/event-test.py
index 1f34930..646ce50 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -663,6 +663,7 @@ def myConnectionCloseCallback(conn, reason, opaque):
 "Error", "End-of-file", "Keepalive", "Client",
 )
 print("myConnectionCloseCallback: %s: %s" % (conn.getURI(), 
reasonStrings[reason]))
+global run
 run = False
 
 def usage():
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 11/22] event-test.py: Convert WATCHDOG events

2018-09-21 Thread Philipp Hahn
to use new Description class

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 46a8db8..004a263 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -494,6 +494,7 @@ DOM_EVENTS = Description(
 )
 BLOCK_JOB_TYPES = Description("unknown", "Pull", "Copy", "Commit", 
"ActiveCommit")
 BLOCK_JOB_STATUS = Description("Completed", "Failed", "Canceled", "Ready")
+WATCHDOG_ACTIONS = Description("none", "Pause", "Reset", "Poweroff", 
"Shutdown", "Debug", "Inject NMI")
 
 def agentLifecycleStateToString(state):
 agentStates = ( "unknown", "connected", "disconnected", )
@@ -515,8 +516,11 @@ def myDomainEventRebootCallback(conn, dom, opaque):
 def myDomainEventRTCChangeCallback(conn, dom, utcoffset, opaque):
 print("myDomainEventRTCChangeCallback: Domain %s(%s) %d" % (dom.name(), 
dom.ID(), utcoffset))
 
+
 def myDomainEventWatchdogCallback(conn, dom, action, opaque):
-print("myDomainEventWatchdogCallback: Domain %s(%s) %d" % (dom.name(), 
dom.ID(), action))
+print("myDomainEventWatchdogCallback: Domain %s(%s) %s" % (
+dom.name(), dom.ID(), WATCHDOG_ACTIONS[action]))
+
 
 def myDomainEventIOErrorCallback(conn, dom, srcpath, devalias, action, opaque):
 print("myDomainEventIOErrorCallback: Domain %s(%s) %s %s %d" % 
(dom.name(), dom.ID(), srcpath, devalias, action))
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python v2 01/22] event-test.py: Handle closed connection

2018-09-21 Thread Philipp Hahn
If libvirtd terminates while event-test.py has an open connection to it,
it will crash with the following traceback:

> myConnectionCloseCallback: qemu:///session: Error
> Exception in thread libvirtEventLoop:
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
> self.run()
>   File "/usr/lib/python2.7/threading.py", line 754, in run
> self.__target(*self.__args, **self.__kwargs)
>   File "examples/event-test.py", line 424, in virEventLoopPollRun
> eventLoop.run_loop()
>   File "examples/event-test.py", line 242, in run_loop
> self.run_once()
>   File "examples/event-test.py", line 187, in run_once
> libvirt.virEventInvokeFreeCallback(opaque)
> AttributeError: 'module' object has no attribute 'virEventInvokeFreeCallback'
>
> libvirt: XML-RPC error : internal error: client socket is closed
> Traceback (most recent call last):
>   File "examples/event-test.py", line 872, in 
> main()
>   File "examples/event-test.py", line 854, in main
> vc.secretEventDeregisterAny(id)
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4987, in 
> secretEventDeregisterAny
> if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() 
> failed', conn=self)
> libvirt.libvirtError: internal error: client socket is closed
> Closing qemu:///session

Skip unregistering the event callbacks and closing the connection if the
connection is already broken / closed.

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 04310e1..c17d2bb 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -716,7 +716,8 @@ def main():
 old_exitfunc = getattr(sys, 'exitfunc', None)
 def exit():
 print("Closing " + vc.getURI())
-vc.close()
+if run:
+vc.close()
 if (old_exitfunc): old_exitfunc()
 sys.exitfunc = exit
 
@@ -777,6 +778,11 @@ def main():
 count = count + 1
 time.sleep(1)
 
+# If the connection was closed, we cannot unregister anything.
+# Just abort now.
+if not run:
+return
+
 vc.domainEventDeregister(myDomainEventCallback1)
 
 for id in seccallbacks:
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] missing libvirt events related to snapshots and media-change for inactive VMs?

2018-09-21 Thread Philipp Hahn
Hello,

Am 20.09.18 um 08:10 schrieb Philipp Hahn:
> event-test.py is bad at handling newer livecycle events.
> Attached are two patches to improve that.
> 
> Philipp Hahn (2):
>   event-test.py: Sync list of domain lifecycle events
>   event-test.py: Future proof lifecycle event handling
> 
>  examples/event-test.py | 18 --
>  1 file changed, 12 insertions(+), 6 deletions(-)

While looking at the events reported by said script I noticed that there
are no events for creating / deleting snapshot, at leat when the VM is
inactive. For an active VM Qemu reports several events:
  VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT
  VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT
  VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT
  VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT
  VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT

Also there is no event generated when doing "virsh change-media" for an
inactive domain; I would have expected an
VIR_DOMAIN_EVENT_DEFINED_UPDATED event.
For an active domain you get the
libvirt.VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN / CLOSE events.

My current work-around is to do polling, but I want to get rid of that.
Did I miss something or is it okay to add events for tha?

Thanks in advance.
Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python 0/2] event-test.py fixes

2018-09-20 Thread Philipp Hahn
Hello,

event-test.py is bad at handling newer livecycle events.
Attached are two patches to improve that.

Philipp Hahn (2):
  event-test.py: Sync list of domain lifecycle events
  event-test.py: Future proof lifecycle event handling

 examples/event-test.py | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python 1/2] event-test.py: Sync list of domain lifecycle events

2018-09-20 Thread Philipp Hahn
Add new events to prevent crash:
> raceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4601, in 
> _dispatchDomainEventCallbacks
> cb(self, virDomain(self, _obj=dom), event, detail, opaque)
>   File "libvirt-python/examples/event-test.py", line 505, in 
> myDomainEventCallback1
> domDetailToString(event, detail)))
>   File "libvirt-python/examples/event-test.py", line 484, in domDetailToString
> return domEventStrings[event][detail]
> IndexError: tuple index out of range

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 281e661..04310e1 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -471,11 +471,11 @@ def domEventToString(event):
 
 def domDetailToString(event, detail):
 domEventStrings = (
-( "Added", "Updated" ),
-( "Removed", ),
+( "Added", "Updated", "Renamed", "Snapshot" ),
+( "Removed", "Renamed", ),
 ( "Booted", "Migrated", "Restored", "Snapshot", "Wakeup" ),
-( "Paused", "Migrated", "IOError", "Watchdog", "Restored", "Snapshot", 
"API error" ),
-( "Unpaused", "Migrated", "Snapshot" ),
+( "Paused", "Migrated", "IOError", "Watchdog", "Restored", "Snapshot", 
"API error", "Postcopy", "Postcopy failed" ),
+( "Unpaused", "Migrated", "Snapshot", "Postcopy" ),
 ( "Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", "Failed", 
"Snapshot"),
 ( "Finished", "On guest request", "On host request"),
 ( "Memory", "Disk" ),
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH libvirt-python 2/2] event-test.py: Future proof lifecycle event handling

2018-09-20 Thread Philipp Hahn
Catch exception if the event or details is outside the known type to
prevent a traceback like the following:
> raceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/libvirt.py", line 4601, in 
> _dispatchDomainEventCallbacks
> cb(self, virDomain(self, _obj=dom), event, detail, opaque)
>   File "libvirt-python/examples/event-test.py", line 505, in 
> myDomainEventCallback1
> domDetailToString(event, detail)))
>   File "libvirt-python/examples/event-test.py", line 484, in domDetailToString
> return domEventStrings[event][detail]
> IndexError: tuple index out of range

Signed-off-by: Philipp Hahn 
---
 examples/event-test.py | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/examples/event-test.py b/examples/event-test.py
index 04310e1..4632110 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -467,7 +467,10 @@ def domEventToString(event):
  "PMSuspended",
  "Crashed",
 )
-return domEventStrings[event]
+try:
+return domEventStrings[event]
+except IndexError:
+return 'Unknown domain event %d' % (event,)
 
 def domDetailToString(event, detail):
 domEventStrings = (
@@ -481,7 +484,10 @@ def domDetailToString(event, detail):
 ( "Memory", "Disk" ),
 ( "Panicked", ),
 )
-return domEventStrings[event][detail]
+try:
+return domEventStrings[event][detail]
+except IndexError:
+return 'Unknown domain event %d detail %d' % (event, detail)
 
 def blockJobTypeToString(type):
 blockJobTypes = ( "unknown", "Pull", "Copy", "Commit", "ActiveCommit", )
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] How to best handle the reoccurring of rom changes breaking cross version migrations?

2017-11-03 Thread Philipp Hahn
Hello

Am 03.11.2017 um 08:30 schrieb Christian Ehrhardt:
> On Thu, Nov 2, 2017 at 4:34 PM, Daniel P. Berrange  
> wrote:
>>
>> On Thu, Nov 02, 2017 at 04:14:06PM +0100, Christian Ehrhardt wrote:
>>> Ping - since there wasn't any reply so far - any best practices one could
>>> share?
>>>
>>> Let me add a TL;DR:
>>> - bump of ipxe rom versions change the size of virtio-net-pci.rom
>>> - that breaks on migration "Length mismatch"
>>>
>>> I'd guess the size of that rom has to be fixed up on the fly, but if that
>>> is really ok and how/where is the question.
>>
>> The actual ROM contents will be transferred in the migration stream, so
>> the fact that the target host has ROMs with different content is not
>> important. The key thing that matters is that QEMU the target host loads
>> the ROMs at the same location, so that when the ROM contents is overwritten
>> with data from the incoming migration scheme, it all ends up at the same
>> place as it was on the source.
> 
> 
> Thanks Daniel for your answer, although you try to kill my remaining
> hopes of a better solution :-)
> But if the actual ROM content is migrated over anyway "all I'd have to
> do" is to make clear that the newer system (qemu) knows that the
> incoming rom has a different size than it thinks.
> I thought that was what the machine types and their mechanisms were
> for, but so far I only scratched like 10% of those - maybe they don't
> cover these rom sizes?

The problem is that libvirt launches a qemu process without knowing
those details.
Later when you try to restore an old snapshot or try to do a live
migration, the newly spawned qemu process must have the same layout to
be able to load the old VMState.

Qemu has gone through several such changes and is worsened by the fact,
that distributions like Debian use their own ROM files, which might be
different from the sizes shipped with Qemu.
For that reason we (Univention) still ship the old ROM images next to
the new ones and carry the attached patch to switch between them based
on the model. Maybe that works for you, too.

One more warning (we experiences): Even if the sizes are the same, live
migration can still fail afterwards: We have observed several cases,
where a migrated VM carried an old version of SeaBIOS, which fails when
you reboot the VM. We traced that down to Qemu implementing a new
feature (SMM), which was not supported by the old SeaBIOS and then got
it wrong after reboot only.

Hope that helps.

Philipp
Bug #24702: Fix PXE ROM size mismatch

For pc-0.14 and older use the PXE ROMs from the deprecated etherboot-qemu
package, which have different sizes. Without the patch the virtual PC gets
build with the current ROM sizes. Loading then fails because the stored PCI ROM
BAR size mismatches the configured size.
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -433,6 +433,30 @@ static QEMUMachine pc_machine_v0_15 = {
 .driver   = "virtio-balloon-pci",\
 .property = "event_idx",\
 .value= "off",\
+},{\
+.driver   = "ne2000",\
+.property = "romfile",\
+.value   = "/usr/lib/etherboot/rtl8029.rom",\
+},{\
+.driver   = "rtl8139",\
+.property = "romfile",\
+.value   = "/usr/lib/etherboot/rtl8139.rom",\
+},{\
+.driver   = "e1000",\
+.property = "romfile",\
+.value   = "/usr/lib/etherboot/e1000-82540em.rom",\
+},{\
+.driver   = "pcnet",\
+.property = "romfile",\
+.value   = "/usr/lib/etherboot/pcnet32.rom",\
+},{\
+.driver   = "ne2k-isa",\
+.property = "romfile",\
+.value   = "/usr/lib/etherboot/ne.rom",\
+},{\
+.driver   = "virtio-net-pci",\
+.property = "romfile",\
+.value   = "/usr/lib/etherboot/virtio-net.rom",\
 }
 
 static QEMUMachine pc_machine_v0_14 = {
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu: Honour

2017-08-03 Thread Philipp Hahn
Hello,

Am 03.08.2017 um 09:36 schrieb Michal Privoznik:
> https://bugzilla.redhat.com/show_bug.cgi?id=1476866
> 
> For some reason, we completely ignore  setting for
> domains. The implementation is simply not there. It never was.
> However, things are slightly more complicated. QEMU sends us two
> RESET events on domain reboot. Fortunately, the event contains
> this 'guest' field telling us who initiated the reboot. And since
> we don't want to destroy the domain if the reset is initiated by
> a user, we have to ignore those events. Whatever, just look at
> the code.

White you are at "QEMU reset": From Xen I remember that on reboot a new
qemu-dm (Device Model) is created - if I remember correctly - for both
PV and HV.
For QEMU the old qemu process is reused and the reset is done by SeaBios
inside the VM. If would be cool if there was an option to kill the old
qemu process and start a new qemu process (with an updated
configuration) on reboot.
I sometimes have the situation where the libvirt part is done by one
group of admins, while the guest OS and everything within in VM is done
by some other group of persons. Currently they always have to coordinate
a time, where the internal group does initiate the guest OS shutdown and
the libvirt admins then updates the configuration and starts the VM again.
It would be nice if I could update the config "just now" and then tell
the OS group "just do the reboot when your schedule permits it - you
will then get your updates configuration automatically."

Or is this already there and I missed it?

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH glib] Don't set LC_ALL=C during build as that breaks python apps

2017-07-25 Thread Philipp Hahn
Hello,

Am 25.07.2017 um 14:07 schrieb Daniel P. Berrange:
> Setting LC_ALL=C breaks python apps doing I/O on UTF-8 source
> files. In particular this broke glib-mkenums
> 
>   GEN  libvirt-gconfig-enum-types.h
> Traceback (most recent call last):
>   File "/usr/bin/glib-mkenums", line 669, in 
> process_file(fname)
>   File "/usr/bin/glib-mkenums", line 406, in process_file
> line = curfile.readline()
>   File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
> return codecs.ascii_decode(input, self.errors)[0]
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 849: 
> ordinal not in range(128)

What about using "C.UTF-8" instead, which us the same as "C" but with
"UTF-8" encoding?
Maybe ancient RedHat still doesn't know about it ...

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [BUG] duplicate suspend/resume lifecycle events with QEMU

2017-06-13 Thread Philipp Hahn
Hello,

Am 13.06.2017 um 06:13 schrieb Philipp Hahn:
> I'm using the libvirt event mechanism and noticed, that several events
> are reported twice:
...
>> $ virsh  event --loop --event lifecycle
>> event 'lifecycle' for domain installer: Started Booted
>> event 'lifecycle' for domain installer: Suspended Paused
>> event 'lifecycle' for domain installer: Resumed Unpaused
>> event 'lifecycle' for domain installer: Resumed Unpaused
>> event 'lifecycle' for domain installer: Suspended Paused
>> event 'lifecycle' for domain installer: Suspended Paused
>> event 'lifecycle' for domain installer: Stopped Destroyed
...
> Looking at src/qemu/qemu_monitor_json.c:qemuMonitorJSONIOProcessEvent:

That was not the cause. Using gdb shows the real duplicator:

Breakpoint 9, virDomainEventLifecycleNew (id=10, name=0x7fffd825e700
"win8", uuid=0x7fffd825e128 "o8r\204\344\372F\263\214oGF\325@=9",
type=4, detail=0) at ../../../src/conf/domain_event.c:657
657 }
$13 = {parent = {parent = {parent = {u = {dummy_align1 = 7700611138,
dummy_align2 = 0x1cafe0042, s = {magic = 3405643842, refs = 1}}, klass =
0x558304e0}, eventID = 0, meta = {id = 10, name = 0x558304a0 "win8",
uuid = "o8r\204\344\372F\263\214oGF\325@=9", key =
0x55831270 "6f387284-e4fa-46b3-8c6f-4746d5403d39"}, remoteID = -1,
dispatch = 0x777d85c0 }, dummy =
false}, type = 4, detail = 0}
> (gdb) bt
> #0  virDomainEventLifecycleNew (id=10, name=0x7fffd825e700 "win8", 
> uuid=0x7fffd825e128 "o8r\204\344\372F\263\214oGF\325@=9", type=4, detail=0) 
> at ../../../src/conf/domain_event.c:657
> #1  0x7fffe52fefef in qemuProcessHandleResume (mon=0x0, 
> vm=0x7fffd825ec80, opaque=0x7fffd8101b90) at 
> ../../../src/qemu/qemu_process.c:773
> #2  0x7fffe531c9c2 in qemuMonitorEmitResume (mon=0x7fffdea0) at 
> ../../../src/qemu/qemu_monitor.c:1330
> #3  0x7fffe532fd0b in qemuMonitorJSONIOProcessEvent (obj=, 
> mon=) at ../../../src/qemu/qemu_monitor_json.c:178
> #4  qemuMonitorJSONIOProcessLine (mon=0x0, line=0x7fffe55d50e0 
> <eventHandlers+224> "}\242\071\345\377\177", msg=0xe) at 
> ../../../src/qemu/qemu_monitor_json.c:207
> #5  0x7fffe532fedb in qemuMonitorJSONIOProcess (mon=0x0, 
> data=0x7774f9b0  "H\203\354\bH\215=\245\315G", len=119, 
> msg=0x0) at ../../../src/qemu/qemu_monitor_json.c:249
> #6  0x7fffe531b293 in qemuMonitorIOProcess (mon=) at 
> ../../../src/qemu/qemu_monitor.c:432
> #7  qemuMonitorIO (watch=18, fd=-134433088, events=1, opaque=0x7fffdea0) 
> at ../../../src/qemu/qemu_monitor.c:686
> #8  0x77735446 in virEventPollDispatchHandles (fds=, 
> nfds=) at ../../../src/util/vireventpoll.c:508
> #9  virEventPollRunOnce () at ../../../src/util/vireventpoll.c:657
> #10 0x77733b71 in virEventRunDefaultImpl () at 
> ../../../src/util/virevent.c:314
> #11 0x7788aced in virNetDaemonRun (dmn=0x55807d60) at 
> ../../../src/rpc/virnetdaemon.c:818
> #12 0x5556e486 in main (argc=-1, argv=0x0) at 
> ../../../daemon/libvirtd.c:1547
> (gdb) c

This is the QEMU monitor event handler

> Continuing.
> [Switching to Thread 0x7fffeee05700 (LWP 11193)]
> 
> Breakpoint 9, virDomainEventLifecycleNew (id=10, name=0x7fffd825e700 "win8", 
> uuid=0x7fffd825e128 "o8r\204\344\372F\263\214oGF\325@=9", type=4, detail=0) 
> at ../../../src/conf/domain_event.c:657
> 657 }
> $14 = {parent = {parent = {parent = {u = {dummy_align1 = 7700611138, 
> dummy_align2 = 0x1cafe0042, s = {magic = 3405643842, refs = 1}}, klass = 
> 0x558304e0}, eventID = 0, meta = {id = 10, name = 0x7fffbc000a30 "win8", 
> uuid = "o8r\204\344\372F\263\214oGF\325@=9", key = 0x7fffbc000b70 
> "6f387284-e4fa-46b3-8c6f-4746d5403d39"}, remoteID = -1, dispatch = 
> 0x777d85c0 }, dummy = false}, type = 
> 4, detail = 0}
> (gdb) bt
> #0  virDomainEventLifecycleNew (id=10, name=0x7fffd825e700 "win8", 
> uuid=0x7fffd825e128 "o8r\204\344\372F\263\214oGF\325@=9", type=4, detail=0) 
> at ../../../src/conf/domain_event.c:657
> #1  0x7fffe53579dc in qemuDomainResume (dom=0x7fffbc000930) at 
> ../../../src/qemu/qemu_driver.c:1965
> #2  0x77818acf in virDomainResume (domain=0x7fffbc000930) at 
> ../../../src/libvirt-domain.c:679
> #3  0x55595a3e in remoteDispatchDomainResume (server=, 
> msg=, args=, rerr=, 
> client=) at ../../../daemon/remote_dispatch.h:9132
> #4  remoteDispatchDomainResumeHelper (server=0x55806d30, 
> client=0x55832970, msg=0x55837910, rerr=0x7fffeee04cc0, 
> args=0x7fffbc000930, ret=0x7fffbc000fc0) at 
> ../../../daemon/remote_dispatch.h:9108
> #5  0x77890939

[libvirt] [RFC] duplicate suspend/resume lifecycle events with QEMU

2017-06-12 Thread Philipp Hahn
gt;  
> 1268  long long seconds, unsigned int micros,
> 1269  const char *details)
...
> 1274 QEMU_MONITOR_CALLBACK(mon, ret, domainEvent, mon->vm, event, seconds,
> 1275   micros, details);
...
> 1325 qemuMonitorEmitResume(qemuMonitorPtr mon)
> 1330 QEMU_MONITOR_CALLBACK(mon, ret, domainResume, mon->vm);

but this doesn't yet completely explain, why only some events are
reported twice.

Is there some way to get rid of the duplication (in Python) or at least
to distinguish them, so I can ignore the second one?


I've observed this behaviour with both Debian-Jessie

> Compiled against library: libvirt 1.2.9
> Using library: libvirt 1.2.9
> Using API: QEMU 1.2.9
> Running hypervisor: QEMU 2.6.0

and also with the newer Debian-Sid

> Compiled against library: libvirt 3.0.0
> Using library: libvirt 3.0.0
> Using API: QEMU 3.0.0
> Running hypervisor: QEMU 2.8.1

Thank you in advance.

Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen
Tel.: +49 421 22232-0
Fax : +49 421 22232-99
h...@univention.de

http://www.univention.de/
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] qemu/doc: Fix function name for handling events

2017-06-12 Thread Philipp Hahn
Insert missing "IO" into function name.
---
 src/qemu/EVENTHANDLERS.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/EVENTHANDLERS.txt b/src/qemu/EVENTHANDLERS.txt
index 79c1505caa..c7798d600b 100644
--- a/src/qemu/EVENTHANDLERS.txt
+++ b/src/qemu/EVENTHANDLERS.txt
@@ -17,7 +17,7 @@ other qemu events in the future.
 
 
 Any event emitted by qemu is received by
-qemu_monitor_json.c:qemuMonitorJSONProcessEvent(). It looks up the
+qemu_monitor_json.c:qemuMonitorJSONIOProcessEvent(). It looks up the
 event by name in the table eventHandlers (in the same file), which
 should have an entry like this for each event that libvirt
 understands:
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v3] doc: Correct the default werror policy

2017-03-08 Thread Philipp Hahn
Hello,

Am 08.03.2017 um 17:28 schrieb Martin Kletzander:
> On Wed, Mar 01, 2017 at 08:44:54PM +0100, Philipp Hahn wrote:
>> The documentation is plain wrong about the default write_error policy,
>> as its only implemented by QEMU (src/vz/vz_utils.c is the only other
>> case, which simply explodes, is anything except other then
>> VIR_DOMAIN_DISK_ERROR_POLICY_DEFAULT is used).
>>
> 
> Sounds like bashing about some problem.  Is there any bug somewhere?  It
> does not add any useful information to the commit message, so I'll strip
> it off before pushing.

My problem is, that the documentation does not match the implementation
and from reading that documentation you get a wrong impression:

The documentation claims, that the default is "report", while the QEMU
internal default is "ENOSPC".
This has a sever difference, namely that your VM gets suspended when
your host systems file systems get full. This is a good default, as you
don't loose any data, but on the other hand your VM disappears from the
network until you free some space and resume the VM.

I have seen this happen multiple times and I know the behaviour by now,
but others have reported this "strange" behaviour to me several times:
they keep wondering why their VM suddenly gets paused, while the libvirt
documentation tells them that the VM would see all errors (report).

So lets please tell those people to look at the QEMU code and not the
libvirt code.

> So my question is; is there anything in that driver that needs fixing
> WRT this patch?

The default is okay and the most save regarding data loss, but might not
be okay if service availability is more important to you.

We can even apply the following change on top, as QEMU is the only
driver implementing a configurable error policy:

> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index dc44a55..025007f 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -2744,13 +2744,14 @@
>  The optional error_policy attribute controls
>  how the hypervisor will behave on a disk read or write
>  error, possible values are "stop", "report", "ignore", and
> -"enospace".Since 0.8.0, "report" since
> +"enospace".Since 0.8.0 (QEMU and KVM only), 
> "report" since
>  0.9.7 The default is left to the discretion of the
>  hypervisor.
>  There is also an
>  optional rerror_policy that controls behavior
>  for read errors only. Since
> -0.9.7. If no rerror_policy is given, error_policy
> +0.9.7 (QEMU and KVM only).
> +If no rerror_policy is given, error_policy
>  is used for both read and write errors. If rerror_policy
>  is given, it overrides the error_policy for
>  read errors. Also note that "enospace" is not a valid

And "report" is the default for QEMU since
release_0_10_0~298 ,which made the policy configurable, but the commit
message claims "report" was even the default before that:

> commit 428c570512c1d9298b52dc9fc1a541b542a5c117
> Author: aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
> Date:   Wed Jan 21 18:59:04 2009 +
> 
> Stop VM on ENOSPC error. (Gleb Natapov)
> 
> This version of the patch adds new option "werror" to -drive flag.
> Possible values are:
> 
> report- report errors to a guest as IO errors
> ignore- continue as if nothing happened
> stop  - stop VM on any error and retry last command on resume
> enospc- stop vm on ENOSPC error and retry last command on resume
> all other errors are reported to a guest.
> 
> Default is "report" to maintain current behaviour.
> 
> Signed-off-by: Gleb Natapov <g...@redhat.com>
> Signed-off-by: Anthony Liguori <aligu...@us.ibm.com>
> 
> 
> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6388 
> c046a42c-6fe2-441c-8c8c-71466251a162

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2] doc: fix writing of QEMU

2017-03-07 Thread Philipp Hahn
QEMU should be written all upper or all lower case.
---
v2: Drop docs/news-* as they are historic.
Drop po/*.po files as they are from extern.

 ChangeLog-old |  4 ++--
 docs/formatnwfilter.html.in   |  6 +++---
 docs/storage.html.in  | 12 ++--
 libvirt.spec.in   |  2 +-
 po/libvirt.pot|  2 +-
 src/cpu/cpu_s390.c|  2 +-
 src/qemu/MIGRATION.txt|  2 +-
 src/qemu/THREADS.txt  |  2 +-
 src/qemu/qemu.conf|  4 ++--
 src/qemu/qemu_command.c   |  2 +-
 src/qemu/qemu_domain.h|  2 +-
 src/qemu/qemu_monitor.c   |  6 +++---
 src/qemu/qemu_parse_command.c |  2 +-
 13 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/ChangeLog-old b/ChangeLog-old
index e38a9bd..b903b54 100644
--- a/ChangeLog-old
+++ b/ChangeLog-old
@@ -576,7 +576,7 @@ Fri May 29 10:00:01 EDT 2009 Cole Robinson 

 Fri May 29 15:29:32 CEST 2009 Daniel Veillard 
 
* src/qemu_conf.c docs/schemas/domain.rng
- tests/capabilityschemadata/caps-qemu-kvm.xml: PPC Qemu Machine Type
+ tests/capabilityschemadata/caps-qemu-kvm.xml: PPC QEMU Machine Type
  changed from g3bw to g3beige some time ago, patch by Thomas Baker
 
 Fri May 29 14:26:30 BST 2009 Daniel P. Berrange 
@@ -8397,7 +8397,7 @@ Thu May 15 09:12:08 CEST 2008 Jim Meyering 

 Thu May 15 15:07:49 JST 2008 Atsushi SAKAI 
 
* qemud/libvirtd.init.in: change libvirtd description
-   which supports various guest not only Qemu
+   which supports various guest not only QEMU
* docs/*: typo fixes
* include/libvirt/libvirt.h, include/libvirt/libvirt.h.in,
qemud/event.c, qemud/qemud.c, qemud/remote.c,
diff --git a/docs/formatnwfilter.html.in b/docs/formatnwfilter.html.in
index 7ea69b5..0d32893 100644
--- a/docs/formatnwfilter.html.in
+++ b/docs/formatnwfilter.html.in
@@ -40,7 +40,7 @@
   of all running virtual machines that reference this filter are updated.
   
   Network filtering support is available since 0.8.1
-  (Qemu, KVM)
+  (QEMU, KVM)
 
 
 Concepts
@@ -2064,7 +2064,7 @@ echo 3 > /proc/sys/net/netfilter/nf_conntrack_icmp_timeout
  traffic you want to allow does pass.
  
  The network filtering subsystem is currently only available on
- Linux hosts and only works for Qemu and KVM type of virtual machines.
+ Linux hosts and only works for QEMU and KVM type of virtual machines.
  On Linux
  it builds upon the support for ebtables, iptables
   and ip6tables and makes use of their features.
@@ -2265,7 +2265,7 @@ echo 3 > /proc/sys/net/netfilter/nf_conntrack_icmp_timeout
  to the incoming and outgoing direction. All this is related to the ftp
  data traffic originating from TCP port 20 of the VM. This then leads to
  the following solution
- (since 0.8.5 (Qemu, KVM, UML)):
+ (since 0.8.5 (QEMU, KVM, UML)):
 
 
 filter name='test-eth0'
diff --git a/docs/storage.html.in b/docs/storage.html.in
index 10b1f1f..6ff38a5 100644
--- a/docs/storage.html.in
+++ b/docs/storage.html.in
@@ -549,13 +549,13 @@
   This storage driver provides a pool which contains all RBD
   images in a RADOS pool.  RBD (RADOS Block Device) is part
   of the Ceph distributed storage project.
-  This backend only supports Qemu with RBD support. Kernel RBD
+  This backend only supports QEMU with RBD support. Kernel RBD
   which exposes RBD devices as block devices in /dev is not
   supported. RBD images created with this storage backend
   can be accessed through kernel RBD if configured manually, but
   this backend does not provide mapping for these images.
-  Images created with this backend can be attached to Qemu guests
-  when Qemu is build with RBD support (Since Qemu 0.14.0). The
+  Images created with this backend can be attached to QEMU guests
+  when QEMU is build with RBD support (Since QEMU 0.14.0). The
   backend supports cephx authentication for communication with the
   Ceph cluster. Storing the cephx authentication key is done with
   the libvirt secret mechanism. The UUID in the example pool input
@@ -601,7 +601,7 @@
 /volume
 
 Example disk attachment
-RBD images can be attached to Qemu guests when Qemu is built
+RBD images can be attached to QEMU guests when QEMU is built
 with RBD support. Information about attaching a RBD image to a
 guest can be found
 at format domain
@@ -661,7 +661,7 @@
 /volume
 
 Example disk attachment
-Sheepdog images can be attached to Qemu guests.
+Sheepdog images can be attached to QEMU guests.
 Information about attaching a Sheepdog image to a
 guest can be found
 at the format domain
@@ -746,7 +746,7 @@
 /volume
 
 Example disk attachment
-Files within a gluster volume can be attached to Qemu 

Re: [libvirt] [PATCH] doc: fix writing of QEMU

2017-03-01 Thread Philipp Hahn
Hello Peter,

Am 23.02.2017 um 12:51 schrieb Peter Krempa:
> On Thu, Feb 23, 2017 at 12:30:03 +0100, Philipp Hahn wrote:
>> QEMU should be written all upper or all lower case.
>>
>> Signed-off-by: Philipp Hahn <h...@univention.de>
>> ---
>>  ChangeLog-old |  4 ++--
>>  docs/formatnwfilter.html.in   |  6 +++---
>>  docs/news-2009.html.in|  6 +++---
>>  docs/news-2010.html.in| 12 ++--
>>  docs/news-2011.html.in|  4 ++--
>>  docs/news-2012.html.in|  2 +-
>>  docs/news-2014.html.in|  2 +-
> 
> These should not be changed.

Can you please clarify, why not? E.g. not changing historic is okay with me.

>>  docs/storage.html.in  | 12 ++--
>>  libvirt.spec.in   |  2 +-
>>  po/af.po  |  2 +-
>>  po/am.po  |  2 +-
>>  po/anp.po |  2 +-
>>  po/ar.po  |  2 +-
> 
> These neither.

Same here: Is it only ar.po you're complaining about or all of the above?

>>  po/as.po  |  2 +-
>>  po/ast.po |  2 +-
>>  po/bal.po |  2 +-
>>  po/be.po  |  2 +-
>>  po/bg.po  |  2 +-
>>  po/bn.po  |  2 +-
>>  po/bn_IN.po   |  2 +-
>>  po/bo.po  |  2 +-
>>  po/br.po  |  2 +-
>>  po/brx.po |  2 +-
>>  po/bs.po  |  2 +-
>>  po/ca.po  |  2 +-
>>  po/cs.po  |  2 +-
>>  po/cy.po  |  2 +-
>>  po/da.po  |  2 +-
>>  po/de.po  |  2 +-
>>  po/de_CH.po   |  2 +-
>>  po/el.po  |  2 +-
>>  po/en_GB.po   |  4 ++--
>>  po/eo.po  |  2 +-
>>  po/es.po  |  2 +-
>>  po/et.po  |  2 +-
>>  po/eu.po  |  2 +-
>>  po/fa.po  |  2 +-
>>  po/fi.po  |  2 +-
>>  po/fr.po  |  2 +-
>>  po/gl.po  |  2 +-
>>  po/gu.po  |  2 +-
>>  po/he.po  |  2 +-
>>  po/hi.po  |  2 +-
>>  po/hr.po  |  2 +-
>>  po/hu.po  |  2 +-
>>  po/ia.po  |  2 +-
>>  po/id.po  |  2 +-
>>  po/ilo.po |  2 +-
>>  po/is.po  |  2 +-
>>  po/it.po  |  2 +-
>>  po/ja.po  |  2 +-
>>  po/ka.po  |  2 +-
>>  po/kk.po  |  2 +-
>>  po/km.po  |  2 +-
>>  po/kn.po  |  2 +-
>>  po/ko.po  |  2 +-
>>  po/kw.po  |  2 +-
>>  po/k...@kkcor.po|  2 +-
>>  po/k...@uccor.po|  2 +-
>>  po/kw_GB.po   |  2 +-
>>  po/ky.po  |  2 +-
>>  po/libvirt.pot|  2 +-
>>  po/lt.po  |  2 +-
>>  po/lv.po  |  2 +-
>>  po/mai.po |  2 +-
>>  po/mk.po  |  2 +-
>>  po/ml.po  |  2 +-
>>  po/mn.po  |  2 +-
>>  po/mr.po  |  2 +-
>>  po/ms.po  |  2 +-
>>  po/nb.po  |  2 +-
>>  po/nds.po |  2 +-
>>  po/ne.po  |  2 +-
>>  po/nl.po  |  2 +-
>>  po/nn.po  |  2 +-
>>  po/nso.po |  2 +-
>>  po/or.po  |  2 +-
>>  po/pa.po  |  2 +-
>>  po/pl.po  |  2 +-
>>  po/pt.po  |  2 +-
>>  po/pt_BR.po   |  2 +-
>>  po/ro.po  |  2 +-
>>  po/ru.po  |  2 +-
>>  po/si.po  |  2 +-
>>  po/sk.po  |  2 +-
>>  po/sl.po  |  2 +-
>>  po/sq.po  |  2 +-
>>  po/sr.po  |  2 +-
>>  po/s...@latin.po|  2 +-
>>  po/sv.po  |  2 +-
>>  po/ta.po  |  2 +-
>>  po/te.po  |  2 +-
>>  po/tg.po  |  2 

[libvirt] [PATCH v3] doc: Correct the default werror policy

2017-03-01 Thread Philipp Hahn
The documentation is plain wrong about the default write_error policy,
as its only implemented by QEMU (src/vz/vz_utils.c is the only other
case, which simply explodes, is anything except other then
VIR_DOMAIN_DISK_ERROR_POLICY_DEFAULT is used).

And QEMUs default is VIR_DOMAIN_DISK_ERROR_POLICY_ENOSPACE.

Signed-off-by: Philipp Hahn <h...@univention.de>
---
Osier Yang proposed v1 on 2011-10-24, which never got applied due to
discussions of "enospace" vs. "enospc". 

v2: Remove internal QEMU default

 docs/formatdomain.html.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 02ce792..dc44a55 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2745,7 +2745,8 @@
 how the hypervisor will behave on a disk read or write
 error, possible values are "stop", "report", "ignore", and
 "enospace".Since 0.8.0, "report" since
-0.9.7 The default setting of error_policy is "report".
+0.9.7 The default is left to the discretion of the
+hypervisor.
 There is also an
 optional rerror_policy that controls behavior
 for read errors only. Since
@@ -2755,8 +2756,7 @@
 read errors. Also note that "enospace" is not a valid
 policy for read errors, so if error_policy is
 set to "enospace" and no rerror_policy is
-given, the read error policy will be left at its default,
-which is "report".
+given, the read error policy will be left at its default.
   
   
 The optional io attribute controls specific
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] doc: fix writing of QEMU

2017-02-23 Thread Philipp Hahn
QEMU should be written all upper or all lower case.

Signed-off-by: Philipp Hahn <h...@univention.de>
---
 ChangeLog-old |  4 ++--
 docs/formatnwfilter.html.in   |  6 +++---
 docs/news-2009.html.in|  6 +++---
 docs/news-2010.html.in| 12 ++--
 docs/news-2011.html.in|  4 ++--
 docs/news-2012.html.in|  2 +-
 docs/news-2014.html.in|  2 +-
 docs/storage.html.in  | 12 ++--
 libvirt.spec.in   |  2 +-
 po/af.po  |  2 +-
 po/am.po  |  2 +-
 po/anp.po |  2 +-
 po/ar.po  |  2 +-
 po/as.po  |  2 +-
 po/ast.po |  2 +-
 po/bal.po |  2 +-
 po/be.po  |  2 +-
 po/bg.po  |  2 +-
 po/bn.po  |  2 +-
 po/bn_IN.po   |  2 +-
 po/bo.po  |  2 +-
 po/br.po  |  2 +-
 po/brx.po |  2 +-
 po/bs.po  |  2 +-
 po/ca.po  |  2 +-
 po/cs.po  |  2 +-
 po/cy.po  |  2 +-
 po/da.po  |  2 +-
 po/de.po  |  2 +-
 po/de_CH.po   |  2 +-
 po/el.po  |  2 +-
 po/en_GB.po   |  4 ++--
 po/eo.po  |  2 +-
 po/es.po  |  2 +-
 po/et.po  |  2 +-
 po/eu.po  |  2 +-
 po/fa.po  |  2 +-
 po/fi.po  |  2 +-
 po/fr.po  |  2 +-
 po/gl.po  |  2 +-
 po/gu.po  |  2 +-
 po/he.po  |  2 +-
 po/hi.po  |  2 +-
 po/hr.po  |  2 +-
 po/hu.po  |  2 +-
 po/ia.po  |  2 +-
 po/id.po  |  2 +-
 po/ilo.po |  2 +-
 po/is.po  |  2 +-
 po/it.po  |  2 +-
 po/ja.po  |  2 +-
 po/ka.po  |  2 +-
 po/kk.po  |  2 +-
 po/km.po  |  2 +-
 po/kn.po  |  2 +-
 po/ko.po  |  2 +-
 po/kw.po  |  2 +-
 po/k...@kkcor.po|  2 +-
 po/k...@uccor.po|  2 +-
 po/kw_GB.po   |  2 +-
 po/ky.po  |  2 +-
 po/libvirt.pot|  2 +-
 po/lt.po  |  2 +-
 po/lv.po  |  2 +-
 po/mai.po |  2 +-
 po/mk.po  |  2 +-
 po/ml.po  |  2 +-
 po/mn.po  |  2 +-
 po/mr.po  |  2 +-
 po/ms.po  |  2 +-
 po/nb.po  |  2 +-
 po/nds.po |  2 +-
 po/ne.po  |  2 +-
 po/nl.po  |  2 +-
 po/nn.po  |  2 +-
 po/nso.po |  2 +-
 po/or.po  |  2 +-
 po/pa.po  |  2 +-
 po/pl.po  |  2 +-
 po/pt.po  |  2 +-
 po/pt_BR.po   |  2 +-
 po/ro.po  |  2 +-
 po/ru.po  |  2 +-
 po/si.po  |  2 +-
 po/sk.po  |  2 +-
 po/sl.po  |  2 +-
 po/sq.po  |  2 +-
 po/sr.po  |  2 +-
 po/s...@latin.po|  2 +-
 po/sv.po  |  2 +-
 po/ta.po  |  2 +-
 po/te.po  |  2 +-
 po/tg.po  |  2 +-
 po/th.po  |  2 +-
 po/tr.po  |  2 +-
 po/tw.po  |  2 +-
 po/uk.po  |  2 +-
 po/ur.po  |  2 +-
 po/vi.po  |  2 +-
 po/wba.po |  2 +-
 po/yo.po  |  2 +-
 po/zh_CN.po   |  2 +-
 po/zh_HK.po   |  2 +-
 po/zh_TW.po   |  2 +-
 po/zu.po  |  2 +-
 src/cpu/cpu_s390.c|  2 +-
 src/qemu/MIGRATION.txt|  2 +-
 src/qemu/THREADS.txt  |  2 +-
 src/qemu/qemu.conf|  4 ++--
 src/qemu/qemu_command.c   |  2 +-
 src/qemu/qemu_domain.h|  2 +-
 src/qemu/qemu_monitor.c   |  6 +++---
 src/qemu/qemu_parse_command.c |  2 +-
 113 files changed, 133 insertions(+), 133 deletions(-)

diff --git a/ChangeLog-old b/ChangeLog-old
index e38a9bd..b903b54 100644
--- a/ChangeLog-old
+++ b/ChangeLog-old
@@ -576,7 +576,7 @@ Fri May 29 10:00:01 EDT 2009 Cole Robinson 
<crobi...@redhat.com>
 Fri May 29 15:29:32 CEST 2009 Daniel Veillard <veill...@redhat.com>
 
* src/qemu_conf.c docs/schemas/domain.rng
- tests/capabilityschemadata/caps

[libvirt] [PATCH v2] doc: Correct the default werror policy

2017-02-23 Thread Philipp Hahn
The documentation is plain wrong about the default write_error policy,
as its only implemented by QEMU (src/vz/vz_utils.c is the only other
case, which simply explodes, is anything except other then
VIR_DOMAIN_DISK_ERROR_POLICY_DEFAULT is used).

And QEMUs default is VIR_DOMAIN_DISK_ERROR_POLICY_ENOSPACE.

Signed-off-by: Philipp Hahn <h...@univention.de>
---
 docs/formatdomain.html.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
Osier Yang proposed v1 on 2011-10-24, which never got applied due to
discussions of "enospace" vs. "enospc".

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 02ce792..3e1a193 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2745,7 +2745,8 @@
 how the hypervisor will behave on a disk read or write
 error, possible values are "stop", "report", "ignore", and
 "enospace".Since 0.8.0, "report" since
-0.9.7 The default setting of error_policy is "report".
+0.9.7 The default is left to the discretion of the
+hypervisor: QEMU defaults to "enospace".
 There is also an
 optional rerror_policy that controls behavior
 for read errors only. Since
@@ -2755,8 +2756,7 @@
 read errors. Also note that "enospace" is not a valid
 policy for read errors, so if error_policy is
 set to "enospace" and no rerror_policy is
-given, the read error policy will be left at its default,
-which is "report".
+given, the read error policy will be left at its default.
   
   
 The optional io attribute controls specific
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2] doc: add storage format entries

2017-02-23 Thread Philipp Hahn
Add format/@type entries to examples to show what the text is talking
about.

Add missing blank.

Signed-off-by: Philipp Hahn <h...@univention.de>
---
 docs/storage.html.in | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)
---
This is a re-post from 2013-02-07, as ist still is unclear where the 
should go.

diff --git a/docs/storage.html.in b/docs/storage.html.in
index d81efdb..10b1f1f 100644
--- a/docs/storage.html.in
+++ b/docs/storage.html.in
@@ -195,6 +195,7 @@
   namevirtimages/name
   source
 device path="/dev/VolGroup00/VirtImages"/
+format type="auto"/
   /source
   target
 path/var/lib/virt/images/path
@@ -324,6 +325,7 @@
 device path="/dev/sda1"/
 device path="/dev/sdb1"/
 device path="/dev/sdc1"/
+format type="lvm2"/
   /source
   target
 path/dev/HostVG/path
@@ -334,7 +336,7 @@
 
   The logical volume pool supports only the lvm2 format,
   although not supplying a format value will result in automatic
-  selection of thelvm2 format.
+  selection of the lvm2 format.
 
 
 Valid volume format types
@@ -359,6 +361,7 @@
   namesda/name
   source
 device path='/dev/sda'/
+format type='gpt'/
   /source
   target
 path/dev/path
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] doc updates

2017-02-23 Thread Philipp Hahn
Hi,

here are 3 patches to improve the documentation:

the 1st one is a re-sent from 2013,

the 2nd one is my version of a patch proposed 2011,

the 3rd is probably most controversal, so drop it if you don't like it. The
QEMU homepage spellts it "QEMU" and "qemu" is used a lot for the binary, but
"Qemu" is used very little.

Philipp Hahn (3):
  doc: add storage format entries
  doc: Correct the default werror policy
  doc: fix writing of QEMU

 ChangeLog-old |  4 ++--
 docs/formatdomain.html.in |  6 +++---
 docs/formatnwfilter.html.in   |  6 +++---
 docs/news-2009.html.in|  6 +++---
 docs/news-2010.html.in| 12 ++--
 docs/news-2011.html.in|  4 ++--
 docs/news-2012.html.in|  2 +-
 docs/news-2014.html.in|  2 +-
 docs/storage.html.in  | 17 ++---
 libvirt.spec.in   |  2 +-
 po/af.po  |  2 +-
 po/am.po  |  2 +-
 po/anp.po |  2 +-
 po/ar.po  |  2 +-
 po/as.po  |  2 +-
 po/ast.po |  2 +-
 po/bal.po |  2 +-
 po/be.po  |  2 +-
 po/bg.po  |  2 +-
 po/bn.po  |  2 +-
 po/bn_IN.po   |  2 +-
 po/bo.po  |  2 +-
 po/br.po  |  2 +-
 po/brx.po |  2 +-
 po/bs.po  |  2 +-
 po/ca.po  |  2 +-
 po/cs.po  |  2 +-
 po/cy.po  |  2 +-
 po/da.po  |  2 +-
 po/de.po  |  2 +-
 po/de_CH.po   |  2 +-
 po/el.po  |  2 +-
 po/en_GB.po   |  4 ++--
 po/eo.po  |  2 +-
 po/es.po  |  2 +-
 po/et.po  |  2 +-
 po/eu.po  |  2 +-
 po/fa.po  |  2 +-
 po/fi.po  |  2 +-
 po/fr.po  |  2 +-
 po/gl.po  |  2 +-
 po/gu.po  |  2 +-
 po/he.po  |  2 +-
 po/hi.po  |  2 +-
 po/hr.po  |  2 +-
 po/hu.po  |  2 +-
 po/ia.po  |  2 +-
 po/id.po  |  2 +-
 po/ilo.po |  2 +-
 po/is.po  |  2 +-
 po/it.po  |  2 +-
 po/ja.po  |  2 +-
 po/ka.po  |  2 +-
 po/kk.po  |  2 +-
 po/km.po  |  2 +-
 po/kn.po  |  2 +-
 po/ko.po  |  2 +-
 po/kw.po  |  2 +-
 po/k...@kkcor.po|  2 +-
 po/k...@uccor.po|  2 +-
 po/kw_GB.po   |  2 +-
 po/ky.po  |  2 +-
 po/libvirt.pot|  2 +-
 po/lt.po  |  2 +-
 po/lv.po  |  2 +-
 po/mai.po |  2 +-
 po/mk.po  |  2 +-
 po/ml.po  |  2 +-
 po/mn.po  |  2 +-
 po/mr.po  |  2 +-
 po/ms.po  |  2 +-
 po/nb.po  |  2 +-
 po/nds.po |  2 +-
 po/ne.po  |  2 +-
 po/nl.po  |  2 +-
 po/nn.po  |  2 +-
 po/nso.po |  2 +-
 po/or.po  |  2 +-
 po/pa.po  |  2 +-
 po/pl.po  |  2 +-
 po/pt.po  |  2 +-
 po/pt_BR.po   |  2 +-
 po/ro.po  |  2 +-
 po/ru.po  |  2 +-
 po/si.po  |  2 +-
 po/sk.po  |  2 +-
 po/sl.po  |  2 +-
 po/sq.po  |  2 +-
 po/sr.po  |  2 +-
 po/s...@latin.po|  2 +-
 po/sv.po  |  2 +-
 po/ta.po  |  2 +-
 po/te.po  |  2 +-
 po/tg.po  |  2 +-
 po/th.po  |  2 +-
 po/tr.po  |  2 +-
 po/tw.po  |  2 +-
 po/uk.po  |  2 +-
 po/ur.po  |  2 +-
 po/vi.po  |  2 +-
 po/wba.po |  2 +-
 po/yo.po  |  2 +-
 po/zh_CN.po   |  2 +-
 po/zh_HK.po   |  2 +-
 po/zh_TW.po   |  2 +-
 po/zu.po  |  2 +-
 src/cpu/cpu_s390.c|  2 +-
 src/qemu/MIGRATION.txt|  2 +-
 src/qemu/THREADS.txt  |  2 +-
 src/qemu/qemu.conf|  4 ++--
 src/qemu/qemu_command.c   |  2 +-
 src/qemu/qemu_domain.h|  2 +-
 src/qemu/qemu_monitor.c   |  6 +++---
 src/qemu/qemu_parse_command.c |  2 +-
 114 files c

[libvirt] RFC: Qemu/SeaBIOS/VGA/PXE upgrades vs. longterm-snapshot/migration

2016-08-29 Thread Philipp Hahn
Hello,

If my understanding of migration/snapshots is correct, the
target/loading VM must be a clone of the source/saving VM, that is have
the same devices, RAM/PCI layout, etc. In the past I have had several
issues with Qemu, when the distribution (Debian) updates their packaging
of SeaBIOS/iPXE/VgaROM, which changes the the next/previous power-of-2
size and thus changes the PCI layout, preventing me from loading old
snapshots.

As the BIOS file is provided externally, it is prone to such
(accidental) updates. As (AFAIK) libvirt does not track the Qemu
version, BIOS files inside its XML data, there's always the danger of
making snapshots invalid by updating Qemu and the BIOS files.

Some questions:

1. Does Qemu use ROM shadowing, that is copying the ROM to RAM? This
makes sense on real HW as ROMs are a low slower than RAM. In that case
the content of the "ROM" would already be contained inside the VM-State
and it would be enough to provide an "empty ROM file of the right size".

2. If Qemu does no ROM shadowing, what happens if I suspend a VM while
executing ROM or SMM code and then doing an SeaBIOS update? (my
DOS-assembler knowledge is quiet old nowadays)

3. How do others handle long-term snapshots? Just say "good-bye" to your
old snapshots when upgrading to a newer Qemu version or keeping the old,
probably unmaintained and vulnerable Qemu/BIOS binaries until the
end-of-time?

Thanks in advance
Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen
Tel.: +49 421 22232-0
Fax : +49 421 22232-99
h...@univention.de

http://www.univention.de/
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCHv2] xen: Also add sub-type for driver=tap2 in xen-xm

2016-05-19 Thread Philipp Hahn
tap2 only handles 'aio', but not 'raw', which must be explicitly given:

| $ virsh domxml-to-native yyy.xml > yyy.xm
| $ xm new yyy.xm
| Error: tap:/srv/xen/xxx.img not a valid disk type
| $ sed -i -e 's/tap2:/:/' yyy.xm
| $ xm new yyy.xm

Fix reading and writing "xen-xm" format for "tap2" by handling it the
same as "tap".
---
 src/xenconfig/xen_xm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
index 34d57de..1018e9b 100644
--- a/src/xenconfig/xen_xm.c
+++ b/src/xenconfig/xen_xm.c
@@ -196,7 +196,8 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def)
 }
 
 /* And the sub-type for tap:XXX: type */
-if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap")) {
+if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap") ||
+STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) {
 char *driverType;
 
 if (!(tmp = strchr(src, ':')))
@@ -298,7 +299,7 @@ xenFormatXMDisk(virConfValuePtr list,
 else
 type = virStorageFileFormatTypeToString(format);
 virBufferAsprintf(, "%s:", driver);
-if (STREQ(driver, "tap"))
+if (STREQ(driver, "tap") || STREQ(driver, "tap2"))
 virBufferAsprintf(, "%s:", type);
 } else {
 switch (virDomainDiskGetType(disk)) {
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2] test: Remove executable permission from Xen xm files

2016-05-19 Thread Philipp Hahn
The configuration files are not directly executable as they don't have
as hash-bang line.
---
 tests/xlconfigdata/test-fullvirt-multiusb.cfg  | 0
 tests/xmconfigdata/test-fullvirt-localtime.cfg | 0
 tests/xmconfigdata/test-fullvirt-new-cdrom.cfg | 0
 tests/xmconfigdata/test-fullvirt-nohap.cfg | 0
 tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg  | 0
 tests/xmconfigdata/test-fullvirt-serial-file.cfg   | 0
 tests/xmconfigdata/test-fullvirt-serial-null.cfg   | 0
 tests/xmconfigdata/test-fullvirt-serial-pipe.cfg   | 0
 tests/xmconfigdata/test-fullvirt-serial-pty.cfg| 0
 tests/xmconfigdata/test-fullvirt-serial-stdio.cfg  | 0
 tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg | 0
 tests/xmconfigdata/test-fullvirt-serial-tcp.cfg| 0
 tests/xmconfigdata/test-fullvirt-serial-udp.cfg| 0
 tests/xmconfigdata/test-fullvirt-serial-unix.cfg   | 0
 tests/xmconfigdata/test-fullvirt-usbmouse.cfg  | 0
 tests/xmconfigdata/test-fullvirt-usbtablet.cfg | 0
 tests/xmconfigdata/test-fullvirt-utc.cfg   | 0
 tests/xmconfigdata/test-paravirt-net-e1000.cfg | 0
 tests/xmconfigdata/test-paravirt-new-pvfb.cfg  | 0
 19 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644 tests/xlconfigdata/test-fullvirt-multiusb.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-localtime.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-nohap.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-file.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-null.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-pipe.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-pty.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-stdio.cfg
 mode change 100755 => 100644 
tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-tcp.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-udp.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-unix.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-usbmouse.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-usbtablet.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-utc.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-paravirt-net-e1000.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-paravirt-new-pvfb.cfg

diff --git a/tests/xlconfigdata/test-fullvirt-multiusb.cfg 
b/tests/xlconfigdata/test-fullvirt-multiusb.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-localtime.cfg 
b/tests/xmconfigdata/test-fullvirt-localtime.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg 
b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-nohap.cfg 
b/tests/xmconfigdata/test-fullvirt-nohap.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg 
b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-file.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-file.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-null.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-null.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg 
b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg 
b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg
old mode 100755
new mode 100644
diff --git a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg 

[libvirt] [PATCHv2] xen: test for driver=tap2 sub-type in xen-xm

2016-05-19 Thread Philipp Hahn
tap2 only handles 'aio', but not 'raw', which must be explicitly given:

XML:raw needs to be translated to XM:aio for 'tap' and 'tap2' Xen
drivers.
---
 tests/xmconfigdata/test-disk-drv-blktap-raw.cfg  | 12 +
 tests/xmconfigdata/test-disk-drv-blktap-raw.xml  | 33 
 tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg | 12 +
 tests/xmconfigdata/test-disk-drv-blktap2-raw.xml | 33 
 tests/xmconfigtest.c |  3 +++
 5 files changed, 93 insertions(+)
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap-raw.cfg
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap-raw.xml
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap2-raw.xml

diff --git a/tests/xmconfigdata/test-disk-drv-blktap-raw.cfg 
b/tests/xmconfigdata/test-disk-drv-blktap-raw.cfg
new file mode 100644
index 000..aa38bc1
--- /dev/null
+++ b/tests/xmconfigdata/test-disk-drv-blktap-raw.cfg
@@ -0,0 +1,12 @@
+name = "XenGuest1"
+uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 2
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ "tap:aio:/root/some.img,xvda,w" ]
diff --git a/tests/xmconfigdata/test-disk-drv-blktap-raw.xml 
b/tests/xmconfigdata/test-disk-drv-blktap-raw.xml
new file mode 100644
index 000..cf859ba
--- /dev/null
+++ b/tests/xmconfigdata/test-disk-drv-blktap-raw.xml
@@ -0,0 +1,33 @@
+
+  XenGuest1
+  c7a5fdb0-cdaf-9455-926a-d65c16db1809
+  592896
+  403456
+  2
+  /usr/bin/pygrub
+  
+linux
+  
+  
+  destroy
+  restart
+  restart
+  
+
+  
+  
+  
+
+
+  
+  
+  
+
+
+  
+
+
+
+
+  
+
diff --git a/tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg 
b/tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg
new file mode 100644
index 000..c74e543
--- /dev/null
+++ b/tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg
@@ -0,0 +1,12 @@
+name = "XenGuest1"
+uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 2
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ "tap2:aio:/root/some.img,xvda,w" ]
diff --git a/tests/xmconfigdata/test-disk-drv-blktap2-raw.xml 
b/tests/xmconfigdata/test-disk-drv-blktap2-raw.xml
new file mode 100644
index 000..af2519a
--- /dev/null
+++ b/tests/xmconfigdata/test-disk-drv-blktap2-raw.xml
@@ -0,0 +1,33 @@
+
+  XenGuest1
+  c7a5fdb0-cdaf-9455-926a-d65c16db1809
+  592896
+  403456
+  2
+  /usr/bin/pygrub
+  
+linux
+  
+  
+  destroy
+  restart
+  restart
+  
+
+  
+  
+  
+
+
+  
+  
+  
+
+
+  
+
+
+
+
+  
+
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 9b21a13..8964a2a 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -249,6 +249,9 @@ mymain(void)
 DO_TEST("no-source-cdrom");
 DO_TEST("pci-devs");
 
+DO_TEST("disk-drv-blktap-raw");
+DO_TEST("disk-drv-blktap2-raw");
+
 virObjectUnref(caps);
 virObjectUnref(xmlopt);
 
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2] Xen: Handle tap2 sub-type

2016-05-19 Thread Philipp Hahn
Hi,

here is v2 which adds the requested unit test and fixes some file permission
for Xen configuration test files.

Philipp Hahn (3):
  xen: Also add sub-type for driver=tap2 in xen-xm
  xen: test for driver=tap2 sub-type in xen-xm
  test: Remove executable permission from Xen xm files

 src/xenconfig/xen_xm.c |  5 ++--
 tests/xlconfigdata/test-fullvirt-multiusb.cfg  |  0
 tests/xmconfigdata/test-disk-drv-blktap-raw.cfg| 12 
 tests/xmconfigdata/test-disk-drv-blktap-raw.xml| 33 ++
 tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg   | 12 
 tests/xmconfigdata/test-disk-drv-blktap2-raw.xml   | 33 ++
 tests/xmconfigdata/test-fullvirt-localtime.cfg |  0
 tests/xmconfigdata/test-fullvirt-new-cdrom.cfg |  0
 tests/xmconfigdata/test-fullvirt-nohap.cfg |  0
 tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg  |  0
 tests/xmconfigdata/test-fullvirt-serial-file.cfg   |  0
 tests/xmconfigdata/test-fullvirt-serial-null.cfg   |  0
 tests/xmconfigdata/test-fullvirt-serial-pipe.cfg   |  0
 tests/xmconfigdata/test-fullvirt-serial-pty.cfg|  0
 tests/xmconfigdata/test-fullvirt-serial-stdio.cfg  |  0
 .../test-fullvirt-serial-tcp-telnet.cfg|  0
 tests/xmconfigdata/test-fullvirt-serial-tcp.cfg|  0
 tests/xmconfigdata/test-fullvirt-serial-udp.cfg|  0
 tests/xmconfigdata/test-fullvirt-serial-unix.cfg   |  0
 tests/xmconfigdata/test-fullvirt-usbmouse.cfg  |  0
 tests/xmconfigdata/test-fullvirt-usbtablet.cfg |  0
 tests/xmconfigdata/test-fullvirt-utc.cfg   |  0
 tests/xmconfigdata/test-paravirt-net-e1000.cfg |  0
 tests/xmconfigdata/test-paravirt-new-pvfb.cfg  |  0
 tests/xmconfigtest.c   |  3 ++
 25 files changed, 96 insertions(+), 2 deletions(-)
 mode change 100755 => 100644 tests/xlconfigdata/test-fullvirt-multiusb.cfg
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap-raw.cfg
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap-raw.xml
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap2-raw.cfg
 create mode 100644 tests/xmconfigdata/test-disk-drv-blktap2-raw.xml
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-localtime.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-nohap.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-file.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-null.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-pipe.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-pty.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-stdio.cfg
 mode change 100755 => 100644 
tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-tcp.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-udp.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-serial-unix.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-usbmouse.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-usbtablet.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-fullvirt-utc.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-paravirt-net-e1000.cfg
 mode change 100755 => 100644 tests/xmconfigdata/test-paravirt-new-pvfb.cfg

-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 3/8] Add support for fetching statistics of completed jobs

2016-05-09 Thread Philipp Hahn
Hi,

FYI as tracking down that failure did cost me some time and hopefully
this summary will help other to avoid this situation:

Am 09.09.2014 um 11:54 schrieb Jiri Denemark:
> virDomainGetJobStats gains new VIR_DOMAIN_JOB_STATS_COMPLETED flag that
> can be used to fetch statistics of a completed job rather than a
> currently running job.
> 
> Signed-off-by: Jiri Denemark <jdene...@redhat.com>
...
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -2500,7 +2500,8 @@ qemuMonitorJSONGetMigrationStatusReply(virJSONValuePtr 
> reply,
...
> -if (status->status == QEMU_MONITOR_MIGRATION_STATUS_ACTIVE) {
> +if (status->status == QEMU_MONITOR_MIGRATION_STATUS_ACTIVE ||
> +status->status == QEMU_MONITOR_MIGRATION_STATUS_COMPLETED) {
>  virJSONValuePtr ram = virJSONValueObjectGet(ret, "ram");
>  if (!ram) {
>  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
>_("migration was active, but RAM 'transferred' "
>  "data was missing"));

This change from libvirt v1.2.9-rc1~203 breaks migration with
qemu-kvm-1.1.2, as that ancient implementation does *not* export
transfer statistics for completed jobs:

> qemuMonitorJSONCommandWithFd:286 : Send command 
> '{"execute":"query-migrate","id":"libvirt-41"}' for write with FD -1
> qemuMonitorJSONIOProcessLine:179 : Line [{"return": {"status": "active", 
> "ram": {"total": 2164654080, "remaining": 22474752, "transferred": 
> 175117413}}, "id": "libvirt-41"}]
...
> qemuMonitorJSONCommandWithFd:286 : Send command 
> '{"execute":"query-migrate","id":"libvirt-42"}' for write with FD -1
> qemuMonitorJSONIOProcessLine:179 : Line [{"return": {"status": "completed"}, 
> "id": "libvirt-42"}]

As you can see, there is not "ram" section and the migration is aborted
with the message:
> internal error: migration was active, but no RAM info was set

qemu-kvm/qmp-commands.hx even states this:
> - "ram": only present if "status" is "active", it is a json-object with the
>   following RAM information (in bytes):
but the example some lines below is wrong:
> 2. Migration is done and has succeeded
> 
> -> { "execute": "query-migrate" }
> <- { "return": {
> "status": "completed",
> "ram":{
That example has been updated by v1.2.0-rc0~29^2~2, but forgot to update
the specification above.


The attached hack for libvirt makes migration work again for me by
making "ram" optional in case of "completed".

Philipp
From c4f6dfb25042f420fdd1728865686552d928d90e Mon Sep 17 00:00:00 2001
Message-Id: <c4f6dfb25042f420fdd1728865686552d928d90e.1462786017.git.h...@univention.de>
From: Philipp Hahn <h...@univention.de>
Date: Mon, 9 May 2016 10:52:09 +0200
Subject: [PATCH] Bug #40318 libvirt: Handle qemu-kvm-1.1.2 migration
 incompatibility
Organization: Univention GmbH, Bremen, Germany
To: libvir-list@redhat.com

The change from libvirt v1.2.9-rc1~203 breaks migration with qemu-kvm-1.1.2, as
that ancient implementation does *not* export transfer statistics for completed
jobs:

> qemuMonitorJSONCommandWithFd:286 : Send command '{"execute":"query-migrate","id":"libvirt-41"}' for write with FD -1
> qemuMonitorJSONIOProcessLine:179 : Line [{"return": {"status": "active", "ram": {"total": 2164654080, "remaining": 22474752, "transferred": 175117413}}, "id": "libvirt-41"}]
...
> qemuMonitorJSONCommandWithFd:286 : Send command '{"execute":"query-migrate","id":"libvirt-42"}' for write with FD -1
> qemuMonitorJSONIOProcessLine:179 : Line [{"return": {"status": "completed"}, "id": "libvirt-42"}]

As you can see, there is not "ram" section and the migration is aborted with
the message:
> internal error: migration was active, but no RAM info was set

qemu-kvm/qmp-commands.hx even states this:
> - "ram": only present if "status" is "active", it is a json-object with the
>   following RAM information (in bytes):
but the example some lines below is wrong:
> 2. Migration is done and has succeeded
>
> -> { "execute": "query-migrate" }
> <- { "return": {
> "status": "completed",
> "ram":{
That examp

Re: [libvirt] Join

2016-03-31 Thread Philipp Hahn
Am 25.03.2016 um 06:52 schrieb Tim Streit:
> Im having problems with my install.  Debian Jessie (8.3), but using libvirt 
> and kernel from back ports (for enhanced vt-d support, passing through a USB 
> card).  Guest is a windows xp sp3 box.  Initially I had hardware time set to 
> UTC, and I set the RealTimeIsUtc=1 in the registry.  But it would 
> periodically reset itself ahead 6 hours (CST), and since we just changed day 
> light savings time now its jumping 5 hours.  Every morning.   I have a 
> similarly configured system running a win7 guest, time works fine.
> 
> Someone on #kvm suggested that maybe I need to set my hwclock to local time, 
> and so I went through all that - changed it, appended LOCAL to  /etc/adjtime 
> etc. I then changed the RealTimeIsUtc=0, and for the first boot it seemed 
> okay.
> 
> Now, whenever I boot, it is constantly 5 hours ahead.  I can reset it but 
> when you reboot, its back.

Tell libvirt to give your VM a RTC with
  

That way your VM will have a RTC 5h behind UTC and Windows is free to
adjust the offset as it likes when the day-light saving occurs. When
that happens the "adjustment" changes and libvirt will persist that in
the XML.

See .

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] xen: Also add sub-type for driver=tap2 in xen-xm

2016-03-30 Thread Philipp Hahn
tap2 only handles 'aio', but not 'raw', which must be explicitly given:

| $ virsh domxml-to-native yyy.xml > yyy.xm
| $ xm new yyy.xm
| Error: tap:/srv/xen/xxx.img not a valid disk type
| $ sed -i -e 's/tap2:/:/' yyy.xm
| $ xm new yyy.xm

Fix reading and writing "xen-xm" format for "tap2" by handling it the
same as "tap".
---
 src/xenconfig/xen_xm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
index e09d97e..6556886 100644
--- a/src/xenconfig/xen_xm.c
+++ b/src/xenconfig/xen_xm.c
@@ -196,7 +196,8 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def)
 }
 
 /* And the sub-type for tap:XXX: type */
-if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap")) {
+if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap") ||
+STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) {
 char *driverType;
 
 if (!(tmp = strchr(src, ':')))
@@ -298,7 +299,7 @@ xenFormatXMDisk(virConfValuePtr list,
 else
 type = virStorageFileFormatTypeToString(format);
 virBufferAsprintf(, "%s:", driver);
-if (STREQ(driver, "tap"))
+if (STREQ(driver, "tap") || STREQ(driver, "tap2"))
 virBufferAsprintf(, "%s:", type);
 } else {
 switch (virDomainDiskGetType(disk)) {
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Canging bridge names on live migration

2015-06-10 Thread Philipp Hahn
Hello,

On 03.06.2015 13:18, seitan wrote:
 i wonder, if there's a possibility to change a name of a shared interface in
 virtual machine config, while doing migration.
 The problem is:
 hypervisor1 (source) uses shared interface name  br0.
 hypervisor2 (target) uses shared interface name br500.
 Live migration fails, because target hypervisor does not have br0 interface.

libvirt supports some hook scripts, which can be used to re-write the
XML file during live migration. Have a look at
http://docs.univention.de/uvmm-4.0.html#uvmmext:kvm:migrate, which
should work similarly for your scenario.

Philipp

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] virsh: Implement command to rename domain

2014-09-01 Thread Philipp Hahn
Hello Tomas,

On 01.09.2014 01:51, Tomas Meszaros wrote:
 I've recently worked with rather large number of virtual machines
 and needed to rename all domains. I couldn't find better way how
 to rename domain other than:
 
 virsh dumpxml domain  domain.xml
 (change domain name in domain.xml)
 virsh undefine domain
 virsh define domain.xml
 
 This is rather pain to do every time I want to rename domain.
 I think there should be simple way to change domain name.

This has been requested in the past already (even by me ;-)
Renaming is not that simple, as there are several more things to do:
1. Rename log files (this was somehow controversial last time it was
discussed, especially combined with external programs like logrotate)
2. Fix domain config for suspended VMs.
3. Keep existing snapshots
3.1 Fix domain config in snapshots.

Especially the last thing does very bad things if you revert a renamed
VM, as the UUID is then no longer unique.

Philipp sorry, no patch Hahn

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [BUG] xenInotify/keep-alive double-free

2014-04-02 Thread Philipp Hahn
Hello,

There seems to be a double-free bug in libvirt; I've checked libvirt
0.9.12 and 1.2.3:

With 0.9.12 xenUnifiedOpen() passes a pointer of conn to
xenInotifyOpen(), which passes it to virEventAddHandle(...opaque=conn...).

After successfully defining a new domain inotify picks up the newly
created directory and generates an event, which is processes when virsh
already dropped its last public reference to the domain and subsequently
already freed the connection. Since *conn is not zero-filled, the data
is still valid and usable, but virsh the terminates on double-freeing
some internal data.
I can reproduce by it doing:
  virsh undefine $DOM
  virsh -c xen:// define $DOM.xml

For 1.2.3 something similar seems to happen with the keep-alive:
$ grep unref ~/BUG/31032_virsh-define-segv.log
virUnrefDomain:276 : unref domain 0x7f4ec4003fe0 ucs32-64-segv 1
virReleaseDomain:246 : unref connection 0x917650 2
virUnrefDomain:276 : unref domain 0x934460 ucs32-64-segv 1
virReleaseDomain:246 : unref connection 0x917650 2
virUnrefConnect:145 : unref connection 0x917650 1
virUnrefDomain:276 : unref domain 0x7f4ec4004060 ucs32-64-segv 1
virReleaseDomain:246 : unref connection 0x917650 1

Notice that there are two lines for unref connection ... 1!


My gut feeling is that libvirt should also increment the reference
counter for internal references to delay freeing still used data and add
a second counter to track external references, which is used to start
closing down things.
Comments and ideas welcomed.

We're tracking this as
https://forge.univention.org/bugzilla/show_bug.cgi?id=31032

Sincerely
Philipp
-- 
Philipp Hahn
Open Source Software Engineer

Univention GmbH
be open.
Mary-Somerville-Str. 1
D-28359 Bremen
Tel.: +49 421 22232-0
Fax : +49 421 22232-99
h...@univention.de

http://www.univention.de/
Geschäftsführer: Peter H. Ganten
HRB 20755 Amtsgericht Bremen
Steuer-Nr.: 71-597-02876
# virsh -c xen:// define ucs32-64-segv.xml
2014-04-02 08:09:42.320+: 18209: info : libvirt version: 0.9.12
2014-04-02 08:09:42.320+: 18209: debug : virInitialize:414 : register drivers
2014-04-02 08:09:42.320+: 18209: debug : virRegisterDriver:775 : driver=0x7f4ed026f460 name=Test
2014-04-02 08:09:42.320+: 18209: debug : virRegisterDriver:799 : registering Test as driver 0
2014-04-02 08:09:42.320+: 18209: debug : virRegisterNetworkDriver:592 : registering Test as network driver 0
2014-04-02 08:09:42.320+: 18209: debug : virRegisterInterfaceDriver:625 : registering Test as interface driver 0
2014-04-02 08:09:42.320+: 18209: debug : virRegisterStorageDriver:658 : registering Test as storage driver 0
2014-04-02 08:09:42.320+: 18209: debug : virRegisterDeviceMonitor:691 : registering Test as device driver 0
2014-04-02 08:09:42.320+: 18209: debug : virRegisterSecretDriver:724 : registering Test as secret driver 0
2014-04-02 08:09:42.320+: 18209: debug : virRegisterNWFilterDriver:757 : registering Test as network filter driver 0
2014-04-02 08:09:42.321+: 18209: debug : xenHypervisorInit:2105 : Using new hypervisor call: 40001
2014-04-02 08:09:42.321+: 18209: debug : xenHypervisorInit:2214 : Using hypervisor call v2, sys ver8 dom ver7
2014-04-02 08:09:42.321+: 18209: debug : virRegisterDriver:775 : driver=0x7f4ed02709a0 name=Xen
2014-04-02 08:09:42.321+: 18209: debug : virRegisterDriver:799 : registering Xen as driver 1
2014-04-02 08:09:42.321+: 18209: debug : virRegisterDriver:775 : driver=0x7f4ed0271240 name=OPENVZ
2014-04-02 08:09:42.321+: 18209: debug : virRegisterDriver:799 : registering OPENVZ as driver 2
2014-04-02 08:09:42.321+: 18209: debug : virRegisterDriver:775 : driver=0x7f4ed0271760 name=VMWARE
2014-04-02 08:09:42.321+: 18209: debug : virRegisterDriver:799 : registering VMWARE as driver 3
2014-04-02 08:09:42.322+: 18209: debug : vboxRegister:137 : VBoxCGlueInit failed, using dummy driver
2014-04-02 08:09:42.322+: 18209: debug : virRegisterDriver:775 : driver=0x7f4ed0271c80 name=VBOX
2014-04-02 08:09:42.322+: 18209: debug : virRegisterDriver:799 : registering VBOX as driver 4
2014-04-02 08:09:42.322+: 18209: debug : virRegisterNetworkDriver:592 : registering VBOX as network driver 1
2014-04-02 08:09:42.322+: 18209: debug : virRegisterStorageDriver:658 : registering VBOX as storage driver 1
2014-04-02 08:09:42.322+: 18209: debug : virRegisterDriver:775 : driver=0x7f4ed026fd40 name=remote
2014-04-02 08:09:42.322+: 18209: debug : virRegisterDriver:799 : registering remote as driver 5
2014-04-02 08:09:42.322+: 18209: debug : virRegisterNetworkDriver:592 : registering remote as network driver 2
2014-04-02 08:09:42.322+: 18209: debug : virRegisterInterfaceDriver:625 : registering remote as interface driver 1
2014-04-02 08:09:42.322+: 18209: debug : virRegisterStorageDriver:658 : registering remote as storage driver 2
2014-04-02 08:09:42.322+: 18209: debug : virRegisterDeviceMonitor:691 : registering remote as device

[libvirt] [PATCH] XML: Escape double-hyphens in XML comment

2014-02-21 Thread Philipp Hahn
To quote http://www.w3.org/TR/REC-xml/#sec-comments:
 For compatibility, the string -- (double-hyphen) must not occur within 
 comments.

For example this breaks creating snapshots:
$ virsh snapshot-create-as $VM comment--bug
$ xmllint --noout /var/lib/libvirt/qemu/snapshot/$VM/comment--bug.xml
/var/lib/libvirt/qemu/snapshot/$VM/comment--bug.xml:4: parser error : Comment 
not terminated
!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES
  virsh snapshot-edit $VM comment--bug
$ /etc/init.d/libvirt-bin restart
error : qemuDomainSnapshotLoad:367 : Failed to parse snapshot XML from file 
'/var/lib/libvirt/qemu/snapshot/$VM/comment--bug.xml'
$ virsh snapshot-list ucs32-33787-performance
 Name Creation Time State


Also applies to QEMU domains, where the name contains double-hyphens.

As a work-around break any sequence of consecutive hyphens by inserting
(arbitrarily chosen) backslashes, as there is no escaping rule defined
as far as I know.

I've not yet checked, how libvirt/libxml handles a document with
multiple root nodes, as this would create interesting possibilities if I
can name my domain
--domain...devices...disk...source dev=/dev/sda/...
It might break on the / as this is the only prohibited character for
QEMU domains, as the name is directly used as a file name.

To fix such broken files (by hand), remove the broken comment by doing
something like this after making sure libvirtd is stopped:
  sed -i -ne '/^domainsnapshot$/,$p' /var/lib/libvirt/qemu/snapshot/*/*.xml
  sed -i -ne '/^domain /,$p' /etc/libvirt/qemu/*.xml
  sed -i -ne '/^pool /,$p' /etc/libvirt/storage/*.xml

@Debian: The bug is also in libvirt-0.9.12.

Signed-off-by: Philipp Hahn h...@univention.de
---
 src/util/virxml.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index dd530a6..ad45e68 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -798,6 +798,34 @@ const char *virXMLPickShellSafeComment(const char *str1, 
const char *str2)
 return NULL;
 }
 
+/*
+ * Break sequence of hyphens by inserting (arbitrarily chosen) backslashes.
+ * http://www.w3.org/TR/REC-xml/#sec-comments:
+ *  For compatibility, the string -- (double-hyphen) must not occur within
+ *  comments.
+ */
+static int virXMLEmitEscapedComment(int fd,
+const char *str)
+{
+size_t len;
+
+if (!strstr(str, --)) {
+len = strlen(str);
+if (safewrite(fd, str, len) != len)
+return -1;
+return 0;
+}
+
+for (;*str;str++) {
+if (safewrite(fd, str, 1) != 1)
+return -1;
+if (str[0] == '-'  str[1] == '-')
+if (safewrite(fd, \\, 1) != 1)
+return -1;
+}
+return 0;
+}
+
 static int virXMLEmitWarning(int fd,
  const char *name,
  const char *cmd)
@@ -822,16 +850,14 @@ static int virXMLEmitWarning(int fd,
 if (safewrite(fd, prologue, len) != len)
 return -1;
 
-len = strlen(cmd);
-if (safewrite(fd, cmd, len) != len)
+if (virXMLEmitEscapedComment(fd, cmd)  0)
 return -1;
 
 if (name) {
 if (safewrite(fd,  , 1) != 1)
 return -1;
 
-len = strlen(name);
-if (safewrite(fd, name, len) != len)
+if (virXMLEmitEscapedComment(fd, name)  0)
 return -1;
 }
 
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] XML: Escape double-hyphens in XML comment

2014-02-21 Thread Philipp Hahn
On 21.02.2014 12:18, Ján Tomko wrote:
 This no longer reproduces with current master, it has been fixed by either of:
 commit 0b121614a2086a8e66ae1f004fe912ba7c1d8a75
 Author: Ján Tomko jto...@redhat.com
 CommitDate: 2012-10-29 14:38:43 +0100
 
 xml: print uuids in the warning
 
 commit 9b704ab8235af010b1fda4886201aab02098b969
 Author: Ján Tomko jto...@redhat.com
 CommitDate: 2012-10-23 14:24:31 +0200
 
 xml: omit domain name from comment if it contains double hyphen

Thanks and sorry for the noise - your solution looks much better :-)

Philipp



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] Fix stream related spelling mistakes

2014-02-13 Thread Philipp Hahn
Remove double is.
Consistent spelling of all-uppercase I/O.

Signed-off-by: Philipp Hahn h...@univention.de
---
 src/libvirt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 9cc5b1c..666ab1e 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -15890,7 +15890,7 @@ error:
  *
  * Send the entire data stream, reading the data from the
  * requested data source. This is simply a convenient alternative
- * to virStreamSend, for apps that do blocking-I/o.
+ * to virStreamSend, for apps that do blocking-I/O.
  *
  * An example using this with a hypothetical file upload
  * API looks like
@@ -15983,7 +15983,7 @@ cleanup:
  *
  * Receive the entire data stream, sending the data to the
  * requested data sink. This is simply a convenient alternative
- * to virStreamRecv, for apps that do blocking-I/o.
+ * to virStreamRecv, for apps that do blocking-I/O.
  *
  * An example using this with a hypothetical file download
  * API looks like
@@ -16192,7 +16192,7 @@ error:
  * virStreamFinish:
  * @stream: pointer to the stream object
  *
- * Indicate that there is no further data is to be transmitted
+ * Indicate that there is no further data to be transmitted
  * on the stream. For output streams this should be called once
  * all data has been written. For input streams this should be
  * called once virStreamRecv returns end-of-file.
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Fix stream related spelling mistakes

2014-02-13 Thread Philipp Hahn
Consistent spelling of all-uppercase I/O.

Signed-off-by: Philipp Hahn h...@univention.de
---
 libvirt-override-virStream.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libvirt-override-virStream.py b/libvirt-override-virStream.py
index 53000da..e9dd09a 100644
--- a/libvirt-override-virStream.py
+++ b/libvirt-override-virStream.py
@@ -28,7 +28,7 @@
 def recvAll(self, handler, opaque):
 Receive the entire data stream, sending the data to the
 requested data sink. This is simply a convenient alternative
-to virStreamRecv, for apps that do blocking-I/o.
+to virStreamRecv, for apps that do blocking-I/O.
 
 A hypothetical handler function looks like:
 
@@ -61,7 +61,7 @@
 
 Send the entire data stream, reading the data from the
 requested data source. This is simply a convenient alternative
-to virStreamSend, for apps that do blocking-I/o.
+to virStreamSend, for apps that do blocking-I/O.
 
 A hypothetical handler function looks like:
 
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


  1   2   3   4   >