123 Commits

Author SHA1 Message Date
Cole Robinson
4b26348290 xmlbuilder: Separate out the property cache
Add a few more mappings to simplify certain lookups, and add
some more validation to prevent programming errors
2018-03-21 14:32:47 -04:00
Cole Robinson
7fb1ddbc18 virtinst: s/_XML_ROOT_NAME/XML_NAME/g
No reason for it to be privatized, could be useful in some cases
2018-03-21 11:17:36 -04:00
Cole Robinson
3e176f2aa4 xmlbuilder: Remove relative_xpath substitution support
This only has one user in interface.py. That case is indeed weird
but we can implement it there, rather than in generic code
2018-03-21 11:17:36 -04:00
Cole Robinson
b7f6e4990e xmlbuilder: Use OrderedDict for propstore
Let's us drop proporder
2018-03-21 11:17:36 -04:00
Cole Robinson
8d0b1f80f1 cli: Have parser classes reference property names, not xmlbuilders
propertys already give us ways to access the backing class, and
switching to this method lets us drop some infrastructure in
xmlbuilder
2018-03-21 11:17:36 -04:00
Cole Robinson
256f0df8c2 xmlbuilder: Drop s/child_classes/child_class/
The only user was Guest._devices hackery, which has been dropped,
so clean up all this stuff
2018-03-21 11:17:36 -04:00
Cole Robinson
b6dcee8eb7 Use consistent and minimal license header for every file 2018-03-21 07:29:40 -04:00
Cole Robinson
1c911ce567 virtinst: Give device classes consistent DeviceX naming
Previous state was inconsistenty and needlessly wordy. Fix up
a few other class namings that have redundant Virtual in the name
2018-03-21 07:29:40 -04:00
Cole Robinson
93c22eff79 xmlbuilder: Move xml_indent to util 2018-03-20 10:35:22 -04:00
Cole Robinson
435fdf2a6a tests: Add xmlns remove_child test case
And tighten up the xmlbuilder xmlns hackery
2018-02-26 14:56:24 -05:00
Cole Robinson
84c02da998 xmlbuilder: Make sure split out XML has xmlns as needed
Otherwise libxml2 whines
2018-02-23 14:41:22 -05:00
Cole Robinson
3079426c82 virtinst: Drop doc= for properties
This data never gets to the user and largely is just duplicating
libvirt docs. It's redundant
2018-02-22 20:49:07 -05:00
Cole Robinson
6f578ffeff xmlbuilder: Remove get_xml_config prep wrappers
The only user was Guest, and in fact it's not needed for the standard
get_xml_config, only for the custom _get_install_xml. So drop it
2018-02-22 20:49:07 -05:00
Cole Robinson
059fb7d0ba xmlbuilder: Order child props before serializing
We were implicitly depending on dict hash ordering here, which
was causing some different XML output in centos CI
2018-02-20 11:41:04 -05:00
Cole Robinson
f04b284f21 xmlbuilder: Abstract libxml2 API and cleanup
Moves the libxml2 bits to a separate xmlapi file and class, a bunch
of cleanups to xmlbuilder internals dealing with XML stuff.

The main point is to experiment with different XML library impls,
since libxml2 is unfun to deal with and we are having python3
issues like

https://bugzilla.gnome.org/show_bug.cgi?id=776815
2018-02-20 11:23:37 -05:00
Cole Robinson
a20230091b xmlbuilder: Move xpath string ops to their own class
This streamlines the actual libxml2 interaction quite a bit
2018-02-14 14:49:35 -05:00
Cole Robinson
dce3484e95 xmlbuilder: Move all libxml2 interaction to a single class
Makes the boundaries clearer
2018-02-14 11:29:12 -05:00
Cole Robinson
a853387866 xmlbuilder: Remove more redundant xml state
We don't need to carry around a separate xml_node. Dropping it simplifies
a few things
2018-02-14 11:08:09 -05:00
Cole Robinson
d108bbe143 Convert docstrings to standard reStructuredText param format 2018-02-14 11:08:09 -05:00
Cole Robinson
c4fdd1d56a xmlbuilder: Remove unused code 2018-02-14 11:08:09 -05:00
Cole Robinson
8917305a6e Don't use count() for substring checking
Use the idiomatic 'X in Y'
2018-02-14 11:08:09 -05:00
Cole Robinson
dae8642bb1 xmlbuilder: centralize adding child new child prop instances
Currently the domain CPU class has a child property like:

  siblings = XMLChildProperty(_CPUCellSibling)

