blob: 75ce9ff1235d6c4af2b54192fea2e6762aa85902 [file] [log] [blame]
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +09001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NEC Corporation.
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import json
19
20from tempest.common.rest_client import RestClient
21from tempest import exceptions
22
23
24class AggregatesClientJSON(RestClient):
25
26 def __init__(self, config, username, password, auth_url, tenant_name=None):
27 super(AggregatesClientJSON, self).__init__(config, username, password,
28 auth_url, tenant_name)
29 self.service = self.config.compute.catalog_type
30
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
43 def create_aggregate(self, name, availability_zone=None):
44 """Creates a new aggregate."""
45 post_body = {
46 'name': name,
47 'availability_zone': availability_zone,
48 }
49 post_body = json.dumps({'aggregate': post_body})
50 resp, body = self.post('os-aggregates', post_body, self.headers)
51
52 body = json.loads(body)
53 return resp, body['aggregate']
54
Zhu Zhu7b5f6292013-09-22 15:47:54 +080055 def update_aggregate(self, aggregate_id, name, availability_zone=None):
56 """Update a aggregate."""
57 put_body = {
58 'name': name,
59 'availability_zone': availability_zone
60 }
61 put_body = json.dumps({'aggregate': put_body})
62 resp, body = self.put('os-aggregates/%s' % str(aggregate_id),
63 put_body, self.headers)
64
65 body = json.loads(body)
66 return resp, body['aggregate']
67
Mitsuhiko Yamazaki74f07072013-04-02 11:52:31 +090068 def delete_aggregate(self, aggregate_id):
69 """Deletes the given aggregate."""
70 return self.delete("os-aggregates/%s" % str(aggregate_id))
71
72 def is_resource_deleted(self, id):
73 try:
74 self.get_aggregate(id)
75 except exceptions.NotFound:
76 return True
77 return False
78
79 def add_host(self, aggregate_id, host):
80 """Adds a host to the given aggregate."""
81 post_body = {
82 'host': host,
83 }
84 post_body = json.dumps({'add_host': post_body})
85 resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
86 post_body, self.headers)
87 body = json.loads(body)
88 return resp, body['aggregate']
89
90 def remove_host(self, aggregate_id, host):
91 """Removes a host from the given aggregate."""
92 post_body = {
93 'host': host,
94 }
95 post_body = json.dumps({'remove_host': post_body})
96 resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
97 post_body, self.headers)
98 body = json.loads(body)
99 return resp, body['aggregate']