Refactoring of ProjectSettings to extend ProjectConfig
[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         """
36
37         self.name = kwargs.get('name')
38         self.domain_name = kwargs.get(
39             'domain', kwargs.get('domain', 'Default'))
40
41         self.description = kwargs.get('description')
42         if kwargs.get('enabled') is not None:
43             self.enabled = kwargs['enabled']
44         else:
45             self.enabled = True
46
47         self.users = kwargs.get('users', list())
48
49         if not self.name:
50             raise ProjectConfigError(
51                 "The attribute name is required for ProjectConfig")
52
53
54 class ProjectConfigError(Exception):
55     """
56     Exception to be thrown when project settings attributes are incorrect
57     """