Added utility function to retrieve the names of all hosts with a hypervisor.
[snaps.git] / snaps / config / volume.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 from neutronclient.common.utils import str2bool
16
17
18 class VolumeConfig(object):
19     def __init__(self, **kwargs):
20         """
21         Constructor
22         :param name: the volume's name (required)
23         :param description: the volume's name (optional)
24         :param size: the volume's size in GB (default 1)
25         :param image_name: when a glance image is used for the image source
26                            (optional)
27         :param type_name: the associated volume's type name (optional)
28         :param availability_zone: the name of the compute server on which to
29                                   deploy the volume (optional)
30         :param multi_attach: when true, volume can be attached to more than one
31                              server (default False)
32         """
33
34         self.name = kwargs.get('name')
35         self.description = kwargs.get('description')
36         self.size = int(kwargs.get('size', 1))
37         self.image_name = kwargs.get('image_name')
38         self.type_name = kwargs.get('type_name')
39         self.availability_zone = kwargs.get('availability_zone')
40
41         if kwargs.get('multi_attach'):
42             self.multi_attach = str2bool(str(kwargs.get('multi_attach')))
43         else:
44             self.multi_attach = False
45
46         if not self.name:
47             raise VolumeConfigError("The attribute name is required")
48
49
50 class VolumeConfigError(Exception):
51     """
52     Exception to be thrown when an volume settings are incorrect
53     """
54
55     def __init__(self, message):
56         Exception.__init__(self, message)