dwalleck | e62b9f0 | 2012-10-10 23:34:42 -0500 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 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 | |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 18 | from tempest.common.rest_client import RestClient |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 19 | import json |
| 20 | |
| 21 | |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 22 | class KeyPairsClientJSON(RestClient): |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 23 | |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 24 | def __init__(self, config, username, password, auth_url, tenant_name=None): |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 25 | super(KeyPairsClientJSON, self).__init__(config, username, password, |
| 26 | auth_url, tenant_name) |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 27 | self.service = self.config.compute.catalog_type |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 28 | |
| 29 | def list_keypairs(self): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 30 | resp, body = self.get("os-keypairs") |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 31 | body = json.loads(body) |
| 32 | #Each returned keypair is embedded within an unnecessary 'keypair' |
| 33 | #element which is a deviation from other resources like floating-ips, |
| 34 | #servers, etc. A bug? |
| 35 | #For now we shall adhere to the spec, but the spec for keypairs |
| 36 | #is yet to be found |
| 37 | return resp, body['keypairs'] |
| 38 | |
| 39 | def get_keypair(self, key_name): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 40 | resp, body = self.get("os-keypairs/%s" % str(key_name)) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 41 | body = json.loads(body) |
| 42 | return resp, body['keypair'] |
| 43 | |
| 44 | def create_keypair(self, name, pub_key=None): |
| 45 | post_body = {'keypair': {'name': name}} |
| 46 | if pub_key: |
| 47 | post_body['keypair']['public_key'] = pub_key |
| 48 | post_body = json.dumps(post_body) |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 49 | resp, body = self.post("os-keypairs", |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 50 | headers=self.headers, body=post_body) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 51 | body = json.loads(body) |
| 52 | return resp, body['keypair'] |
| 53 | |
| 54 | def delete_keypair(self, key_name): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 55 | return self.delete("os-keypairs/%s" % str(key_name)) |