Kami commented on a change in pull request #1478:
URL: https://github.com/apache/libcloud/pull/1478#discussion_r470844475



##########
File path: libcloud/container/drivers/lxd.py
##########
@@ -1155,21 +1278,66 @@ def ex_get_storage_pool_volume(self, pool_id, type, 
name):
         response_dict = response.parse_body()
         assert_response(response_dict=response_dict, status_code=200)
 
-        return self._to_storage_volume(response_dict["metadata"])
+        return self._to_storage_volume(pool_id=pool_id,
+                                       metadata=response_dict["metadata"])
 
-    def ex_create_storage_pool_volume(self, pool_id, definition):
+    def ex_get_volume_by_name(self, name, vol_type="custom"):
         """
-        Create a new storage volume on a given storage pool
+        Returns a storage volume that has the given name.
+        The function will loop over all storage-polls available
+        and will pick the first volume from the first storage poll
+        that matches the given name. Thus this function can be
+        quite expensive
 
-        Operation: sync or async (when copying an existing volume)
+        :param name: The name of the volume to look for
+        :type  name: str
+
+        :param vol_type: The type of the volume default is custom
+        :type  vol_type: str
 
         :return: A StorageVolume  representing a storage volume
         """
 
+        req = '/%s/storage-pools' % self.version
+        response = self.connection.request(req)
+        response_dict = response.parse_body()
+        assert_response(response_dict=response_dict, status_code=200)
+
+        pools = response_dict['metadata']
+
+        for pool in pools:
+
+            pool_id = pool.split('/')[-1]
+
+            volumes = self.ex_list_storage_pool_volumes(pool_id=pool_id)
+
+            for vol in volumes:
+                if vol.name == name:
+                    return vol
+
+        return self._to_storage_volume(pool_id=None,

Review comment:
       Hm, shouldn't we simply return None if a matching volume doesn't exist?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to