ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
dwalleck | e62b9f0 | 2012-10-10 23:34:42 -0500 | [diff] [blame] | 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 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame^] | 16 | from oslo_serialization import jsonutils as json |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 17 | |
ghanshyam | aa93b4b | 2015-03-20 11:03:44 +0900 | [diff] [blame] | 18 | from tempest.api_schema.response.compute.v2_1 import keypairs as schema |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 19 | from tempest.common import service_client |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 21 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 22 | class KeyPairsClient(service_client.ServiceClient): |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 23 | |
| 24 | def list_keypairs(self): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 25 | resp, body = self.get("os-keypairs") |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 26 | body = json.loads(body) |
Attila Fazekas | a8b5fe7 | 2013-08-01 16:59:06 +0200 | [diff] [blame] | 27 | # Each returned keypair is embedded within an unnecessary 'keypair' |
| 28 | # element which is a deviation from other resources like floating-ips, |
| 29 | # servers, etc. A bug? |
| 30 | # For now we shall adhere to the spec, but the spec for keypairs |
| 31 | # is yet to be found |
ghanshyam | df7a300 | 2015-03-20 12:09:07 +0900 | [diff] [blame] | 32 | self.validate_response(schema.list_keypairs, resp, body) |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 33 | return service_client.ResponseBodyList(resp, body['keypairs']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 34 | |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 35 | def show_keypair(self, keypair_name): |
| 36 | resp, body = self.get("os-keypairs/%s" % keypair_name) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 37 | body = json.loads(body) |
Ghanshyam | 2af64af | 2014-03-24 11:45:42 +0900 | [diff] [blame] | 38 | self.validate_response(schema.get_keypair, resp, body) |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 39 | return service_client.ResponseBody(resp, body['keypair']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 40 | |
| 41 | def create_keypair(self, name, pub_key=None): |
| 42 | post_body = {'keypair': {'name': name}} |
| 43 | if pub_key: |
| 44 | post_body['keypair']['public_key'] = pub_key |
| 45 | post_body = json.dumps(post_body) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 46 | resp, body = self.post("os-keypairs", body=post_body) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 47 | body = json.loads(body) |
Ghanshyam | 44f74a4 | 2014-03-24 19:22:40 +0900 | [diff] [blame] | 48 | self.validate_response(schema.create_keypair, resp, body) |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 49 | return service_client.ResponseBody(resp, body['keypair']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 50 | |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 51 | def delete_keypair(self, keypair_name): |
| 52 | resp, body = self.delete("os-keypairs/%s" % keypair_name) |
Ghanshyam | 44f74a4 | 2014-03-24 19:22:40 +0900 | [diff] [blame] | 53 | self.validate_response(schema.delete_keypair, resp, body) |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 54 | return service_client.ResponseBody(resp, body) |