devicedisk: copy all rbd pool host and auth for volume

(crobinso: add test suite coverage, fix some pylint)
This commit is contained in:
Rauno Väli 2018-01-26 12:27:20 +02:00 committed by Cole Robinson
parent ae5239358a
commit 582c1d3ded
4 changed files with 46 additions and 1 deletions

View File

@ -84,8 +84,13 @@
</disk>
<disk type="network" device="disk">
<driver name="qemu" type="raw"/>
<auth username="admin">
<secret type="ceph" uuid="f65cc5a8-b77b-4254-9030-d50a528fb456"/>
</auth>
<source protocol="rbd" name="rbd/foobar">
<host name="ceph-mon-1.example.com" port="6789"/>
<host name="ceph-mon-2.example.com" port="6789"/>
<host name="ceph-mon-3.example.com" port="6789"/>
</source>
<target dev="vdh" bus="virtio"/>
</disk>

View File

@ -2078,6 +2078,9 @@ ba</description>
<host name='ceph-mon-2.example.com' port='6789'/>
<host name='ceph-mon-3.example.com' port='6789'/>
<name>rbd</name>
<auth type='ceph' username='admin'>
<secret uuid='f65cc5a8-b77b-4254-9030-d50a528fb456'/>
</auth>
</source>
<volume type='network'>

View File

@ -90,6 +90,14 @@ def _is_dir_searchable(uid, username, path):
return bool(re.search("user:%s:..x" % username, out))
class _Host(XMLBuilder):
_XML_PROP_ORDER = ["name", "port"]
_XML_ROOT_NAME = "host"
name = XMLProperty("./@name")
port = XMLProperty("./@port", is_int=True)
class _DiskSeclabel(XMLBuilder):
"""
This is for disk source <seclabel>. It's similar to a domain
@ -473,6 +481,7 @@ class VirtualDisk(VirtualDevice):
"driver_cache", "driver_discard", "driver_detect_zeroes",
"driver_io", "error_policy",
"_source_file", "_source_dev", "_source_dir",
"auth_username", "auth_secret_type", "auth_secret_uuid",
"source_volume", "source_pool", "source_protocol", "source_name",
"source_host_name", "source_host_port",
"source_host_transport", "source_host_socket",
@ -587,6 +596,21 @@ class VirtualDisk(VirtualDevice):
source_pool = XMLProperty("./source/@pool")
source_volume = XMLProperty("./source/@volume")
auth_username = XMLProperty("./auth/@username")
auth_secret_type = XMLProperty("./auth/secret/@type")
auth_secret_uuid = XMLProperty("./auth/secret/@uuid")
def add_host(self, name, port):
obj = _Host(self.conn)
obj.name = name
obj.port = port
self.add_child(obj)
def remove_host(self, obj):
self.remove_child(obj)
hosts = XMLChildProperty(_Host, relative_xpath="./source")
source_name = XMLProperty("./source/@name")
source_protocol = XMLProperty("./source/@protocol")
# Technically multiple host lines can be listed
@ -617,9 +641,17 @@ class VirtualDisk(VirtualDevice):
def _set_source_network_from_storage(self, volxml, poolxml):
self.source_protocol = poolxml.type
logging.debug("disk.set_vol_object: poolxml=\n%s",
dir(poolxml))
if poolxml.auth_type:
self.auth_username = poolxml.auth_username
self.auth_secret_type = poolxml.auth_type
self.auth_secret_uuid = poolxml.auth_secret_uuid
if poolxml.hosts:
self.source_host_name = poolxml.hosts[0].name
self.source_host_port = poolxml.hosts[0].port
for host in poolxml.hosts:
self.add_host(host.name, host.port)
path = ""
if poolxml.source_name:

View File

@ -390,7 +390,8 @@ class StoragePool(_StorageObject):
"format", "hosts",
"_source_dir", "_source_adapter", "_source_device",
"source_name", "target_path",
"permissions"]
"permissions",
"auth_type", "auth_username", "auth_secret_uuid"]
_source_dir = XMLProperty("./source/dir/@path")
@ -413,6 +414,10 @@ class StoragePool(_StorageObject):
default_cb=_default_source_name,
doc=_("Name of the Volume Group"))
auth_type = XMLProperty("./source/auth/@type")
auth_username = XMLProperty("./source/auth/@username")
auth_secret_uuid = XMLProperty("./source/auth/secret/@uuid")
target_path = XMLProperty("./target/path",
default_cb=_get_default_target_path)