1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from cinderclient.exceptions import NotFound
21 from snaps.config.qos import QoSConfig
22 from snaps.openstack.openstack_creator import OpenStackVolumeObject
23 from snaps.openstack.utils import cinder_utils
25 __author__ = 'spisarski'
27 logger = logging.getLogger('create_qos')
29 IMAGE_ACTIVE_TIMEOUT = 600
31 STATUS_ACTIVE = 'active'
34 class OpenStackQoS(OpenStackVolumeObject):
36 Class responsible for managing an qos in OpenStack
39 def __init__(self, os_creds, qos_settings):
42 :param os_creds: The OpenStack connection credentials
43 :param qos_settings: The qos settings
46 super(self.__class__, self).__init__(os_creds)
48 self.qos_settings = qos_settings
53 Loads the existing QoS
54 :return: The QoS domain object or None
56 super(self.__class__, self).initialize()
58 self.__qos = cinder_utils.get_qos(
59 self._cinder, qos_settings=self.qos_settings)
65 Creates the qos in OpenStack if it does not already exist and returns
67 :return: The QoS domain object or None
72 self.__qos = cinder_utils.create_qos(
73 self._cinder, self.qos_settings)
76 'Created qos with name - %s', self.qos_settings.name)
82 Cleanse environment of all artifacts
87 cinder_utils.delete_qos(self._cinder, self.__qos)
95 Returns the domain QoS object as it was populated when create() was
102 class Consumer(enum.Enum):
104 QoS Specification consumer types
105 deprecated - use snaps.config.qos.Consumer
107 front_end = 'front-end'
108 back_end = 'back-end'
112 class QoSSettings(QoSConfig):
114 Class to hold the configuration settings required for creating OpenStack
119 def __init__(self, **kwargs):
120 from warnings import warn
121 warn('Use snaps.config.qos.QoSConfig instead',
123 super(self.__class__, self).__init__(**kwargs)
126 class QoSCreationError(Exception):
128 Exception to be thrown when an qos cannot be created
131 def __init__(self, message):
132 Exception.__init__(self, message)