79c316b08786178fc5ee996fe1eb940a3983395e
[snaps.git] / snaps / config / 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 ProjectConfig(object):
18     """
19     Class to hold the configuration settings required for creating OpenStack
20     project objects
21     """
22
23     def __init__(self, **kwargs):
24
25         """
26         Constructor
27         :param name: the project's name (required)
28         :param domain or domain_name: the project's domain name
29                                       (default = 'Default').
30                                       Field is used for v3 clients
31         :param description: the description (optional)
32         :param users: list of users to associate project to (optional)
33         :param enabled: denotes whether or not the project is enabled
34                         (default True)
35         :param quotas: quota values to override (optional)
36         """
37
38         self.name = kwargs.get('name')
39         self.domain_name = kwargs.get(
40             'domain', kwargs.get('domain', 'Default'))
41
42         self.description = kwargs.get('description')
43         if kwargs.get('enabled') is not None:
44             self.enabled = kwargs['enabled']
45         else:
46             self.enabled = True
47
48         self.users = kwargs.get('users', list())
49
50         self.quotas = kwargs.get('quotas')
51
52         if not self.name:
53             raise ProjectConfigError(
54                 "The attribute name is required for ProjectConfig")
55
56
57 class ProjectConfigError(Exception):
58     """
59     Exception to be thrown when project settings attributes are incorrect
60     """