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      Runs the host inspector on the configured hosts. 
137   
138      @return: Information about the submitted command. 
139      """ 
140      return self._cmd('inspectHosts') 
 141   
143      """ 
144      This method is deprecated as of CM 4.5. 
145      You should use collect_diagnostic_data_45. 
146      Issue the command to collect diagnostic data. 
147   
148      @param start_datetime: The start of the collection period. Type datetime. 
149      @param end_datetime: The end of the collection period. Type datetime. 
150      @param includeInfoLog: Whether to include INFO level log messages. 
151      """ 
152      args = { 
153          'startTime': start_datetime.isoformat(), 
154          'endTime': end_datetime.isoformat(), 
155          'includeInfoLog': includeInfoLog, 
156      } 
157      return self._cmd('collectDiagnosticData', data=args) 
 158   
160      """ 
161      Issue the command to collect diagnostic data. 
162   
163      @param end_datetime: The end of the collection period. Type datetime. 
164      @param bundle_size_bytes: The target size for the support bundle in bytes 
165      @param cluster_name: The cluster to collect or None for all clusters 
166      """ 
167      args = { 
168          'endTime': end_datetime.isoformat(), 
169          'bundleSizeBytes': bundle_size_bytes, 
170          'clusterName': cluster_name 
171      } 
172      return self._cmd('collectDiagnosticData', data=args) 
 173   
175      """ 
176      Decommission the specified hosts by decommissioning the slave roles 
177      and stopping the remaining ones. 
178   
179      @param host_names: List of names of hosts to be decommissioned. 
180      @return: Information about the submitted command. 
181      @since: API v2 
182      """ 
183      return self._cmd('hostsDecommission', data=host_names) 
 184   
186      """ 
187      Recommission the specified hosts by recommissioning the slave roles. 
188      This command doesn't start the roles. Use hosts_start_roles for that. 
189   
190      @param host_names: List of names of hosts to be recommissioned. 
191      @return: Information about the submitted command. 
192      @since: API v2 
193      """ 
194      return self._cmd('hostsRecommission', data=host_names) 
 195   
197      """ 
198      Start all the roles on the specified hosts. 
199   
200      @param host_names: List of names of hosts on which to start all roles. 
201      @return: Information about the submitted command. 
202      @since: API v2 
203      """ 
204      return self._cmd('hostsStartRoles', data=host_names) 
 205   
207      """ 
208      Create a new peer for replication. 
209   
210      @param name: The name of the peer. 
211      @param url: The url of the peer. 
212      @param username: The admin username to use to setup the remote side of the peer connection. 
213      @param password: The password of the admin user. 
214      @return: The newly created peer. 
215      @since: API v3 
216      """ 
217      peer = ApiCmPeer(self._get_resource_root(), 
218          name=name, 
219          url=url, 
220          username=username, 
221          password=password) 
222      return self._post("peers", ApiCmPeer, data=peer, api_version=3) 
 223   
225      """ 
226      Delete a replication peer. 
227   
228      @param name: The name of the peer. 
229      @return: The deleted peer. 
230      @since: API v3 
231      """ 
232      return self._delete("peers/" + name, ApiCmPeer, api_version=3) 
 233   
234 -  def update_peer(self, 
235        current_name, 
236        new_name, new_url, username, password): 
 237      """ 
