blob: e26f57014686eb0bebcbdf155232b91ecfca9a12 [file] [log] [blame]
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +09001# Copyright 2013 NEC Corporation.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import json
17
18from tempest.common.rest_client import RestClient
Matthew Treinish684d8992014-01-30 16:27:40 +000019from tempest import config
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090020from tempest import exceptions
21
Matthew Treinish684d8992014-01-30 16:27:40 +000022CONF = config.CONF
23
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090024
25class AggregatesClientJSON(RestClient):
26
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000027 def __init__(self, auth_provider):
28 super(AggregatesClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000029 self.service = CONF.compute.catalog_type
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090030
31 def list_aggregates(self):
32 """Get aggregate list."""
33 resp, body = self.get("os-aggregates")
34 body = json.loads(body)
35 return resp, body['aggregates']
36
37 def get_aggregate(self, aggregate_id):
38 """Get details of the given aggregate."""
39 resp, body = self.get("os-aggregates/%s" % str(aggregate_id))
40 body = json.loads(body)
41 return resp, body['aggregate']
42
Yuiko Takadaf93d2482014-01-30 16:25:08 +000043 def create_aggregate(self, **kwargs):
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090044 """Creates a new aggregate."""
Yuiko Takadaf93d2482014-01-30 16:25:08 +000045 post_body = json.dumps({'aggregate': kwargs})
vponomaryovf4c27f92014-02-18 10:56:42 +020046 resp, body = self.post('os-aggregates', post_body)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090047
48 body = json.loads(body)
49 return resp, body['aggregate']
50
Zhu Zhu7b5f6292013-09-22 15:47:54 +080051 def update_aggregate(self, aggregate_id, name, availability_zone=None):
52 """Update a aggregate."""
53 put_body = {
54 'name': name,
55 'availability_zone': availability_zone
56 }
57 put_body = json.dumps({'aggregate': put_body})
vponomaryovf4c27f92014-02-18 10:56:42 +020058 resp, body = self.put('os-aggregates/%s' % str(aggregate_id), put_body)
Zhu Zhu7b5f6292013-09-22 15:47:54 +080059
60 body = json.loads(body)
61 return resp, body['aggregate']
62
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090063 def delete_aggregate(self, aggregate_id):
64 """Deletes the given aggregate."""
65 return self.delete("os-aggregates/%s" % str(aggregate_id))
66
67 def is_resource_deleted(self, id):
68 try:
69 self.get_aggregate(id)
70 except exceptions.NotFound:
71 return True
72 return False
73
74 def add_host(self, aggregate_id, host):
75 """Adds a host to the given aggregate."""
76 post_body = {
77 'host': host,
78 }
79 post_body = json.dumps({'add_host': post_body})
80 resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
vponomaryovf4c27f92014-02-18 10:56:42 +020081 post_body)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090082 body = json.loads(body)
83 return resp, body['aggregate']
84
85 def remove_host(self, aggregate_id, host):
86 """Removes a host from the given aggregate."""
87 post_body = {
88 'host': host,
89 }
90 post_body = json.dumps({'remove_host': post_body})
91 resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
vponomaryovf4c27f92014-02-18 10:56:42 +020092 post_body)
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090093 body = json.loads(body)
94 return resp, body['aggregate']
ivan-zhu35e1f8e2013-10-18 15:51:16 +080095
96 def set_metadata(self, aggregate_id, meta):
97 """Replaces the aggregate's existing metadata with new metadata."""
98 post_body = {
99 'metadata': meta,
100 }
101 post_body = json.dumps({'set_metadata': post_body})
102 resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
vponomaryovf4c27f92014-02-18 10:56:42 +0200103 post_body)
ivan-zhu35e1f8e2013-10-18 15:51:16 +0800104 body = json.loads(body)
105 return resp, body['aggregate']