Skip to content

Commit

Permalink
Adds support for serial to libvirt config disks.
Browse files Browse the repository at this point in the history
In order for users to find a volume that they have attached to
a vm, it is valuable to be able to find it in a consistent
location. A following patch wil accomplish this by setting
the serial number of the device to the uuid of the volume.

This patch prepares for that change by allowing serial numbers
to be set in the libvirt config disk object.

Prepares to fix bug 1004328

Change-Id: Iecdfc17b45e1c38df50f844f127c0e95558ab22c
  • Loading branch information
vishvananda committed Aug 16, 2012
1 parent 2f45636 commit 1e7769c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nova/tests/test_libvirt_config.py
Expand Up @@ -319,6 +319,22 @@ def test_config_file(self):
<target bus="ide" dev="/dev/hda"/>
</disk>""")

def test_config_file_serial(self):
obj = config.LibvirtConfigGuestDisk()
obj.source_type = "file"
obj.source_path = "/tmp/hello"
obj.target_dev = "/dev/hda"
obj.target_bus = "ide"
obj.serial = "7a97c4a3-6f59-41d4-bf47-191d7f97f8e9"

xml = obj.to_xml()
self.assertXmlEqual(xml, """
<disk type="file" device="disk">
<source file="/tmp/hello"/>
<target bus="ide" dev="/dev/hda"/>
<serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>
</disk>""")

def test_config_block(self):
obj = config.LibvirtConfigGuestDisk()
obj.source_type = "block"
Expand Down
4 changes: 4 additions & 0 deletions nova/virt/libvirt/config.py
Expand Up @@ -363,6 +363,7 @@ def __init__(self, **kwargs):
self.auth_username = None
self.auth_secret_type = None
self.auth_secret_uuid = None
self.serial = None

def format_dom(self):
dev = super(LibvirtConfigGuestDisk, self).format_dom()
Expand Down Expand Up @@ -404,6 +405,9 @@ def format_dom(self):
dev.append(etree.Element("target", dev=self.target_dev,
bus=self.target_bus))

if self.serial is not None:
dev.append(self._text_node("serial", self.serial))

return dev


Expand Down

0 comments on commit 1e7769c

Please sign in to comment.