1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from cm_api.endpoints.types import *
18 from cm_api.endpoints.services import ApiService
19
30
32 """
33 The Cloudera Manager instance.
34
35 Provides access to CM configuration and services.
36 """
37
40
43
45 """
46 Retrieve a list of running global commands.
47
48 @param view: View to materialize ('full' or 'summary')
49 @return: A list of running commands.
50 """
51 return self._get("commands", ApiCommand, True,
52 params = view and dict(view=view) or None)
53
55 """
56 Setup the Cloudera Management Service.
57
58 @param service_setup_info: ApiServiceSetupInfo object.
59 @return: The management service instance.
60 """
61 return self._put("service", ApiService, data=service_setup_info)
62
64 """
65 Delete the Cloudera Management Service.
66
67 @return: The deleted management service instance.
68 """
69 return self._delete("service", ApiService, api_version=6)
70
72 """
73 Return the Cloudera Management Services instance.
74
75 @return: An ApiService instance.
76 """
77 return self._get("service", ApiService)
78
80 """
81 Return information about the currently installed license.
82
83 @return: License information.
84 """
85 return self._get("license", ApiLicense)
86
88 """
89 Install or update the Cloudera Manager license.
90
91 @param license_text: the license in text form
92 """
93 content = (
94 '--MULTI_BOUNDARY',
95 'Content-Disposition: form-data; name="license"',
96 '',
97 license_text,
98 '--MULTI_BOUNDARY--',
99 '')
100 resp = self._get_resource_root().post('cm/license',
101 data="\r\n".join(content),
102 contenttype='multipart/form-data; boundary=MULTI_BOUNDARY')
103 return ApiLicense.from_json_dict(resp, self._get_resource_root())
104
106 """
107 Retrieve the Cloudera Manager configuration.
108
109 The 'summary' view contains strings as the dictionary values. The full
110 view contains ApiConfig instances as the values.
111
112 @param view: View to materialize ('full' or 'summary')
113 @return: Dictionary with configuration data.
114 """
115 return self._get_config("config", view)
116
118 """
119 Update the CM configuration.
120
121 @param config: Dictionary with configuration to update.
122 @return: Dictionary with updated configuration.
123 """
124 return self._update_config("config", config)
125
127 """
128 Generate credentials for services configured with Kerberos.
129
130 @return: Information about the submitted command.
131 """
132 return self._cmd('generateCredentials')
133
135 """
136 Imports the KDC Account Manager credentials needed by Cloudera
137 Manager to create kerberos principals needed by CDH services.
138
139 @param username Username of the Account Manager. Full name including the Kerberos
140 realm must be specified.
141 @param password Password for the Account Manager.
142
143 @return: Information about the submitted command.
144
145 @since API v7
146 """
147 return self._cmd('importAdminCredentials', params=dict(username=username, password=password))
148
150 """
151 Retrieve a summary of licensed feature usage.
152
153 This command will return information about what Cloudera Enterprise
154 licensed features are in use in the clusters being managed by this Cloudera
155 Manager, as well as totals for usage across all clusters.
156
157 The specific features described can vary between different versions of
158 Cloudera Manager.
159
160 Available since API v6.
161 """
162 return self._get('getLicensedFeatureUsage',
163 ret_type=ApiLicensedFeatureUsage,
164 ret_is_list=False,
165 api_version=6)
166
168 """
169 Runs the host inspector on the configured hosts.
170
171 @return: Information about the submitted command.
172 """
173 return self._cmd('inspectHosts')
174
176 """
177 This method is deprecated as of CM 4.5.
178 You should use collect_diagnostic_data_45.
179 Issue the command to collect diagnostic data.
180
181 @param start_datetime: The start of the collection period. Type datetime.
182 @param end_datetime: The end of the collection period. Type datetime.
183 @param includeInfoLog: Whether to include INFO level log messages.
184 """
185 args = {
186 'startTime': start_datetime.isoformat(),
187 'endTime': end_datetime.isoformat(),
188 'includeInfoLog': includeInfoLog,
189 }
190
191
192 return self._cmd('collectDiagnosticData', data=args, api_version=2)
193
194 - def collect_diagnostic_data_45(self, end_datetime, bundle_size_bytes, cluster_name=None,
195 roles=None, collect_metrics=False, start_datetime=None):
196 """
197 Issue the command to collect diagnostic data.
198 If start_datetime is specified, diagnostic data is collected for the entire period between
199 start_datetime and end_datetime provided that bundle size is less than or equal to
200 bundle_size_bytes. Diagnostics data collection fails if the bundle size is greater than
201 bundle_size_bytes.
202
203 If start_datetime is not specified, diagnostic data is collected starting from end_datetime
204 and collecting backwards upto a maximum of bundle_size_bytes.
205
206 @param end_datetime: The end of the collection period. Type datetime.
207 @param bundle_size_bytes: The target size for the support bundle in bytes
208 @param cluster_name: The cluster to collect or None for all clusters
209 @param roles: Role ids of roles to restrict log and metric collection to. Valid since v10.
210 @param collect_metrics: Whether to collect metrics for viewing as charts. Valid since v13.
211 @param start_datetime: The start of the collection period. Type datetime. Valid since v13.
212 """
213 args = {
214 'endTime': end_datetime.isoformat(),
215 'bundleSizeBytes': bundle_size_bytes,
216 'clusterName': cluster_name
217 }
218 if self._get_resource_root().version >= 10:
219 args['roles'] = roles
220 if self._get_resource_root().version >= 13:
221 args['enableMonitorMetricsCollection'] = collect_metrics
222 if start_datetime is not None:
223 args['startTime'] = start_datetime.isoformat()
224 return self._cmd('collectDiagnosticData', data=args)
225
227 """
228 Decommission the specified hosts by decommissioning the slave roles
229 and stopping the remaining ones.
230
231 @param host_names: List of names of hosts to be decommissioned.
232 @return: Information about the submitted command.
233 @since: API v2
234 """
235 return self._cmd('hostsDecommission', data=host_names)
236
238 """
239 Decommission the specified hosts by offlining or decommissioning the slave
240 roles and stopping the remaining ones. Offline has precedence if supported
241 by the service.
242
243 @param host_names: List of names of hosts to be decommissioned.
244 @param timeout: Offline timeout in seconds. Omit to get the default timeout (4 hours).
245 @return: Information about the submitted command.
246 @since: API v17
247 """
248 return self._cmd('hostsOfflineOrDecommission', data=host_names,
249 params=timeout and dict(timeout=timeout) or dict(),
250 api_version=17)
251
253 """
254 Recommission the specified hosts by recommissioning the slave roles.
255 This command doesn't start the roles. Use hosts_start_roles for that.
256
257 @param host_names: List of names of hosts to be recommissioned.
258 @return: Information about the submitted command.
259 @since: API v2
260 """
261 return self._cmd('hostsRecommission', data=host_names)
262
264 """
265 Recommission the specified hosts by recommissioning the slave roles.
266 This command will start the roles before recommissioning.
267
268 Warning: Evolving. This method may change in the future and does not
269 offer standard compatibility guarantees.
270 Do not use without guidance from Cloudera.
271
272 Currently, only HDFS DataNodes will be started by this command.
273
274 @param host_names: List of names of hosts to be recommissioned.
275 @return: Information about the submitted command.
276 @since: API v15
277 """
278 return self._cmd('hostsRecommissionWithStart', data=host_names, api_version=15)
279
281 """
282 Start all the roles on the specified hosts.
283
284 @param host_names: List of names of hosts on which to start all roles.
285 @return: Information about the submitted command.
286 @since: API v2
287 """
288 return self._cmd('hostsStartRoles', data=host_names)
289
290 - def create_peer(self, name, url, username, password, peer_type="REPLICATION"):
291 """
292 Create a new peer for replication.
293
294 @param name: The name of the peer.
295 @param url: The url of the peer.
296 @param username: The admin username to use to setup the remote side of the peer connection.
297 @param password: The password of the admin user.
298 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
299 @return: The newly created peer.
300 @since: API v3
301 """
302 if self._get_resource_root().version < 11:
303 peer_type = None
304 peer = ApiCmPeer(self._get_resource_root(),
305 name=name,
306 url=url,
307 username=username,
308 password=password,
309 type=peer_type)
310 return self._post("peers", ApiCmPeer, data=peer, api_version=3)
311
313 """
314 Checks if the resource_root's API version is >= 11 and construct type param.
315 """
316 params = None
317 if self._get_resource_root().version >= 11:
318 params = {
319 'type': peer_type,
320 }
321 return params
322
324 """
325 Delete a replication peer.
326
327 @param name: The name of the peer.
328 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
329 @return: The deleted peer.
330 @since: API v3
331 """
332 params = self._get_peer_type_param(peer_type)
333 return self._delete("peers/" + name, ApiCmPeer, params=params, api_version=3)
334
335 - def update_peer(self,
336 current_name,
337 new_name, new_url, username, password, peer_type="REPLICATION"):
338 """
339 Update a replication peer.
340
341 @param current_name: The name of the peer to updated.
342 @param new_name: The new name for the peer.
343 @param new_url: The new url for the peer.
344 @param username: The admin username to use to setup the remote side of the peer connection.
345 @param password: The password of the admin user.
346 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
347 @return: The updated peer.
348 @since: API v3
349 """
350 if self._get_resource_root().version < 11:
351 peer_type = None
352 peer = ApiCmPeer(self._get_resource_root(),
353 name=new_name,
354 url=new_url,
355 username=username,
356 password=password,
357 type=peer_type)
358 return self._put("peers/" + current_name, ApiCmPeer, data=peer, api_version=3)
359
361 """
362 Retrieve a list of replication peers.
363
364 @return: A list of replication peers.
365 @since: API v3
366 """
367 return self._get("peers", ApiCmPeer, True, api_version=3)
368
369 - def get_peer(self, name, peer_type="REPLICATION"):
370 """
371 Retrieve a replication peer by name.
372
373 @param name: The name of the peer.
374 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
375 @return: The peer.
376 @since: API v3
377 """
378 params = self._get_peer_type_param(peer_type)
379 return self._get("peers/" + name, ApiCmPeer, params=params, api_version=3)
380
382 """
383 Test connectivity for a replication peer.
384
385 @param name: The name of the peer to test.
386 @param peer_type: Added in v11. The type of the peer to test. Defaults to 'REPLICATION'.
387 @return: The command representing the test.
388 @since: API v3
389 """
390 params = self._get_peer_type_param(peer_type)
391 return self._post("peers/%s/commands/test" % name, ApiCommand, params=params,
392 api_version=3)
393
395 """
396 Retrieve the default configuration for all hosts.
397
398 @param view: View to materialize.
399 @param view: View to materialize ('full' or 'summary')
400 @return: Dictionary with configuration data.
401 """
402 return self._get_config("allHosts/config", view)
403
405 """
406 Update the default configuration for all hosts.
407
408 @param config: Dictionary with configuration to update.
409 @return: Dictionary with updated configuration.
410 """
411 return self._update_config("allHosts/config", config)
412
414 """
415 Automatically assign roles to hosts and create the roles for the Cloudera
416 Management Service.
417
418 Assignments are done based on number of hosts in the deployment and hardware
419 specifications. Existing roles will be taken into account and their
420 assignments will be not be modified. The deployment should not have any
421 clusters when calling this endpoint. If it does, an exception will be thrown
422 preventing any role assignments.
423 @since: API v6
424 """
425 self._put("service/autoAssignRoles", None, api_version=6)
426
441
442 - def host_install(self, user_name, host_names, ssh_port=None, password=None,
443 private_key=None, passphrase=None, parallel_install_count=None,
444 cm_repo_url=None, gpg_key_custom_url=None,
445 java_install_strategy=None, unlimited_jce=None):
446 """
447 Install Cloudera Manager Agent on a set of hosts.
448
449 @param user_name: The username used to authenticate with the hosts. Root access
450 to your hosts is required to install Cloudera packages. The
451 installer will connect to your hosts via SSH and log in either
452 directly as root or as another user with password-less sudo
453 privileges to become root.
454 @param host_names: List of names of hosts to configure for use with
455 Cloudera Manager. A host may be specified by a
456 hostname(FQDN) or an IP address.
457 @param ssh_port: SSH port. If unset, defaults to 22.
458 @param password: The password used to authenticate with the hosts. Specify
459 either this or a private key. For password-less login, use
460 an empty string as password.
461 @param private_key: The private key to authenticate with the hosts. Specify
462 either this or a password.
463 @param passphrase: The passphrase associated with the private key used to
464 authenticate with the hosts (optional).
465 @param parallel_install_count: Number of simultaneous installations.
466 Defaults to 10. Running a large number of
467 installations at once can consume large amounts
468 of network bandwidth and other system resources.
469 @param cm_repo_url: The Cloudera Manager repository URL to use (optional).
470 Example for SLES, Redhat or other RPM based distributions:
471 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/5/
472 Example for Ubuntu or other Debian based distributions:
473 "deb http://archive.cloudera.com/cm5/ubuntu/lucid/amd64/cm/ lucid-cm5 contrib"
474 @param gpg_key_custom_url: The Cloudera Manager public GPG key (optional).
475 Example for SLES, Redhat or other RPM based distributions:
476 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/RPM-GPG-KEY-cloudera
477 Example for Ubuntu or other Debian based distributions:
478 http://archive.cloudera.com/debian/archive.key
479 @param java_install_strategy: Added in v8: Strategy to use for JDK installation. Valid values are 1.
480 AUTO (default): Cloudera Manager will install the JDK versions that are
481 required when the "AUTO" option is selected. Cloudera Manager may
482 overwrite any of the existing JDK installations. 2. NONE: Cloudera
483 Manager will not install any JDK when "NONE" option is selected. It
484 should be used if an existing JDK installation has to be used.
485 @param unlimited_jce: Added in v8: Flag for unlimited strength JCE policy files installation If
486 unset, defaults to false
487 @return: Information about the submitted command.
488 @since: API v6
489 """
490 host_install_args = {}
491 if user_name:
492 host_install_args['userName'] = user_name
493 if host_names:
494 host_install_args['hostNames'] = host_names
495 if ssh_port:
496 host_install_args['sshPort'] = ssh_port
497 if password:
498 host_install_args['password'] = password
499 if private_key:
500 host_install_args['privateKey'] = private_key
501 if passphrase:
502 host_install_args['passphrase'] = passphrase
503 if parallel_install_count:
504 host_install_args['parallelInstallCount'] = parallel_install_count
505 if cm_repo_url:
506 host_install_args['cmRepoUrl'] = cm_repo_url
507 if gpg_key_custom_url:
508 host_install_args['gpgKeyCustomUrl'] = gpg_key_custom_url
509 if java_install_strategy is not None:
510 host_install_args['javaInstallStrategy'] = java_install_strategy
511 if unlimited_jce:
512 host_install_args['unlimitedJCE'] = unlimited_jce
513 return self._cmd('hostInstall', data=host_install_args)
514
516 """
517 Begin the trial license for this Cloudera Manager instance.
518
519 This allows the user to have enterprise-level features for a 60-day trial
520 period.
521
522 @since: API v6
523 """
524 self._post("trial/begin", None, api_version=6)
525
527 """
528 End the trial license for this Cloudera Manager instance.
529
530 @since: API v6
531 """
532 self._post("trial/end", None, api_version=6)
533
535 """
536 Create a cluster according to the provided template
537
538 @param api_cluster_template: cluster template to import
539 @param add_repositories: if true the parcels repositories in the cluster template will be added.
540 @return: Command handing cluster import
541 @since: API v12
542 """
543 return self._post("importClusterTemplate", ApiCommand, False, api_cluster_template, params=dict(addRepositories=add_repositories), api_version=12)
544
546 """
547 Delete credentials for services configured with Kerberos.
548
549 @return: Information about the submitted command.
550 @since: API v17
551 """
552 return self._cmd('deleteCredentials', api_version=17)
553