Added feature to update the quotas on a project/tenant.
[snaps.git] / snaps / domain / project.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 Project:
18     """
19     SNAPS domain class for Projects. Should contain attributes that
20     are shared amongst cloud providers
21     """
22     def __init__(self, name, project_id, domain_id=None):
23         """
24         Constructor
25         :param name: the project's name
26         :param project_id: the project's id
27         :param domain_id: the project's domain id
28         """
29         self.name = name
30         self.id = project_id
31         self.domain_id = domain_id
32
33     def __eq__(self, other):
34         return self.name == other.name and self.id == other.id
35
36
37 class Domain:
38     """
39     SNAPS domain class for OpenStack Keystone v3+ domains.
40     """
41     def __init__(self, name, domain_id=None):
42         """
43         Constructor
44         :param name: the project's name
45         :param domain_id: the project's domain id
46         """
47         self.name = name
48         self.id = domain_id
49
50     def __eq__(self, other):
51         return self.name == other.name and self.id == other.id
52
53
54 class ComputeQuotas:
55     """
56     SNAPS domain class for holding project quotas for compute services
57     """
58     def __init__(self, nova_quotas=None, **kwargs):
59         """
60         Constructor
61         :param nova_quotas: the OS nova quota object
62         """
63         if nova_quotas:
64             self.metadata_items = nova_quotas.metadata_items
65             self.cores = nova_quotas.cores  # aka. VCPUs
66             self.instances = nova_quotas.instances
67             self.injected_files = nova_quotas.injected_files
68             self.injected_file_content_bytes = nova_quotas.injected_file_content_bytes
69             self.ram = nova_quotas.ram
70             self.fixed_ips = nova_quotas.fixed_ips
71             self.key_pairs = nova_quotas.key_pairs
72         else:
73             self.metadata_items = kwargs.get('metadata_items')
74             self.cores = kwargs.get('cores')  # aka. VCPUs
75             self.instances = kwargs.get('instances')
76             self.injected_files = kwargs.get('injected_files')
77             self.injected_file_content_bytes = kwargs.get(
78                 'injected_file_content_bytes')
79             self.ram = kwargs.get('ram')
80             self.fixed_ips = kwargs.get('fixed_ips')
81             self.key_pairs = kwargs.get('key_pairs')
82
83     def __eq__(self, other):
84         return (self.metadata_items == other.metadata_items and
85                 self.cores == other.cores and
86                 self.instances == other.instances and
87                 self.injected_files == other.injected_files and
88                 self.injected_file_content_bytes == other.injected_file_content_bytes and
89                 self.fixed_ips == other.fixed_ips and
90                 self.key_pairs == other.key_pairs)
91
92
93 class NetworkQuotas:
94     """
95     SNAPS domain class for holding project quotas for networking services
96     """
97     def __init__(self, **neutron_quotas):
98         """
99         Constructor
100         :param neutron_quotas: the OS network quota object
101         """
102
103         # Networks settings here
104         self.security_group = neutron_quotas['security_group']
105         self.security_group_rule = neutron_quotas['security_group_rule']
106         self.floatingip = neutron_quotas['floatingip']
107         self.network = neutron_quotas['network']
108         self.port = neutron_quotas['port']
109         self.router = neutron_quotas['router']
110         self.subnet = neutron_quotas['subnet']
111
112     def __eq__(self, other):
113         return (self.security_group == other.security_group and
114                 self.security_group_rule == other.security_group_rule and
115                 self.floatingip == other.floatingip and
116                 self.network == other.network and
117                 self.port == other.port and
118                 self.router == other.router and
119                 self.subnet == other.subnet)