Sergey Lukjanov | 3bc60e9 | 2013-12-10 16:40:50 +0400 | [diff] [blame] | 1 | # Copyright (c) 2013 Mirantis Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | # implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | import json |
| 17 | |
| 18 | from tempest.common import rest_client |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 19 | from tempest import config |
| 20 | |
| 21 | CONF = config.CONF |
Sergey Lukjanov | 3bc60e9 | 2013-12-10 16:40:50 +0400 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class DataProcessingClient(rest_client.RestClient): |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 25 | def __init__(self, auth_provider): |
| 26 | super(DataProcessingClient, self).__init__(auth_provider) |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 27 | self.service = CONF.data_processing.catalog_type |
Sergey Lukjanov | 3bc60e9 | 2013-12-10 16:40:50 +0400 | [diff] [blame] | 28 | |
| 29 | @classmethod |
| 30 | def _request_and_parse(cls, req_fun, uri, res_name, *args, **kwargs): |
| 31 | """Make a request using specified req_fun and parse response. |
| 32 | |
| 33 | It returns pair: resp and parsed resource(s) body. |
| 34 | """ |
| 35 | |
| 36 | resp, body = req_fun(uri, headers={ |
| 37 | 'Content-Type': 'application/json' |
| 38 | }, *args, **kwargs) |
| 39 | body = json.loads(body) |
| 40 | return resp, body[res_name] |
| 41 | |
| 42 | def list_node_group_templates(self): |
| 43 | """List all node group templates for a user.""" |
| 44 | |
| 45 | uri = 'node-group-templates' |
| 46 | return self._request_and_parse(self.get, uri, 'node_group_templates') |
| 47 | |
| 48 | def get_node_group_template(self, tmpl_id): |
| 49 | """Returns the details of a single node group template.""" |
| 50 | |
| 51 | uri = "node-group-templates/%s" % tmpl_id |
| 52 | return self._request_and_parse(self.get, uri, 'node_group_template') |
| 53 | |
| 54 | def create_node_group_template(self, name, plugin_name, hadoop_version, |
| 55 | node_processes, flavor_id, |
| 56 | node_configs=None, **kwargs): |
| 57 | """Creates node group template with specified params. |
| 58 | |
| 59 | It supports passing additional params using kwargs and returns created |
| 60 | object. |
| 61 | """ |
| 62 | uri = "node-group-templates" |
| 63 | body = kwargs.copy() |
| 64 | body.update({ |
| 65 | 'name': name, |
| 66 | 'plugin_name': plugin_name, |
| 67 | 'hadoop_version': hadoop_version, |
| 68 | 'node_processes': node_processes, |
| 69 | 'flavor_id': flavor_id, |
| 70 | 'node_configs': node_configs or dict(), |
| 71 | }) |
| 72 | return self._request_and_parse(self.post, uri, 'node_group_template', |
| 73 | body=json.dumps(body)) |
| 74 | |
| 75 | def delete_node_group_template(self, tmpl_id): |
| 76 | """Deletes the specified node group template by id.""" |
| 77 | |
| 78 | uri = "node-group-templates/%s" % tmpl_id |
| 79 | return self.delete(uri) |
Sergey Lukjanov | dad26cc | 2014-02-06 19:58:31 +0400 | [diff] [blame] | 80 | |
| 81 | def list_plugins(self): |
| 82 | """List all enabled plugins.""" |
| 83 | |
| 84 | uri = 'plugins' |
| 85 | return self._request_and_parse(self.get, uri, 'plugins') |
| 86 | |
| 87 | def get_plugin(self, plugin_name, plugin_version=None): |
| 88 | """Returns the details of a single plugin.""" |
| 89 | |
| 90 | uri = "plugins/%s" % plugin_name |
| 91 | if plugin_version: |
| 92 | uri += '/%s' % plugin_version |
| 93 | return self._request_and_parse(self.get, uri, 'plugin') |