blob: 500aa0e41793017a671e9cdb8dc2bd9f83a75e40 [file] [log] [blame]
ivan-zhu595858e2013-11-20 15:40:33 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack Foundation
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
21
22
ivan-zhu7e7e6a32013-11-20 16:07:29 +080023class KeyPairsV3ClientJSON(RestClient):
ivan-zhu595858e2013-11-20 15:40:33 +080024
25 def __init__(self, config, username, password, auth_url, tenant_name=None):
ivan-zhu7e7e6a32013-11-20 16:07:29 +080026 super(KeyPairsV3ClientJSON, self).__init__(config, username, password,
27 auth_url, tenant_name)
28 self.service = self.config.compute.catalog_v3_type
ivan-zhu595858e2013-11-20 15:40:33 +080029
30 def list_keypairs(self):
ivan-zhu7e7e6a32013-11-20 16:07:29 +080031 resp, body = self.get("keypairs")
ivan-zhu595858e2013-11-20 15:40:33 +080032 body = json.loads(body)
33 # Each returned keypair is embedded within an unnecessary 'keypair'
34 # element which is a deviation from other resources like floating-ips,
35 # servers, etc. A bug?
36 # For now we shall adhere to the spec, but the spec for keypairs
37 # is yet to be found
38 return resp, body['keypairs']
39
40 def get_keypair(self, key_name):
ivan-zhu7e7e6a32013-11-20 16:07:29 +080041 resp, body = self.get("keypairs/%s" % str(key_name))
ivan-zhu595858e2013-11-20 15:40:33 +080042 body = json.loads(body)
43 return resp, body['keypair']
44
45 def create_keypair(self, name, pub_key=None):
46 post_body = {'keypair': {'name': name}}
47 if pub_key:
48 post_body['keypair']['public_key'] = pub_key
49 post_body = json.dumps(post_body)
ivan-zhu7e7e6a32013-11-20 16:07:29 +080050 resp, body = self.post("keypairs",
ivan-zhu595858e2013-11-20 15:40:33 +080051 headers=self.headers, body=post_body)
52 body = json.loads(body)
53 return resp, body['keypair']
54
55 def delete_keypair(self, key_name):
ivan-zhu7e7e6a32013-11-20 16:07:29 +080056 return self.delete("keypairs/%s" % str(key_name))