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