Merge "Third patch for volume support."
[snaps.git] / snaps / domain / 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
16
17 class Volume:
18     """
19     SNAPS domain object for Volumes. Should contain attributes that
20     are shared amongst cloud providers
21     """
22     def __init__(self, name, volume_id, description, size, vol_type,
23                  availability_zone, multi_attach):
24         """
25         Constructor
26         :param name: the volume's name
27         :param volume_id: the volume's id
28         :param description: the volume's description
29         :param size: the volume's size in GB
30         :param vol_type: the volume's type
31         :param availability_zone: the volume's availability zone
32         :param multi_attach: When true, volume can be attached to multiple VMs
33         """
34         self.name = name
35         self.id = volume_id
36         self.description = description
37         self.size = size
38         self.type = vol_type
39         self.availability_zone = availability_zone
40         self.multi_attach = multi_attach
41
42     def __eq__(self, other):
43         return (self.name == other.name and self.id == other.id
44                 and self.description == other.description
45                 and self.size == other.size
46                 and self.type == other.type
47                 and self.availability_zone == other.availability_zone
48                 and self.multi_attach == other.multi_attach)
49
50
51 class VolumeType:
52     """
53     SNAPS domain object for Volume Types. Should contain attributes that
54     are shared amongst cloud providers
55     """
56     def __init__(self, name, volume_type_id, public, encryption, qos_spec):
57         """
58         Constructor
59         :param name: the volume's name
60         :param volume_type_id: the volume type's id
61         :param public: True if public
62         :param encryption: instance of a VolumeTypeEncryption domain object
63         :param qos_spec: instance of a QoSSpec domain object
64         """
65         self.name = name
66         self.id = volume_type_id
67         self.public = public
68         self.encryption = encryption
69         self.qos_spec = qos_spec
70
71     def __eq__(self, other):
72         return (self.name == other.name and self.id == other.id
73                 and self.public == other.public
74                 and self.encryption == other.encryption
75                 and self.qos_spec == other.qos_spec)
76
77
78 class VolumeTypeEncryption:
79     """
80     SNAPS domain object for Volume Types. Should contain attributes that
81     are shared amongst cloud providers
82     """
83     def __init__(self, volume_encryption_id, volume_type_id,
84                  control_location, provider, cipher, key_size):
85         """
86         Constructor
87         :param volume_encryption_id: the encryption id
88         :param volume_type_id: the associated volume type's id
89         :param control_location: front-end | back-end
90         :param provider: the encryption provider class
91         :param cipher: the encryption cipher
92         :param key_size: the encryption key size
93         """
94         self.id = volume_encryption_id
95         self.volume_type_id = volume_type_id
96         self.control_location = control_location
97         self.provider = provider
98         self.cipher = cipher
99         self.key_size = key_size
100
101     def __eq__(self, other):
102         return (self.id == other.id
103                 and self.volume_type_id == other.volume_type_id
104                 and self.control_location == other.control_location
105                 and self.provider == other.provider
106                 and self.cipher == other.cipher
107                 and self.key_size == other.key_size)
108
109
110 class QoSSpec:
111     """
112     SNAPS domain object for Volume Types. Should contain attributes that
113     are shared amongst cloud providers
114     """
115     def __init__(self, name, spec_id, consumer):
116         """
117         Constructor
118         :param name: the volume's name
119         :param spec_id: the QoS Spec's id
120         """
121         self.name = name
122         self.id = spec_id
123         self.consumer = consumer
124
125     def __eq__(self, other):
126         return (self.name == other.name and self.id == other.id
127                 and self.consumer == other.consumer)