1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Resource class and its manager for projects in Identity V2 API
18 """
19
20 from yakumo import base
21 from yakumo.constant import UNDEF
22 from yakumo import mapper
23
24
25 ATTRIBUTE_MAPPING = [
26 ('id', 'id', mapper.Noop),
27 ('name', 'name', mapper.Noop),
28 ('description', 'description', mapper.Noop),
29 ('is_enabled', 'enabled', mapper.Noop),
30 ]
31
32
34 """resource class for projects on Identity V2 API"""
35
37 """
38 Update properties of a project
39
40 @keyword name: Project name
41 @type name: str
42 @keyword description: Description
43 @type description: str
44 @keyword is_enabled: Whether the project is enabled or not
45 @type is_enabled: bool
46 @rtype: None
47 """
48 super(Resource, self).update(
49 name=name,
50 description=description,
51 is_enabled=is_enabled)
52
54 """
55 Grant roles to users for a project
56
57 @keyword users: List of users
58 @type users: [keystone.user.Resource]
59 @keyword roles: List of roles
60 @type roles: [keystone.role.Resource]
61 @rtype: None
62 """
63 if not isinstance(users, list):
64 users = [users]
65 if not isinstance(roles, list):
66 roles = [roles]
67 for role in roles:
68 for user in users:
69 self._http.put(self._url_resource_path, self._id,
70 "users", user.get_id(),
71 "roles/OS-KSADM", role.get_id())
72
74 """
75 Revoke roles from users for a project
76
77 @keyword users: List of users
78 @type users: [keystone.user.Resource]
79 @keyword roles: List of roles
80 @type roles: [keystone.role.Resource]
81 @rtype: None
82 """
83 if not isinstance(users, list):
84 users = [users]
85 if not isinstance(roles, list):
86 roles = [roles]
87 for role in roles:
88 for user in users:
89 self._http.delete(self._url_resource_path, self._id,
90 "users", user.get_id(),
91 "roles/OS-KSADM", role.get_id())
92
93
95 """manager class for projects on Identity V2 API"""
96
97 resource_class = Resource
98 service_type = 'identity'
99 _attr_mapping = ATTRIBUTE_MAPPING
100 _json_resource_key = 'tenant'
101 _json_resources_key = 'tenants'
102 _url_resource_path = '/tenants'
103
105 """
106 Register a project
107
108 @keyword name: Project name
109 @type name: str
110 @keyword description: Description
111 @type description: str
112 @keyword is_enabled: Whether the project is enabled or not
113 @type is_enabled: bool
114 @return: Created project
115 @rtype: yakumo.keystone.v2.project.Resource
116 """
117 return super(Manager, self).create(
118 name=name,
119 description=description,
120 is_enabled=is_enabled)
121