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