Package cm_api :: Package endpoints :: Module cms
[hide private]
[frames] | no frames]

Source Code for Module cm_api.endpoints.cms

  1  # Licensed to Cloudera, Inc. under one 
  2  # or more contributor license agreements.  See the NOTICE file 
  3  # distributed with this work for additional information 
  4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
  5  # to you under the Apache License, Version 2.0 (the 
  6  # "License"); you may not use this file except in compliance 
  7  # with the License.  You may obtain a copy of the License at 
  8  # 
  9  #     http://www.apache.org/licenses/LICENSE-2.0 
 10  # 
 11  # Unless required by applicable law or agreed to in writing, software 
 12  # distributed under the License is distributed on an "AS IS" BASIS, 
 13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 14  # See the License for the specific language governing permissions and 
 15  # limitations under the License. 
 16   
 17  from cm_api.endpoints.types import * 
 18  from cm_api.endpoints.services import ApiService 
 19   
20 -class ApiLicense(BaseApiObject):
21 """Model for a CM license.""" 22 _ATTRIBUTES = { 23 'owner' : ROAttr(), 24 'uuid' : ROAttr(), 25 'expiration' : ROAttr(), 26 } 27
28 - def __init__(self, resource_root):
29 BaseApiObject.init(self, resource_root)
30
31 -class ClouderaManager(BaseApiResource):
32 """ 33 The Cloudera Manager instance. 34 35 Provides access to CM configuration and services. 36 """ 37
38 - def __init__(self, resource_root):
39 BaseApiObject.init(self, resource_root)
40
41 - def _path(self):
42 return '/cm'
43
44 - def get_commands(self, view=None):
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
54 - def create_mgmt_service(self, service_setup_info):
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
63 - def delete_mgmt_service(self):
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
71 - def get_service(self):
72 """ 73 Return the Cloudera Management Services instance. 74 75 @return: An ApiService instance. 76 """ 77 return self._get("service", ApiService)
78
79 - def get_license(self):
80 """ 81 Return information about the currently installed license. 82 83 @return: License information. 84 """ 85 return self._get("license", ApiLicense)
86
87 - def update_license(self, license_text):
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
105 - def get_config(self, view = None):
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
117 - def update_config(self, config):
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
126 - def generate_credentials(self):
127 """ 128 Generate credentials for services configured with Kerberos. 129 130 @return: Information about the submitted command. 131 """ 132 return self._cmd('generateCredentials')
133
134 - def import_admin_credentials(self, username, password):
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
167 - def inspect_hosts(self):
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
175 - def collect_diagnostic_data(self, start_datetime, end_datetime, includeInfoLog=False):
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 # This method is deprecated as of CM API version 3 which was introduced 191 # in CM 4.5. 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
226 - def hosts_decommission(self, host_names):
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
237 - def hosts_recommission(self, host_names):
238 """ 239 Recommission the specified hosts by recommissioning the slave roles. 240 This command doesn't start the roles. Use hosts_start_roles for that. 241 242 @param host_names: List of names of hosts to be recommissioned. 243 @return: Information about the submitted command. 244 @since: API v2 245 """ 246 return self._cmd('hostsRecommission', data=host_names)
247
248 - def hosts_start_roles(self, host_names):
249 """ 250 Start all the roles on the specified hosts. 251 252 @param host_names: List of names of hosts on which to start all roles. 253 @return: Information about the submitted command. 254 @since: API v2 255 """ 256 return self._cmd('hostsStartRoles', data=host_names)
257
258 - def create_peer(self, name, url, username, password, peer_type="REPLICATION"):
259 """ 260 Create a new peer for replication. 261 262 @param name: The name of the peer. 263 @param url: The url of the peer. 264 @param username: The admin username to use to setup the remote side of the peer connection. 265 @param password: The password of the admin user. 266 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'. 267 @return: The newly created peer. 268 @since: API v3 269 """ 270 if self._get_resource_root().version < 11: 271 peer_type = None 272 peer = ApiCmPeer(self._get_resource_root(), 273 name=name, 274 url=url, 275 username=username, 276 password=password, 277 type=peer_type) 278 return self._post("peers", ApiCmPeer, data=peer, api_version=3)
279
280 - def _get_peer_type_param(self, peer_type):
281 """ 282 Checks if the resource_root's API version is >= 11 and construct type param. 283 """ 284 params = None 285 if self._get_resource_root().version >= 11: 286 params = { 287 'type': peer_type, 288 } 289 return params
290
291 - def delete_peer(self, name, peer_type="REPLICATION"):
292 """ 293 Delete a replication peer. 294 295 @param name: The name of the peer. 296 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'. 297 @return: The deleted peer. 298 @since: API v3 299 """ 300 params = self._get_peer_type_param(peer_type) 301 return self._delete("peers/" + name, ApiCmPeer, params=params, api_version=3)
302
303 - def update_peer(self, 304 current_name, 305 new_name, new_url, username, password, peer_type="REPLICATION"):
306 """ 307 Update a replication peer. 308 309 @param current_name: The name of the peer to updated. 310 @param new_name: The new name for the peer. 311 @param new_url: The new url for the peer. 312 @param username: The admin username to use to setup the remote side of the peer connection. 313 @param password: The password of the admin user. 314 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'. 315 @return: The updated peer. 316 @since: API v3 317 """ 318 if self._get_resource_root().version < 11: 319 peer_type = None 320 peer = ApiCmPeer(self._get_resource_root(), 321 name=new_name, 322 url=new_url, 323 username=username, 324 password=password, 325 type=peer_type) 326 return self._put("peers/" + current_name, ApiCmPeer, data=peer, api_version=3)
327
328 - def get_peers(self):
329 """ 330 Retrieve a list of replication peers. 331 332 @return: A list of replication peers. 333 @since: API v3 334 """ 335 return self._get("peers", ApiCmPeer, True, api_version=3)
336
337 - def get_peer(self, name, peer_type="REPLICATION"):
338 """ 339 Retrieve a replication peer by name. 340 341 @param name: The name of the peer. 342 @param peer_type: Added in v11. The type of the peer. Defaults to 'REPLICATION'. 343 @return: The peer. 344 @since: API v3 345 """ 346 params = self._get_peer_type_param(peer_type) 347 return self._get("peers/" + name, ApiCmPeer, params=params, api_version=3)
348
349 - def test_peer_connectivity(self, name, peer_type="REPLICATION"):
350 """ 351 Test connectivity for a replication peer. 352 353 @param name: The name of the peer to test. 354 @param peer_type: Added in v11. The type of the peer to test. Defaults to 'REPLICATION'. 355 @return: The command representing the test. 356 @since: API v3 357 """ 358 params = self._get_peer_type_param(peer_type) 359 return self._post("peers/%s/commands/test" % name, ApiCommand, params=params, 360 api_version=3)
361
362 - def get_all_hosts_config(self, view=None):
363 """ 364 Retrieve the default configuration for all hosts. 365 366 @param view: View to materialize. 367 @param view: View to materialize ('full' or 'summary') 368 @return: Dictionary with configuration data. 369 """ 370 return self._get_config("allHosts/config", view)
371
372 - def update_all_hosts_config(self, config):
373 """ 374 Update the default configuration for all hosts. 375 376 @param config: Dictionary with configuration to update. 377 @return: Dictionary with updated configuration. 378 """ 379 return self._update_config("allHosts/config", config)
380
381 - def auto_assign_roles(self):
382 """ 383 Automatically assign roles to hosts and create the roles for the Cloudera 384 Management Service. 385 386 Assignments are done based on number of hosts in the deployment and hardware 387 specifications. Existing roles will be taken into account and their 388 assignments will be not be modified. The deployment should not have any 389 clusters when calling this endpoint. If it does, an exception will be thrown 390 preventing any role assignments. 391 @since: API v6 392 """ 393 self._put("service/autoAssignRoles", None, api_version=6)
394
395 - def auto_configure(self):
396 """ 397 Automatically configures roles of the Cloudera Management Service. 398 399 Overwrites some existing configurations. Only default role config groups 400 must exist before calling this endpoint. Other role config groups must not 401 exist. If they do, an exception will be thrown preventing any 402 configuration. Ignores any clusters (and their services and roles) 403 colocated with the Cloudera Management Service. To avoid over-committing 404 the heap on hosts, place the Cloudera Management Service roles on machines 405 not used by any of the clusters. 406 @since: API v6 407 """ 408 self._put("service/autoConfigure", None, api_version=6)
409
410 - def host_install(self, user_name, host_names, ssh_port=None, password=None, 411 private_key=None, passphrase=None, parallel_install_count=None, 412 cm_repo_url=None, gpg_key_custom_url=None, 413 java_install_strategy=None, unlimited_jce=None):
414 """ 415 Install Cloudera Manager Agent on a set of hosts. 416 417 @param user_name: The username used to authenticate with the hosts. Root access 418 to your hosts is required to install Cloudera packages. The 419 installer will connect to your hosts via SSH and log in either 420 directly as root or as another user with password-less sudo 421 privileges to become root. 422 @param host_names: List of names of hosts to configure for use with 423 Cloudera Manager. A host may be specified by a 424 hostname(FQDN) or an IP address. 425 @param ssh_port: SSH port. If unset, defaults to 22. 426 @param password: The password used to authenticate with the hosts. Specify 427 either this or a private key. For password-less login, use 428 an empty string as password. 429 @param private_key: The private key to authenticate with the hosts. Specify 430 either this or a password. 431 @param passphrase: The passphrase associated with the private key used to 432 authenticate with the hosts (optional). 433 @param parallel_install_count: Number of simultaneous installations. 434 Defaults to 10. Running a large number of 435 installations at once can consume large amounts 436 of network bandwidth and other system resources. 437 @param cm_repo_url: The Cloudera Manager repository URL to use (optional). 438 Example for SLES, Redhat or other RPM based distributions: 439 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/5/ 440 Example for Ubuntu or other Debian based distributions: 441 "deb http://archive.cloudera.com/cm5/ubuntu/lucid/amd64/cm/ lucid-cm5 contrib" 442 @param gpg_key_custom_url: The Cloudera Manager public GPG key (optional). 443 Example for SLES, Redhat or other RPM based distributions: 444 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/RPM-GPG-KEY-cloudera 445 Example for Ubuntu or other Debian based distributions: 446 http://archive.cloudera.com/debian/archive.key 447 @param java_install_strategy: Added in v8: Strategy to use for JDK installation. Valid values are 1. 448 AUTO (default): Cloudera Manager will install the JDK versions that are 449 required when the "AUTO" option is selected. Cloudera Manager may 450 overwrite any of the existing JDK installations. 2. NONE: Cloudera 451 Manager will not install any JDK when "NONE" option is selected. It 452 should be used if an existing JDK installation has to be used. 453 @param unlimited_jce: Added in v8: Flag for unlimited strength JCE policy files installation If 454 unset, defaults to false 455 @return: Information about the submitted command. 456 @since: API v6 457 """ 458 host_install_args = {} 459 if user_name: 460 host_install_args['userName'] = user_name 461 if host_names: 462 host_install_args['hostNames'] = host_names 463 if ssh_port: 464 host_install_args['sshPort'] = ssh_port 465 if password: 466 host_install_args['password'] = password 467 if private_key: 468 host_install_args['privateKey'] = private_key 469 if passphrase: 470 host_install_args['passphrase'] = passphrase 471 if parallel_install_count: 472 host_install_args['parallelInstallCount'] = parallel_install_count 473 if cm_repo_url: 474 host_install_args['cmRepoUrl'] = cm_repo_url 475 if gpg_key_custom_url: 476 host_install_args['gpgKeyCustomUrl'] = gpg_key_custom_url 477 if java_install_strategy is not None: 478 host_install_args['javaInstallStrategy'] = java_install_strategy 479 if unlimited_jce: 480 host_install_args['unlimitedJCE'] = unlimited_jce 481 return self._cmd('hostInstall', data=host_install_args)
482
483 - def begin_trial(self):
484 """ 485 Begin the trial license for this Cloudera Manager instance. 486 487 This allows the user to have enterprise-level features for a 60-day trial 488 period. 489 490 @since: API v6 491 """ 492 self._post("trial/begin", None, api_version=6)
493
494 - def end_trial(self):
495 """ 496 End the trial license for this Cloudera Manager instance. 497 498 @since: API v6 499 """ 500 self._post("trial/end", None, api_version=6)
501
502 - def import_cluster_template(self, api_cluster_template, add_repositories=False):
503 """ 504 Create a cluster according to the provided template 505 506 @param api_cluster_template: cluster template to import 507 @param add_repositories: if true the parcels repositories in the cluster template will be added. 508 @return: Command handing cluster import 509 @since: API v12 510 """ 511 return self._post("importClusterTemplate", ApiCommand, False, api_cluster_template, params=dict(addRepositories=add_repositories), api_version=12)
512