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):
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 @return: The newly created peer. 251 @since: API v3 252 """ 253 peer = ApiCmPeer(self._get_resource_root(), 254 name=name, 255 url=url, 256 username=username, 257 password=password) 258 return self._post("peers", ApiCmPeer, data=peer, api_version=3)
259
260 - def delete_peer(self, name):
261 """ 262 Delete a replication peer. 263 264 @param name: The name of the peer. 265 @return: The deleted peer. 266 @since: API v3 267 """ 268 return self._delete("peers/" + name, ApiCmPeer, api_version=3)
269
270 - def update_peer(self, 271 current_name, 272 new_name, new_url, username, password):
273 """ 274 Update a replication peer. 275 276 @param current_name: The name of the peer to updated. 277 @param new_name: The new name for the peer. 278 @param new_url: The new url for the peer. 279 @param username: The admin username to use to setup the remote side of the peer connection. 280 @param password: The password of the admin user. 281 @return: The updated peer. 282 @since: API v3 283 """ 284 peer = ApiCmPeer(self._get_resource_root(), 285 name=new_name, 286 url=new_url, 287 username=username, 288 password=password) 289 return self._put("peers/" + current_name, data=peer, api_version=3)
290
291 - def get_peers(self):
292 """ 293 Retrieve a list of replication peers. 294 295 @return: A list of replication peers. 296 @since: API v3 297 """ 298 return self._get("peers", ApiCmPeer, True, api_version=3)
299
300 - def get_peer(self, name):
301 """ 302 Retrieve a replication peer by name. 303 304 @param name: The name of the peer. 305 @return: The peer. 306 @since: API v3 307 """ 308 return self._get("peers/" + name, ApiCmPeer, api_version=3)
309
310 - def test_peer_connectivity(self, name):
311 """ 312 Test connectivity for a replication peer. 313 314 @param name: The name of the peer to test. 315 @return: The command representing the test. 316 @since: API v3 317 """ 318 return self._post("peers/%s/commands/test" % (name, ), ApiCommand, 319 api_version=3)
320
321 - def get_all_hosts_config(self, view=None):
322 """ 323 Retrieve the default configuration for all hosts. 324 325 @param view: View to materialize. 326 @param view: View to materialize ('full' or 'summary') 327 @return: Dictionary with configuration data. 328 """ 329 return self._get_config("allHosts/config", view)
330
331 - def update_all_hosts_config(self, config):
332 """ 333 Update the default configuration for all hosts. 334 335 @param config: Dictionary with configuration to update. 336 @return: Dictionary with updated configuration. 337 """ 338 return self._update_config("allHosts/config", config)
339
340 - def auto_assign_roles(self):
341 """ 342 Automatically assign roles to hosts and create the roles for the Cloudera 343 Management Service. 344 345 Assignments are done based on number of hosts in the deployment and hardware 346 specifications. Existing roles will be taken into account and their 347 assignments will be not be modified. The deployment should not have any 348 clusters when calling this endpoint. If it does, an exception will be thrown 349 preventing any role assignments. 350 @since: API v6 351 """ 352 self._put("service/autoAssignRoles", None, api_version=6)
353
354 - def auto_configure(self):
355 """ 356 Automatically configures roles of the Cloudera Management Service. 357 358 Overwrites some existing configurations. Only default role config groups 359 must exist before calling this endpoint. Other role config groups must not 360 exist. If they do, an exception will be thrown preventing any 361 configuration. Ignores any clusters (and their services and roles) 362 colocated with the Cloudera Management Service. To avoid over-committing 363 the heap on hosts, place the Cloudera Management Service roles on machines 364 not used by any of the clusters. 365 @since: API v6 366 """ 367 self._put("service/autoConfigure", None, api_version=6)
368
369 - def host_install(self, user_name, host_names, ssh_port=None, password=None, 370 private_key=None, passphrase=None, parallel_install_count=None, 371 cm_repo_url=None, gpg_key_custom_url=None, 372 java_install_strategy=None, unlimited_jce=None):
373 """ 374 Install Cloudera Manager Agent on a set of hosts. 375 376 @param user_name: The username used to authenticate with the hosts. Root access 377 to your hosts is required to install Cloudera packages. The 378 installer will connect to your hosts via SSH and log in either 379 directly as root or as another user with password-less sudo 380 privileges to become root. 381 @param host_names: List of names of hosts to configure for use with 382 Cloudera Manager. A host may be specified by a 383 hostname(FQDN) or an IP address. 384 @param ssh_port: SSH port. If unset, defaults to 22. 385 @param password: The password used to authenticate with the hosts. Specify 386 either this or a private key. For password-less login, use 387 an empty string as password. 388 @param private_key: The private key to authenticate with the hosts. Specify 389 either this or a password. 390 @param passphrase: The passphrase associated with the private key used to 391 authenticate with the hosts (optional). 392 @param parallel_install_count: Number of simultaneous installations. 393 Defaults to 10. Running a large number of 394 installations at once can consume large amounts 395 of network bandwidth and other system resources. 396 @param cm_repo_url: The Cloudera Manager repository URL to use (optional). 397 Example for SLES, Redhat or other RPM based distributions: 398 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/5/ 399 Example for Ubuntu or other Debian based distributions: 400 "deb http://archive.cloudera.com/cm5/ubuntu/lucid/amd64/cm/ lucid-cm5 contrib" 401 @param gpg_key_custom_url: The Cloudera Manager public GPG key (optional). 402 Example for SLES, Redhat or other RPM based distributions: 403 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/RPM-GPG-KEY-cloudera 404 Example for Ubuntu or other Debian based distributions: 405 http://archive.cloudera.com/debian/archive.key 406 @param java_install_strategy: Added in v8: Strategy to use for JDK installation. Valid values are 1. 407 AUTO (default): Cloudera Manager will install the JDK versions that are 408 required when the "AUTO" option is selected. Cloudera Manager may 409 overwrite any of the existing JDK installations. 2. NONE: Cloudera 410 Manager will not install any JDK when "NONE" option is selected. It 411 should be used if an existing JDK installation has to be used. 412 @param unlimited_jce: Added in v8: Flag for unlimited strength JCE policy files installation If 413 unset, defaults to false 414 @return: Information about the submitted command. 415 @since: API v6 416 """ 417 host_install_args = {} 418 if user_name: 419 host_install_args['userName'] = user_name 420 if host_names: 421 host_install_args['hostNames'] = host_names 422 if ssh_port: 423 host_install_args['sshPort'] = ssh_port 424 if password: 425 host_install_args['password'] = password 426 if private_key: 427 host_install_args['privateKey'] = private_key 428 if passphrase: 429 host_install_args['passphrase'] = passphrase 430 if parallel_install_count: 431 host_install_args['parallelInstallCount'] = parallel_install_count 432 if cm_repo_url: 433 host_install_args['cmRepoUrl'] = cm_repo_url 434 if gpg_key_custom_url: 435 host_install_args['gpgKeyCustomUrl'] = gpg_key_custom_url 436 if java_install_strategy is not None: 437 host_install_args['javaInstallStrategy'] = java_install_strategy 438 if unlimited_jce: 439 host_install_args['unlimitedJCE'] = unlimited_jce 440 return self._cmd('hostInstall', data=host_install_args)
441
442 - def begin_trial(self):
443 """ 444 Begin the trial license for this Cloudera Manager instance. 445 446 This allows the user to have enterprise-level features for a 60-day trial 447 period. 448 449 @since: API v6 450 """ 451 self._post("trial/begin", None, api_version=6)
452
453 - def end_trial(self):
454 """ 455 End the trial license for this Cloudera Manager instance. 456 457 @since: API v6 458 """ 459 self._post("trial/end", None, api_version=6)
460