238      Update a replication peer. 
239   
240      @param current_name: The name of the peer to updated. 
241      @param new_name: The new name for the peer. 
242      @param new_url: The new url for the peer. 
243      @param username: The admin username to use to setup the remote side of the peer connection. 
244      @param password: The password of the admin user. 
245      @return: The updated peer. 
246      @since: API v3 
247      """ 
248      peer = ApiCmPeer(self._get_resource_root(), 
249          name=new_name, 
250          url=new_url, 
251          username=username, 
252          password=password) 
253      return self._put("peers/" + current_name, data=peer, api_version=3) 
 254   
256      """ 
257      Retrieve a list of replication peers. 
258   
259      @return: A list of replication peers. 
260      @since: API v3 
261      """ 
262      return self._get("peers", ApiCmPeer, True, api_version=3) 
 263   
265      """ 
266      Retrieve a replication peer by name. 
267   
268      @param name: The name of the peer. 
269      @return: The peer. 
270      @since: API v3 
271      """ 
272      return self._get("peers/" + name, ApiCmPeer, api_version=3) 
 273   
275      """ 
276      Test connectivity for a replication peer. 
277   
278      @param name: The name of the peer to test. 
279      @return: The command representing the test. 
280      @since: API v3 
281      """ 
282      return self._post("peers/%s/commands/test" % (name, ), ApiCommand, 
283          api_version=3) 
 284   
286      """ 
287      Retrieve the default configuration for all hosts. 
288   
289      @param view: View to materialize. 
290      @param view: View to materialize ('full' or 'summary') 
291      @return: Dictionary with configuration data. 
292      """ 
293      return self._get_config("allHosts/config", view) 
 294   
296      """ 
297      Update the default configuration for all hosts. 
298   
299      @param config: Dictionary with configuration to update. 
300      @return: Dictionary with updated configuration. 
301      """ 
302      return self._update_config("allHosts/config", config) 
 303   
305      """ 
306      Automatically assign roles to hosts and create the roles for the Cloudera 
307      Management Service. 
308   
309      Assignments are done based on number of hosts in the deployment and hardware 
310      specifications. Existing roles will be taken into account and their 
311      assignments will be not be modified. The deployment should not have any 
312      clusters when calling this endpoint. If it does, an exception will be thrown 
313      preventing any role assignments. 
314      @since: API v6 
315      """ 
316      self._put("service/autoAssignRoles", None, api_version=6) 
 317   
332   
333 -  def host_install(self, user_name, host_names, ssh_port=None, password=None, 
334            private_key=None, passphrase=None, parallel_install_count=None, 
335            cm_repo_url=None, gpg_key_custom_url=None): 
 336      """ 
337      Install Cloudera Manager Agent on a set of hosts. 
338   
339      @param user_name: The username used to authenticate with the hosts. Root access 
340                        to your hosts is required to install Cloudera packages. The 
341                        installer will connect to your hosts via SSH and log in either 
342                        directly as root or as another user with password-less sudo 
343                        privileges to become root. 
344      @param host_names: List of names of hosts to configure for use with 
345                         Cloudera Manager. A host may be specified by a 
346                         hostname(FQDN) or an IP address. 
347      @param ssh_port: SSH port. If unset, defaults to 22. 
348      @param password: The password used to authenticate with the hosts. Specify 
349                       either this or a private key. For password-less login, use 
350                       an empty string as password. 
351      @param private_key: The private key to authenticate with the hosts. Specify 
352                          either this or a password. 
353      @param passphrase: The passphrase associated with the private key used to 
354                         authenticate with the hosts (optional). 
355      @param parallel_install_count: Number of simultaneous installations. 
356                                     Defaults to 10. Running a large number of 
357                                     installations at once can consume large amounts 
358                                     of network bandwidth and other system resources. 
359      @param cm_repo_url: The Cloudera Manager repository URL to use (optional). 
360                          Example for SLES, Redhat or other RPM based distributions: 
361                          http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/5/ 
362                          Example for Ubuntu or other Debian based distributions: 
363                          "deb http://archive.cloudera.com/cm5/ubuntu/lucid/amd64/cm/ lucid-cm5 contrib" 
364      @param gpg_key_custom_url: The Cloudera Manager public GPG key (optional). 
365                                 Example for SLES, Redhat or other RPM based distributions: 
366                                 http://archive-primary.cloudera.com/cm5/redhat/6/x86_64/cm/RPM-GPG-KEY-cloudera 
367                                 Example for Ubuntu or other Debian based distributions: 
368                                 http://archive.cloudera.com/debian/archive.key 
369      @return: Information about the submitted command. 
370      @since: API v6 
371      """ 
372      host_install_args = {} 
373      if user_name: 
374       host_install_args['userName'] = user_name 
375      if host_names: 
376        host_install_args['hostNames'] = host_names 
377      if ssh_port: 
378       host_install_args['sshPort'] = ssh_port 
379      if password: 
380       host_install_args['password'] = password 
381      if private_key: 
382       host_install_args['privateKey'] = private_key 
383      if passphrase: 
384       host_install_args['passphrase'] = passphrase 
385      if parallel_install_count: 
386       host_install_args['parallelInstallCount'] = parallel_install_count 
387      if cm_repo_url: 
388       host_install_args['cmRepoUrl'] = cm_repo_url 
389      if gpg_key_custom_url: 
390       host_install_args['gpgKeyCustomUrl'] = gpg_key_custom_url 
391      return self._cmd('hostInstall', data=host_install_args) 
  392