1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import web
18
19 from pulp.server.api.consumer_group import ConsumerGroupApi
20 from pulp.server.webservices.controllers.base import JSONController
21 from pulp.server.webservices.role_check import RoleCheck
22
23
24
25 api = ConsumerGroupApi()
30
31 @JSONController.error_handler
32 @RoleCheck(admin=True)
34 """
35 List all available consumergroups.
36 @return: a list of all consumergroups
37 """
38
39 return self.ok(api.consumergroups())
40
41 @JSONController.error_handler
42 @RoleCheck(admin=True)
44 """
45 Create a new consumer group.
46 @return: consumer group metadata on successful creation
47 """
48 consumergroup_data = self.params()
49 consumergroup = api.create(consumergroup_data['id'], consumergroup_data['description'],
50 consumergroup_data['consumerids'])
51 return self.created(consumergroup['id'], consumergroup)
52
53 @JSONController.error_handler
54 @RoleCheck(admin=True)
56 """
57 @return: True on successful deletion of all consumer groups
58 """
59 api.clean()
60 return self.ok(True)
61
64
65 @JSONController.error_handler
66 @RoleCheck(admin=True)
68 """
69 Get a consumergroup's meta data.
70 @param id: consumer group id
71 @return: consumer group meta data
72 """
73 return self.ok(api.consumergroup(id))
74
75 @JSONController.error_handler
76 @RoleCheck(admin=True)
85
86 @JSONController.error_handler
87 @RoleCheck(admin=True)
89 """
90 Delete a consumer group.
91 @param id: consumer group id
92 @return: True on successful deletion of consumer
93 """
94 api.delete(id=id)
95 return self.ok(True)
96
98
99
100
101 exposed_actions = (
102 'bind',
103 'unbind',
104 'add_consumer',
105 'delete_consumer',
106 'installpackages',
107 'installerrata',
108 )
109
110 - def bind(self, id):
111 """
112 Bind (subscribe) all the consumers in a consumergroup to a repository.
113 @param id: consumer group id
114 """
115 data = self.params()
116 api.bind(id, data)
117 return self.ok(True)
118
120 """
121 Unbind (unsubscribe) all the consumers in a consumergroup from a repository.
122 @param id: consumer group id
123 """
124 data = self.params()
125 api.unbind(id, data)
126 return self.ok(None)
127
128
130 """
131 Add a consumer to the group.
132 @param id: consumer group id
133 """
134 data = self.params()
135 api.add_consumer(id, data)
136 return self.ok(True)
137
139 """
140 Delete a consumer from the group.
141 @param id: consumer group id
142 """
143 data = self.params()
144 api.delete_consumer(id, data)
145 return self.ok(None)
146
147
149 """
150 Install packages.
151 Body contains a list of package names.
152 """
153 data = self.params()
154 names = data.get('packagenames', [])
155 return self.ok(api.installpackages(id, names))
156
158 """
159 Install applicable errata
160 Body contains a list of consumer groups
161 """
162 data = self.params()
163 errataids = data.get('errataids', [])
164 types = data.get('types', [])
165 return self.ok(api.installerrata(id, errataids, types))
166
167 @JSONController.error_handler
168 @RoleCheck(admin=True)
169 - def POST(self, id, action_name):
170 """
171 Consumer action dispatcher
172 @type id: str
173 @param id: controller id
174 @type action_name: str
175 @param action_name: action name
176 """
177 action = getattr(self, action_name, None)
178 if action is None:
179 return self.internal_server_error('No implementation for %s found' % action_name)
180 return action(id)
181
182
183
184
185 URLS = (
186 '/$', 'ConsumerGroups',
187 '/([^/]+)/$', 'ConsumerGroup',
188 '/([^/]+)/(%s)/$' % '|'.join(ConsumerGroupActions.exposed_actions),
189 'ConsumerGroupActions',
190 )
191
192 application = web.application(URLS, globals())
193