If a user wants to add a new sibling, we add a convenience function:

    def add_sibling(self):
        obj = _CPUCellSibling(self.conn)
        self.add_child(obj)
        return obj

Rather than require every child property to define a similar matching
helper function, this adds infrastructure in xmlbuilder to do this
generically for every child property. Now callers can do

    obj = guest.cpu.siblings.add_new()
2018-02-08 14:03:47 -05:00
Cole Robinson
8819176ad4 xmlbuilder: Drop unused node_top_xpath 2018-02-07 15:45:38 -05:00
Cole Robinson
598be36862 xmlbuilder: drop is_build monkey patching
It's not needed
2018-02-07 15:38:30 -05:00
Radostin Stoyanov
5146d66126 python3 compat: python3 strings have no decode() 2018-02-06 18:49:17 -05:00
Radostin Stoyanov
978fb25ac7 Wrap keys(), values() in a list
In Python 3 dict.values() [1] , dict.keys() [2] and dict.items() [3]
return a view [4] of the dictionary’s values, keys and items.

In Python 2 these functions return a list. [5] [6] [7]

To resolve this we can convert the result of these function to a list.

[1] https://docs.python.org/3/library/stdtypes.html#dict.values
[2] https://docs.python.org/3/library/stdtypes.html#dict.keys
[3] https://docs.python.org/3/library/stdtypes.html#dict.items
[4] https://docs.python.org/3/library/stdtypes.html#dict-views
[5] https://docs.python.org/2/library/stdtypes.html#dict.items
[6] https://docs.python.org/2/library/stdtypes.html#dict.keys
[7] https://docs.python.org/2/library/stdtypes.html#dict.values
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
63fce081ed pycodestyle: Use isinstance() for type checking
This is E721 in pycodestyle [1]:
   "do not compare types, use ‘isinstance()’"

The main differece between "type() is" and "isinstance()" is that
isinstance() supports inheritance. [1]

This can be seen in the example below:
    >>> type(True) is int
    False
    >>> isinstance(True, int)
    True

As we can see in python 'bool' a subclass of 'int'.

[1] https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
[2] https://docs.python.org/2/library/functions.html#isinstance
2017-10-20 11:49:13 -04:00
Radostin Stoyanov
b93cc3bbc9 pycodestyle: Do not use bare 'except:'
A bare 'except:' catches all exceptions [1], including SystemExit,
KeyboardInterrupt, and GeneratorExit (which is not an error and should
not normally be caught by user code). In situations where you need to
catch all “normal” errors, you can catch the base class for all normal
exceptions, Exception [2].

[1] https://docs.python.org/2/howto/doanddont.html#except
[2] https://docs.python.org/2/library/exceptions.html#Exception
2017-08-02 13:57:43 -04:00
Cole Robinson
a9e3e50046 xmlbuilder: Improve __repr__ a bit
To show child class name as well
2017-03-08 13:59:11 -05:00
Cole Robinson
22b6becd5d guest: Add support for qemu cli passthrough
This is for xml like:

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  ...
  </devices>
  <qemu:commandline>
    <qemu:arg value='-newarg'/>
    <qemu:env name='QEMU_ENV' value='VAL'/>
  </qemu:commandline>
</domain>

Requires some extensions to the xmlbuilder infrastructure
2017-03-06 22:15:46 -05:00
Cole Robinson
8424d7fa7c xmlbuilder: Pass around top level xpath context
Rather than instantiate it for every object. Gives about a 10% speed up
to to the test suite.

