1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 try:
18 import json
19 except ImportError:
20 import simplejson as json
21
22 from cm_api.endpoints.types import *
23 from cm_api.endpoints.services import ApiService
24
35
37 """
38 The Cloudera Manager instance.
39
40 Provides access to CM configuration and services.
41 """
42
45
46 - def _cmd(self, command, data = None):
47 """
48 Invokes a global command.
49
50 @param command: Command name.
51 @param data: Optional data to send to the command.
52 @return Information about the submitted command.
53 """
54 resp = self._get_resource_root().post("/cm/commands/" + command, data=data)
55 return ApiCommand.from_json_dict(resp, self._get_resource_root())
56
68
79
88
97
99 """
100 Install or update the Cloudera Manager license.
101
102 @param license_text: the license in text form
103 """
104 content = (
105 '--MULTI_BOUNDARY',
106 'Content-Disposition: form-data; name="license"',
107 '',
108 license_text,
109 '--MULTI_BOUNDARY--',
110 '')
111 resp = self._get_resource_root().post('cm/license',
112 data="\r\n".join(content),
113 contenttype='multipart/form-data; boundary=MULTI_BOUNDARY')
114 return ApiLicense.from_json_dict(resp, self._get_resource_root())
115
117 """
118 Retrieve the Cloudera Manager configuration.
119
120 The 'summary' view contains strings as the dictionary values. The full
121 view contains ApiConfig instances as the values.
122
123 @param view: View to materialize ('full' or 'summary')
124 @return: Dictionary with configuration data.
125 """
126 resp = self._get_resource_root().get('/cm/config',
127 params = view and dict(view=view) or None)
128 return json_to_config(resp, view == 'full')
129
131 """
132 Update the CM configuration.
133
134 @param: config Dictionary with configuration to update.
135 @return: Dictionary with updated configuration.
136 """
137 resp = self._get_resource_root().put('/cm/config',
138 data = config_to_json(config))
139 return json_to_config(resp, False)
140
142 """
143 Generate credentials for services configured with Kerberos.
144
145 @return: Information about the submitted command.
146 """
147 return self._cmd('generateCredentials')
148
150 """
151 Runs the host inspector on the configured hosts.
152
153 @return: Information about the submitted command.
154 """
155 return self._cmd('inspectHosts')
156
158 """
159 This method is deprecated as of CM 4.5.
160 You should use collect_diagnostic_data_45.
161 Issue the command to collect diagnostic data.
162
163 @param start_datetime: The start of the collection period. Type datetime.
164 @param end_datetime: The end of the collection period. Type datetime.
165 @param includeInfoLog: Whether to include INFO level log messages.
166 """
167 args = {
168 'startTime': start_datetime.isoformat(),
169 'endTime': end_datetime.isoformat(),
170 'includeInfoLog': includeInfoLog,
171 }
172 return self._cmd('collectDiagnosticData', data=json.dumps(args))
173
175 """
176 Issue the command to collect diagnostic data.
177
178 @param end_datetime: The end of the collection period. Type datetime.
179 @param bundle_size_bytes: The target size for the support bundle in bytes
180 """
181 args = {
182 'endTime': end_datetime.isoformat(),
183 'bundleSizeBytes': bundle_size_bytes
184 }
185 return self._cmd('collectDiagnosticData', data=json.dumps(args))
186
188 """
189 Decommission the specified hosts by decommissioning the slave roles
190 and stopping the remaining ones.
191
192 @param host_names: List of names of hosts to be decommissioned.
193 @return: Information about the submitted command.
194 @since: API v2
195 """
196 return self._cmd('hostsDecommission', data=json.dumps({ApiList.LIST_KEY : host_names}))
197
199 """
200 Recommission the specified hosts by recommissioning the slave roles.
201 This command doesn't start the roles. Use hosts_start_roles for that.
202
203 @param host_names: List of names of hosts to be recommissioned.
204 @return: Information about the submitted command.
205 @since: API v2
206 """
207 return self._cmd('hostsRecommission', data=json.dumps({ApiList.LIST_KEY : host_names}))
208
210 """
211 Start all the roles on the specified hosts.
212
213 @param host_names: List of names of hosts on which to start all roles.
214 @return: Information about the submitted command.
215 @since: API v2
216 """
217 return self._cmd('hostsStartRoles', data=json.dumps({ApiList.LIST_KEY : host_names}))
218
220 """
221 Create a new peer for replication.
222
223 @param name: The name of the peer.
224 @param url: The url of the peer.
225 @param username: The admin username to use to setup the remote side of the peer connection.
226 @param password: The password of the admin user.
227 @return: The newly created peer.
228 @since: API v3
229 """
230 self._require_min_api_version(3)
231 body = json.dumps(
232 ApiCmPeer(self._get_resource_root(),
233 name=name,
234 url=url,
235 username=username,
236 password=password).to_json_dict())
237 resp = self._get_resource_root().post('/cm/peers', data=body)
238 return ApiCmPeer.from_json_dict(resp, self._get_resource_root())
239
252
253 - def update_peer(self,
254 current_name,
255 new_name, new_url, username, password):
256 """
257 Update a replication peer.
258
259 @param current_name: The name of the peer to updated.
260 @param new_name: The new name for the peer.
261 @param new_url: The new url for the peer.
262 @param username: The admin username to use to setup the remote side of the peer connection.
263 @param password: The password of the admin user.
264 @return: The updated peer.
265 @since: API v3
266 """
267 self._require_min_api_version(3)
268 body = json.dumps(
269 ApiCmPeer(self._get_resource_root(),
270 name=new_name,
271 url=new_url,
272 username=username,
273 password=password).to_json_dict())
274 resp = self._get_resource_root().put('/cm/peers/%s' % (current_name, ), data=body)
275 return ApiCmPeer.from_json_dict(resp, self._get_resource_root())
276
287
299
311
313 """
314 Retrieve the default configuration for all hosts.
315
316 @param view: View to materialize.
317 @param view: View to materialize ('full' or 'summary')
318 @return: Dictionary with configuration data.
319 """
320 params = view and dict(view=view) or None
321 resp = self._get_resource_root().get('/cm/allHosts/config', params=params)
322 return json_to_config(resp, view == 'full')
323
325 """
326 Update the default configuration for all hosts.
327
328 @param: config Dictionary with configuration to update.
329 @return: Dictionary with updated configuration.
330 """
331 resp = self._get_resource_root().put('/cm/allHosts/config',
332 data=config_to_json(config))
333 return json_to_config(resp, False)
334