openstack team mailing list archive
-
openstack team
-
Mailing list archive
-
Message #08426
答复: RFC: Rewritten libvirt driver XML generation
Hi all:
I tried kvm on my openstack on ubuntu11.10 with the libvirt.xml file as
follows:
<domain type='kvm'>
<name>instance-00000011</name>
<memory>2097152</memory>
<os>
<type>hvm</type>
<boot dev="hd" />
</os>
<features>
<acpi/>
</features>
<vcpu>1</vcpu>
<devices>
<sound model='ac97'/>
<input type='tablet' bus='usb'/>
<disk type='file'>
<driver type='qcow2'/>
<source
file='/opt/stack/nova/nova/..//instances/instance-00000011/disk'/>
<target dev='vda' bus='ide'/>
</disk>
<disk type='file'>
<driver type='qcow2'/>
<source
file='/opt/stack/nova/nova/..//instances/instance-00000011/disk.local'/>
<target dev='vdb' bus='ide'/>
</disk>
<interface type='bridge'>
<source bridge='br100'/>
<mac address='02:16:3e:44:a1:dd'/>
<filterref
filter="nova-instance-instance-00000011-02163e44a1dd">
<parameter name="IP" value="10.0.0.2" />
<parameter name="DHCPSERVER" value="10.0.0.1" />
</filterref>
</interface>
<!-- The order is significant here. File must be defined first -->
<serial type="file">
<source
path='/opt/stack/nova/nova/..//instances/instance-00000011/console.log'/>
<target port='1'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target port='0'/>
</console>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target port='0'/>
</serial>
<graphics type='vnc' port='-1' autoport='yes' keymap='en-us'
listen='0.0.0.0'/>
</devices>
</domain>
So it works well.
Howerver, I want change the remote access method by spice, I simply changed
the libvirt.xml as follows:
<domain type='kvm'>
<name>instance-00000011</name>
<memory>2097152</memory>
<os>
<type>hvm</type>
<boot dev="hd" />
</os>
<features>
<acpi/>
</features>
<vcpu>1</vcpu>
<devices>
<sound model='ac97'/>
<input type='tablet' bus='usb'/>
<disk type='file'>
<driver type='qcow2'/>
<source
file='/opt/stack/nova/nova/..//instances/instance-00000011/disk'/>
<target dev='vda' bus='ide'/>
</disk>
<disk type='file'>
<driver type='qcow2'/>
<source
file='/opt/stack/nova/nova/..//instances/instance-00000011/disk.local'/>
<target dev='vdb' bus='ide'/>
</disk>
<interface type='bridge'>
<source bridge='br100'/>
<mac address='02:16:3e:44:a1:dd'/>
<filterref
filter="nova-instance-instance-00000011-02163e44a1dd">
<parameter name="IP" value="10.0.0.2" />
<parameter name="DHCPSERVER" value="10.0.0.1" />
</filterref>
</interface>
<!-- The order is significant here. File must be defined first -->
<serial type="file">
<source
path='/opt/stack/nova/nova/..//instances/instance-00000011/console.log'/>
<target port='1'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target port='0'/>
</console>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target port='0'/>
</serial>
<graphics type='spice' port='-1' autoport='yes' keymap='en-us'
listen='0.0.0.0'/>
</devices>
</domain>
As you can see, I just change <graphics type='vnc' port='-1' autoport='yes'
keymap='en-us' listen='0.0.0.0'/> to <graphics type='spice' port='-1'
autoport='yes' keymap='en-us' listen='0.0.0.0'/> , But it called the
error as follows:
libvirtError: internal error Process exited while reading console log
output: char device redirected to /dev/pts/12
TRACE: do_spice_init: starting 0.8.1
TRACE: do_spice_init: statistics shm_open failed, Permission denied"
I wish someone can give me some help! Thanks!
发件人: openstack-bounces+wangsuyi640=gmail.com@xxxxxxxxxxxxxxxxxxx
[mailto:openstack-bounces+wangsuyi640=gmail.com@xxxxxxxxxxxxxxxxxxx] 代表
Joshua Harlow
发送时间: 2012年3月9日 4:34
收件人: Daniel P. Berrange; openstack
主题: Re: [Openstack] RFC: Rewritten libvirt driver XML generation
Awesome!
Great job :-)
+1 milllion
On 3/8/12 11:03 AM, "Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
Back in January Joshua Harlow raised the question of whether we should
replace the usage of Cheetah templates for generating XML in the libvirt
driver:
https://lists.launchpad.net/openstack/msg06481.html
Since then I have had some time to work on this idea and now have a
working branch available for testing. I don't want to push this to
Gerrit right now, since it isn't really material suitable for the
Essex release, and AFAICT we don't have a separate review/GIT branch
for non-Essex feature dev work.
Thus for now I have pushed it to a private a branch here:
https://github.com/berrange/nova/tree/libvirt-xml-config-v1
The foundation for the work is early in the series, where I create
a new nova/virt/libvirt/config.py module with a set of classes for
representing the aspects of libvirt configuration that Nova is interested
in. Each of the config classes implement a format_dom() method for
serializing themselves to an lxml.etree.Element DOM instance.
Currently these objects can be used to generate XML, but in the future
they will also be able to parse the XML. For this they will implement
a parse_dom() method which will de-deserialize the xml.etree.Element
DOM.
Joshua's original posting had talked about having separate layers
for the config objects vs the serialization. IMHO this would be
overkill, just adding abstraction for little real world gain. We
don't need to have pluggable XML serialization impls, one good one
is sufficient.
The rest of the series is simply a piece-by-piece conversion of the
template code to the new object based APIs. I did it in a great many
steps, to make it easier to review & test the changes.
As well as the guest config creation, I also took the opportunity to
change two others places where we generate XML. The host CPU comparison
code and the domain snapshot creation. There is still one place left
to fix, the firewall filter generator.
By the end of the series we have the following benefits
- No code anywhere outside config.py ever needs to know about XML
documents
- We actually have proper XML escaping, making us safe from potential
exploits in that area
- There is clean separation of the logic for constructing the
guest config, from the logic for generating XML.
My next step following on from this is to actually start making the
config generation more flexible, removing alot of hardcoding it
currently does (eg horrible global virtio on/off switch). This will
entail tagging images on import with an operating system identifier,
and then using libosinfo to query exactly what hardware devices the
OS supports & picking the optimal ones.
I tested this on a KVM host and verified the XML generated for the
guest before/after was the same. I've not tested all the possible
block / network driver combinations though, so might have broken
something not covered by the test suite
Diffstat for the whole patch series
b/nova/tests/fakelibvirt.py | 11
b/nova/tests/test_libvirt.py | 67 +++--
b/nova/tests/test_libvirt_config.py | 448
+++++++++++++++++++++++++++++++++
b/nova/tests/test_libvirt_vif.py | 54 +---
b/nova/virt/libvirt/config.py | 420 +++++++++++++++++++++++++++++++
b/nova/virt/libvirt/connection.py | 476
++++++++++++++++++++++--------------
b/nova/virt/libvirt/vif.py | 102 ++++---
b/nova/virt/libvirt/volume.py | 52 ++-
nova/virt/cpuinfo.xml.template | 9
nova/virt/libvirt.xml.template | 188 --------------
10 files changed, 1323 insertions(+), 504 deletions(-)
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/
:|
|: http://libvirt.org -o- http://virt-manager.org
:|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/
:|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc
:|
Follow ups
References