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 return self._cmd('collectDiagnosticData', data=args)
191
193 """
194 Issue the command to collect diagnostic data.
195
196 @param end_datetime: The end of the collection period. Type datetime.
197 @param bundle_size_bytes: The target size for the support bundle in bytes
198 @param cluster_name: The cluster to collect or None for all clusters
199 @param roles: Role ids of roles to restrict log and metric collection to. Valid since v10.
200 """
201 args = {
202 'endTime': end_datetime.isoformat(),
203 'bundleSizeBytes': bundle_size_bytes,
204 'clusterName': cluster_name
205 }
206 if self._get_resource_root().version >= 10:
207 args['roles'] = roles
208 return self._cmd('collectDiagnosticData', data=args)
209
211 """
212 Decommission the specified hosts by decommissioning the slave roles
213 and stopping the remaining ones.
214
215 @param host_names: List of names of hosts to be decommissioned.
216 @return: Information about the submitted command.
217 @since: API v2
218 """
219 return self._cmd('hostsDecommission', data=host_names)
220
222 """
223 Recommission the specified hosts by recommissioning the slave roles.
224 This command doesn't start the roles. Use hosts_start_roles for that.
225
226 @param host_names: List of names of hosts to be recommissioned.
227 @return: Information about the submitted command.
228 @since: API v2
229 """
230 return self._cmd('hostsRecommission', data=host_names)
231
233 """
234 Start all the roles on the specified hosts.
235
236 @param host_names: List of names of hosts on which to start all roles.
237 @return: Information about the submitted command.
238 @since: API v2
239 """
240 return self._cmd('hostsStartRoles', data=host_names)
241
242 - def create_peer(self, name, url, username, password, peer_type="REPLICATION"):
243 """
244 Create a new peer for replication.
245
246 @param name: The name of the peer.
247 @param url: The url of the peer.
248 @param username: The admin username to use to setup the remote side of the peer connection.
249 @param password: The password of the admin user.
250 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
251 @return: The newly created peer.
252 @since: API v3
253 """
254 if self._get_resource_root().version < 11:
255 peer_type = None
256 peer = ApiCmPeer(self._get_resource_root(),
257 name=name,
258 url=url,
259 username=username,
260 password=password,
261 type=peer_type)
262 return self._post("peers", ApiCmPeer, data=peer, api_version=3)
263
265 """
266 Checks if the resource_root's API version is >= 11 and construct type param.
267 """
268 params = None
269 if self._get_resource_root().version >= 11:
270 params = {
271 'type': peer_type,
272 }
273 return params
274
276 """
277 Delete a replication peer.
278
279 @param name: The name of the peer.
280 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
281 @return: The deleted peer.
282 @since: API v3
283 """
284 params = self._get_peer_type_param(peer_type)
285 return self._delete("peers/" + name, ApiCmPeer, params=params, api_version=3)
286
287 - def update_peer(self,
288 current_name,
289 new_name, new_url, username, password, peer_type="REPLICATION"):
290 """
291 Update a replication peer.
292
293 @param current_name: The name of the peer to updated.
294 @param new_name: The new name for the peer.
295 @param new_url: The new url for 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 updated 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=new_name,
306 url=new_url,
307 username=username,
308 password=password,
309 type=peer_type)
310 return self._put("peers/" + current_name, ApiCmPeer, data=peer, api_version=3)
311
313 """
314 Retrieve a list of replication peers.
315
316 @return: A list of replication peers.
317 @since: API v3
318 """
319 return self._get("peers", ApiCmPeer, True, api_version=3)
320
321 - def get_peer(self, name, peer_type="REPLICATION"):
322 """
323 Retrieve a replication peer by name.
324
325 @param name: The name of the peer.
326 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'.
327 @return: The peer.
328 @since: API v3
329 """
330 params = self._get_peer_type_param(peer_type)
331 return self._get("peers/" + name, ApiCmPeer, params=params, api_version=3)
332
334 """
335 Test connectivity for a replication peer.
336
337 @param name: The name of the peer to test.
338 @param peer_type: Added in v11. The type of the peer to test. Defaults to 'REPLICATION'.
339 @return: The command representing the test.
340 @since: API v3
341 """
342 params = self._get_peer_type_param(peer_type)
343 return self._post("peers/%s/commands/test" % name, ApiCommand, params=params,
344 api_version=3)
345
347 """
348 Retrieve the default configuration for all hosts.
349
350 @param view: View to materialize.
351 @param view: View to materialize ('full' or 'summary')
352 @return: Dictionary with configuration data.
353 """
354 return self._get_config("allHosts/config", view)
355
357 """
358 Update the default configuration for all hosts.
359
360 @param config: Dictionary with configuration to update.
361 @return: Dictionary with updated configuration.
362 """
363 return self._update_config("allHosts/config", config)
364
366 """
367 Automatically assign roles to hosts and create the roles for the Cloudera
368 Management Service.
369
370 Assignments are done based on number of hosts in the deployment and hardware
371 specifications. Existing roles will be taken into account and their
372 assignments will be not be modified. The deployment should not have any
373 clusters when calling this endpoint. If it does, an exception will be thrown
374 preventing any role assignments.
375 @since: API v6
376 """
377 self._put("service/autoAssignRoles", None, api_version=6)
378
393
394 - def host_install(self, user_name, host_names, ssh_port=None, password=None,
395 private_key=None, passphrase=None, parallel_install_count=None,
396 cm_repo_url=None, gpg_key_custom_url=None,
397 java_install_strategy=None, unlimited_jce=None):
398 """
399 Install Cloudera Manager Agent on a set of hosts.
400
401 @param user_name: The username used to authenticate with the hosts. Root access
402 to your hosts is required to install Cloudera packages. The
403 installer will connect to your hosts via SSH and log in either
404 directly as root or as another user with password-less sudo
405 privileges to become root.
406 @param host_names: List of names of hosts to configure for use with
407 Cloudera Manager. A host may be specified by a
408 hostname(FQDN) or an IP address.
409 @param ssh_port: SSH port. If unset, defaults to 22.
410 @param password: The password used to authenticate with the hosts. Specify
411 either this or a private key. For password-less login, use
412 an empty string as password.
413 @param private_key: The private key to authenticate with the hosts. Specify
414 either this or a password.
415 @param passphrase: The passphrase associated with the private key used to
416 authenticate with the hosts (optional).
417 @param parallel_install_count: Number of simultaneous installations.
418 Defaults to 10. Running a large number of
419 installations at once can consume large amounts
420 of network bandwidth and other system resources.
421 @param cm_repo_url: The Cloudera Manager repository URL to use (optional).
422 Example for SLES, Redhat or other RPM based distributions:
423 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/5/
424 Example for Ubuntu or other Debian based distributions:
425 "deb http://archive.cloudera.com/cm5/ubuntu/lucid/amd64/cm/ lucid-cm5 contrib"
426 @param gpg_key_custom_url: The Cloudera Manager public GPG key (optional).
427 Example for SLES, Redhat or other RPM based distributions:
428 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/RPM-GPG-KEY-cloudera
429 Example for Ubuntu or other Debian based distributions:
430 http://archive.cloudera.com/debian/archive.key
431 @param java_install_strategy: Added in v8: Strategy to use for JDK installation. Valid values are 1.
432 AUTO (default): Cloudera Manager will install the JDK versions that are
433 required when the "AUTO" option is selected. Cloudera Manager may
434 overwrite any of the existing JDK installations. 2. NONE: Cloudera
435 Manager will not install any JDK when "NONE" option is selected. It
436 should be used if an existing JDK installation has to be used.
437 @param unlimited_jce: Added in v8: Flag for unlimited strength JCE policy files installation If
438 unset, defaults to false
439 @return: Information about the submitted command.
440 @since: API v6
441 """
442 host_install_args = {}
443 if user_name:
444 host_install_args['userName'] = user_name
445 if host_names:
446 host_install_args['hostNames'] = host_names
447 if ssh_port:
448 host_install_args['sshPort'] = ssh_port
449 if password:
450 host_install_args['password'] = password
451 if private_key:
452 host_install_args['privateKey'] = private_key
453 if passphrase:
454 host_install_args['passphrase'] = passphrase
455 if parallel_install_count:
456 host_install_args['parallelInstallCount'] = parallel_install_count
457 if cm_repo_url:
458 host_install_args['cmRepoUrl'] = cm_repo_url
459 if gpg_key_custom_url:
460 host_install_args['gpgKeyCustomUrl'] = gpg_key_custom_url
461 if java_install_strategy is not None:
462 host_install_args['javaInstallStrategy'] = java_install_strategy
463 if unlimited_jce:
464 host_install_args['unlimitedJCE'] = unlimited_jce
465 return self._cmd('hostInstall', data=host_install_args)
466
468 """
469 Begin the trial license for this Cloudera Manager instance.
470
471 This allows the user to have enterprise-level features for a 60-day trial
472 period.
473
474 @since: API v6
475 """
476 self._post("trial/begin", None, api_version=6)
477
479 """
480 End the trial license for this Cloudera Manager instance.
481
482 @since: API v6
483 """
484 self._post("trial/end", None, api_version=6)
485
487 """
488 Create a cluster according to the provided template
489
490 @param api_cluster_template: cluster template to import
491 @param add_repositories: if true the parcels repositories in the cluster template will be added.
492 @return: Command handing cluster import
493 @since: API v12
494 """
495 return self._post("importClusterTemplate", ApiCommand, False, api_cluster_template, params=dict(addRepositories=add_repositories), api_version=12)
496