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 return self._cmd('collectDiagnosticData', data=args)
191
192 - def collect_diagnostic_data_45(self, end_datetime, bundle_size_bytes, cluster_name=None, roles=None):
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
210 - def hosts_decommission(self, host_names):
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
221 - def hosts_recommission(self, host_names):
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
232 - def hosts_start_roles(self, host_names):
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
264 - def _get_peer_type_param(self, peer_type):
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
275 - def delete_peer(self, name, peer_type="REPLICATION"):
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
312 - def get_peers(self):
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
333 - def test_peer_connectivity(self, name, peer_type="REPLICATION"):
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
346 - def get_all_hosts_config(self, view=None):
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
356 - def update_all_hosts_config(self, config):
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
365 - def auto_assign_roles(self):
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
379 - def auto_configure(self):
380 """ 381 Automatically configures roles of the Cloudera Management Service. 382 383 Overwrites some existing configurations. Only default role config groups 384 must exist before calling this endpoint. Other role config groups must not 385 exist. If they do, an exception will be thrown preventing any 386 configuration. Ignores any clusters (and their services and roles) 387 colocated with the Cloudera Management Service. To avoid over-committing 388 the heap on hosts, place the Cloudera Management Service roles on machines 389 not used by any of the clusters. 390 @since: API v6 391 """ 392 self._put("service/autoConfigure", None, api_version=6)
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
467 - def begin_trial(self):
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
478 - def end_trial(self):
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
486 - def import_cluster_template(self, api_cluster_template, add_repositories=False):
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