libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject libcloud git commit: LIBCLOUD-764: Return proper volume state for CloudStack volumes
Date Tue, 03 Nov 2015 14:47:45 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 728bd8873 -> 08bb5a04b


LIBCLOUD-764: Return proper volume state for CloudStack volumes

Map the 'state' value being returned by the CloudStack to a
libcloud StorageVolumeState.

Signed-off-by: runseb <runseb@gmail.com>

This closes #615


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/08bb5a04
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/08bb5a04
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/08bb5a04

Branch: refs/heads/trunk
Commit: 08bb5a04b0e79f0f6b83ed6d2b00117b16601b2d
Parents: 728bd88
Author: Wido den Hollander <wido@pcextreme.nl>
Authored: Tue Oct 27 14:18:05 2015 +0100
Committer: runseb <runseb@gmail.com>
Committed: Tue Nov 3 15:47:20 2015 +0100

----------------------------------------------------------------------
 CHANGES.rst                            |  4 ++++
 libcloud/compute/drivers/cloudstack.py | 35 +++++++++++++++++++++++++++--
 2 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/08bb5a04/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index d0512f5..90c5c11 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -15,6 +15,10 @@ Compute
   (GITHUB-617)
   [Wido den Hollander]
 
+- Return proper volume state for CloudStack volumes.
+  (GITHUB-615, LIBCLOUD-764)
+  [Wido den Hollander]
+    
 Storage
 ~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/08bb5a04/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 0d06786..65572cf 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -28,7 +28,7 @@ from libcloud.compute.base import Node, NodeDriver, NodeImage, NodeLocation
 from libcloud.compute.base import NodeSize, StorageVolume, VolumeSnapshot
 from libcloud.compute.base import KeyPair
 from libcloud.compute.types import NodeState, LibcloudError
-from libcloud.compute.types import KeyPairDoesNotExistError
+from libcloud.compute.types import KeyPairDoesNotExistError, StorageVolumeState
 from libcloud.utils.networking import is_private_subnet
 
 
@@ -1241,6 +1241,18 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         'Error': NodeState.TERMINATED
     }
 
+    VOLUME_STATE_MAP = {
+        'Creating': StorageVolumeState.CREATING,
+        'Destroying': StorageVolumeState.DELETING,
+        'Expunging': StorageVolumeState.DELETING,
+        'Destroy': StorageVolumeState.DELETED,
+        'Expunged': StorageVolumeState.DELETED,
+        'Allocated': StorageVolumeState.AVAILABLE,
+        'Ready': StorageVolumeState.AVAILABLE,
+        'Snapshotting': StorageVolumeState.BACKUP,
+        'UploadError': StorageVolumeState.ERROR
+    }
+
     def __init__(self, key, secret=None, secure=True, host=None,
                  path=None, port=None, url=None, *args, **kwargs):
         """
@@ -2112,9 +2124,12 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
 
         volumeResponse = requestResult['volume']
 
+        state = self._to_volume_state(volumeResponse)
+
         return StorageVolume(id=volumeResponse['id'],
                              name=name,
                              size=size,
+                             state=state,
                              driver=self,
                              extra=dict(name=volumeResponse['name']))
 
@@ -2176,9 +2191,12 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
             if 'tags' in vol:
                 extra['tags'] = self._get_resource_tags(vol['tags'])
 
+            state = self._to_volume_state(vol)
+
             list_volumes.append(StorageVolume(id=vol['id'],
                                               name=vol['name'],
                                               size=vol['size'],
+                                              state=state,
                                               driver=self,
                                               extra=extra))
         return list_volumes
@@ -2210,7 +2228,9 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         if 'tags' in vol:
             extra['tags'] = self._get_resource_tags(vol['tags'])
 
-        volume = StorageVolume(id=vol['id'], name=vol['name'],
+        state = self._to_volume_state(vol)
+
+        volume = StorageVolume(id=vol['id'], name=vol['name'], state=state,
                                size=vol['size'], driver=self, extra=extra)
         return volume
 
@@ -4705,3 +4725,14 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
                 extra[attribute] = None
 
         return extra
+
+    def _to_volume_state(self, vol):
+        state = self.VOLUME_STATE_MAP.get(vol['state'],
+                                          StorageVolumeState.UNKNOWN)
+
+        # If a volume is 'Ready' and is attached to a virtualmachine, set
+        # the status to INUSE
+        if state == StorageVolumeState.AVAILABLE and 'virtualmachineid' in vol:
+            state = StorageVolumeState.INUSE
+
+        return state


Mime
View raw message