Subject: devicedisk: copy all rbd pool host and auth for volume
From: Rauno Väli rauno@oyenetwork.com Fri Jan 26 12:27:20 2018 +0200
Date: Tue Jan 30 11:30:22 2018 -0500:
Git: 582c1d3dedbb09f987039213648d9f37ef80fd7c

(crobinso: add test suite coverage, fix some pylint)

Index: virt-manager-1.4.1/tests/cli-test-xml/compare/virt-install-many-devices.xml
===================================================================
--- virt-manager-1.4.1.orig/tests/cli-test-xml/compare/virt-install-many-devices.xml
+++ virt-manager-1.4.1/tests/cli-test-xml/compare/virt-install-many-devices.xml
@@ -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>
Index: virt-manager-1.4.1/tests/testdriver.xml
===================================================================
--- virt-manager-1.4.1.orig/tests/testdriver.xml
+++ virt-manager-1.4.1/tests/testdriver.xml
@@ -2040,6 +2040,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'>
Index: virt-manager-1.4.1/virtinst/devicedisk.py
===================================================================
--- virt-manager-1.4.1.orig/virtinst/devicedisk.py
+++ virt-manager-1.4.1/virtinst/devicedisk.py
@@ -90,6 +90,14 @@ def _is_dir_searchable(uid, username, pa
     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
@@ -472,6 +480,7 @@ class VirtualDisk(VirtualDevice):
         "driver_name", "driver_type",
         "driver_cache", "driver_discard", "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",
@@ -585,6 +594,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
@@ -615,9 +639,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:
Index: virt-manager-1.4.1/virtinst/storage.py
===================================================================
--- virt-manager-1.4.1.orig/virtinst/storage.py
+++ virt-manager-1.4.1/virtinst/storage.py
@@ -395,7 +395,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")
@@ -420,6 +421,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)
 
