Refactoring of VolumeSettings to extend VolumeConfig
[snaps.git] / snaps / openstack / create_volume.py
index 9baad7e..c134ca1 100644 (file)
@@ -18,6 +18,7 @@ import time
 
 from cinderclient.exceptions import NotFound
 
+from snaps.config.volume import VolumeConfig
 from snaps.openstack.openstack_creator import OpenStackVolumeObject
 from snaps.openstack.utils import cinder_utils
 
@@ -29,7 +30,8 @@ VOLUME_ACTIVE_TIMEOUT = 300
 VOLUME_DELETE_TIMEOUT = 60
 POLL_INTERVAL = 3
 STATUS_ACTIVE = 'available'
-STATUS_FAILED = 'failed'
+STATUS_IN_USE = 'in-use'
+STATUS_FAILED = 'error'
 STATUS_DELETED = 'deleted'
 
 
@@ -97,7 +99,7 @@ class OpenStackVolume(OpenStackVolumeObject):
         """
         if self.__volume:
             try:
-                if self.volume_active(block=True):
+                if self.volume_active():
                     cinder_utils.delete_volume(self._cinder, self.__volume)
                 else:
                     logger.warn('Timeout waiting to delete volume %s',
@@ -144,6 +146,14 @@ class OpenStackVolume(OpenStackVolumeObject):
         return self._volume_status_check(STATUS_ACTIVE, block, timeout,
                                          poll_interval)
 
+    def volume_in_use(self):
+        """
+        Returns true when the volume status returns the value of
+        expected_status_code
+        :return: T/F
+        """
+        return self._volume_status_check(STATUS_IN_USE, False, 0, 0)
+
     def volume_deleted(self, block=False, poll_interval=POLL_INTERVAL):
         """
         Returns true when the VM status returns the value of
@@ -179,7 +189,7 @@ class OpenStackVolume(OpenStackVolumeObject):
         if block:
             start = time.time()
         else:
-            start = time.time() - timeout + 10
+            start = time.time() - timeout + 1
 
         while timeout > time.time() - start:
             status = self._status(expected_status_code)
@@ -219,45 +229,18 @@ class OpenStackVolume(OpenStackVolumeObject):
         return status == expected_status_code
 
 
-class VolumeSettings:
-    def __init__(self, **kwargs):
-        """
-        Constructor
-        :param name: the volume's name (required)
-        :param description: the volume's name (required)
-        :param size: the volume's size in GB (default 1)
-        :param image_name: when a glance image is used for the image source
-                           (optional)
-        :param type_name: the associated volume's type name (optional)
-        :param availability_zone: the name of the compute server on which to
-                                  deploy the volume (optional)
-        :param multi_attach: when true, volume can be attached to more than one
-                             server (default False)
-        """
-
-        self.name = kwargs.get('name')
-        self.description = kwargs.get('description')
-        self.size = int(kwargs.get('size', 1))
-        self.image_name = kwargs.get('image_name')
-        self.type_name = kwargs.get('type_name')
-        self.availability_zone = kwargs.get('availability_zone')
-
-        if kwargs.get('availability_zone'):
-            self.multi_attach = bool(kwargs.get('availability_zone'))
-        else:
-            self.multi_attach = False
-
-        if not self.name:
-            raise VolumeSettingsError("The attribute name is required")
-
-
-class VolumeSettingsError(Exception):
+class VolumeSettings(VolumeConfig):
     """
-    Exception to be thrown when an volume settings are incorrect
+    Class to hold the configuration settings required for creating OpenStack
+    Volume Type Encryption objects
+    deprecated
     """
 
-    def __init__(self, message):
-        Exception.__init__(self, message)
+    def __init__(self, **kwargs):
+        from warnings import warn
+        warn('Use snaps.config.volume.VolumeConfig instead',
+             DeprecationWarning)
+        super(self.__class__, self).__init__(**kwargs)
 
 
 class VolumeCreationError(Exception):