blob: a1d558acdfe0a03c87e79f0e27e98a9f747dc63c [file] [log] [blame]
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +04001# 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
16import json
17
18from tempest.common import rest_client
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
20
21CONF = config.CONF
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040022
23
24class DataProcessingClient(rest_client.RestClient):
Matthew Treinish684d8992014-01-30 16:27:40 +000025 def __init__(self, username, password, auth_url, tenant_name=None):
26 super(DataProcessingClient, self).__init__(username, password,
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040027 auth_url, tenant_name)
Matthew Treinish684d8992014-01-30 16:27:40 +000028 self.service = CONF.data_processing.catalog_type
Sergey Lukjanov3bc60e92013-12-10 16:40:50 +040029
30 @classmethod
31 def _request_and_parse(cls, req_fun, uri, res_name, *args, **kwargs):
32 """Make a request using specified req_fun and parse response.
33
34 It returns pair: resp and parsed resource(s) body.
35 """
36
37 resp, body = req_fun(uri, headers={
38 'Content-Type': 'application/json'
39 }, *args, **kwargs)
40 body = json.loads(body)
41 return resp, body[res_name]
42
43 def list_node_group_templates(self):
44 """List all node group templates for a user."""
45
46 uri = 'node-group-templates'
47 return self._request_and_parse(self.get, uri, 'node_group_templates')
48
49 def get_node_group_template(self, tmpl_id):
50 """Returns the details of a single node group template."""
51
52 uri = "node-group-templates/%s" % tmpl_id
53 return self._request_and_parse(self.get, uri, 'node_group_template')
54
55 def create_node_group_template(self, name, plugin_name, hadoop_version,
56 node_processes, flavor_id,
57 node_configs=None, **kwargs):
58 """Creates node group template with specified params.
59
60 It supports passing additional params using kwargs and returns created
61 object.
62 """
63 uri = "node-group-templates"
64 body = kwargs.copy()
65 body.update({
66 'name': name,
67 'plugin_name': plugin_name,
68 'hadoop_version': hadoop_version,
69 'node_processes': node_processes,
70 'flavor_id': flavor_id,
71 'node_configs': node_configs or dict(),
72 })
73 return self._request_and_parse(self.post, uri, 'node_group_template',
74 body=json.dumps(body))
75
76 def delete_node_group_template(self, tmpl_id):
77 """Deletes the specified node group template by id."""
78
79 uri = "node-group-templates/%s" % tmpl_id
80 return self.delete(uri)