Clean up how we pass around this info a bit
2017-03-06 22:15:46 -05:00
Marc-André Lureau
1f0d1d3f7d xmlbuilder: add a __repr__ for XMLBuilder object
To help with debugging.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2017-02-23 19:42:00 -05:00
Cole Robinson
eb2a56f700 util: Move xml_indent to XMLBuilder 2016-08-24 15:56:13 -04:00
Cole Robinson
b08647c2f2 xmlbuilder: Handle setting conditional xpaths correctly
So if xml=<foo> and xpath=./bar[@baz='foo'] and val=XXX, xmlbuilder
previously would generate XML

  <foo>
    <bar>XXX</bar>
  </foo>

But now generates the expected

  <foo>
    <bar baz='foo'/>XXX</bar>
  </foo>

No users yet, but they are incoming
2016-07-18 14:46:50 -04:00
Cole Robinson
835ddc5f77 xmlbuilder: More comments for _build_xpath_node 2016-07-18 14:46:50 -04:00
Cole Robinson
a931a1a6ad xmlbuilder: Opencode single addnode= usage 2016-07-18 14:46:50 -04:00
Cole Robinson
559e813b96 xmlbuilder: Clarify the node 'pretty' helper function 2016-07-18 14:46:50 -04:00
Cole Robinson
d8a0a78805 xmlbuilder: Update XMLProperty docs 2016-07-18 14:46:50 -04:00
Cole Robinson
55327c81b7 xmlbuilder: Support clear()ing an object in place
This gives friendly XML output via virt-xml for clearxml=yes +
extra options: the XML block is editted in place, rather than removed
and with the newchanges appended
2016-05-20 14:51:31 -04:00
Cole Robinson
333103adbf xmlbuilder: minor cleanup 2016-05-20 14:51:31 -04:00
Cole Robinson
f4dfb6de9d Fix recent pylint/pep8 output 2016-04-18 16:42:12 -04:00
Cole Robinson
d449fb6fd5 xmlbuilder: Kill make_xpath_cb
There's no users left, and it's better to come up with a solution at
the caller anyways
2015-09-05 17:20:43 -04:00
Cole Robinson
7786c4b35b xmlbuilder: Make clear() work for child objects
So we can call clear() on a Guest owned VirtualDisk, and it actually
does the correct thing. This allows us to enable clearxml= cli option
for most devices.
2015-09-05 13:16:35 -04:00
Cole Robinson
4d87d2f27b cli: Make child lookup not specific to guest devices
<seclabel> is not singleton nowadays, so we need to extend our
infrastructure to handle non-device child properties. This is part of
that
2015-09-04 16:16:25 -04:00
Cole Robinson
acfb988945 xmlbuilder: Make _add_child and _remove_child public
We have a lot of functions that are just wrappers around these, so
make it public for future use.
2015-09-04 15:47:43 -04:00
Cole Robinson
070664b9e7 tests: Enable property checking for all objects
And loosen restrictions a bit so any read/write will trigger the
tracking.
2015-04-22 16:26:03 -04:00
Cole Robinson
e125aa69d8 nodedev: Handle busted 'system' XML
Libvirt can generated invalid XML for the system nodedev device:

https://bugzilla.redhat.com/show_bug.cgi?id=1184131

This hits at least two people, so catch this specific case, but the
real fix is libvirt not outputing busted XML.
2015-03-26 18:04:23 -04:00
Cole Robinson
0e67ffba2e xmlbuilder: Remove now unused clear_attrs infrastructure 2014-12-04 15:29:12 -05:00
Cole Robinson
86417d42ca osxml: Ensure kernel/initrd/dtb are absolute paths 2014-09-23 14:32:01 -04:00
Cole Robinson
052220cfc8 virtinst: Add DomainCapabilities parser 2014-09-17 18:29:24 -04:00