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 | a1f8713 | 2015-11-13 14:49:27 +0900 | [diff] [blame] | 18 | from tempest.api_schema.response.compute.v2_1 import keypairs as schemav21 |
| 19 | from tempest.api_schema.response.compute.v2_2 import keypairs as schemav22 |
Ken'ichi Ohmichi | 3ee057e | 2016-03-01 15:58:33 -0800 | [diff] [blame] | 20 | from tempest.lib.common import rest_client |
Ghanshyam | bbdb33b | 2016-01-08 11:51:07 +0900 | [diff] [blame] | 21 | from tempest.services.compute.json import base_compute_client |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 22 | |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 23 | |
Ghanshyam | bbdb33b | 2016-01-08 11:51:07 +0900 | [diff] [blame] | 24 | class KeyPairsClient(base_compute_client.BaseComputeClient): |
ghanshyam | a1f8713 | 2015-11-13 14:49:27 +0900 | [diff] [blame] | 25 | |
| 26 | schema_versions_info = [{'min': None, 'max': '2.1', 'schema': schemav21}, |
| 27 | {'min': '2.2', 'max': None, 'schema': schemav22}] |
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) |
ghanshyam | a1f8713 | 2015-11-13 14:49:27 +0900 | [diff] [blame] | 32 | schema = self.get_schema(self.schema_versions_info) |
ghanshyam | df7a300 | 2015-03-20 12:09:07 +0900 | [diff] [blame] | 33 | self.validate_response(schema.list_keypairs, resp, body) |
Ken'ichi Ohmichi | 3ee057e | 2016-03-01 15:58:33 -0800 | [diff] [blame] | 34 | return rest_client.ResponseBody(resp, body) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 35 | |
Ken'ichi Ohmichi | 9509b96 | 2015-07-07 05:30:15 +0000 | [diff] [blame] | 36 | def show_keypair(self, keypair_name): |
| 37 | resp, body = self.get("os-keypairs/%s" % keypair_name) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 38 | body = json.loads(body) |
ghanshyam | a1f8713 | 2015-11-13 14:49:27 +0900 | [diff] [blame] | 39 | schema = self.get_schema(self.schema_versions_info) |
Ghanshyam | 2af64af | 2014-03-24 11:45:42 +0900 | [diff] [blame] | 40 | self.validate_response(schema.get_keypair, resp, body) |
Ken'ichi Ohmichi | 3ee057e | 2016-03-01 15:58:33 -0800 | [diff] [blame] | 41 | return rest_client.ResponseBody(resp, body) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 42 | |
Ken'ichi Ohmichi | e364bce | 2015-07-17 10:27:59 +0000 | [diff] [blame] | 43 | def create_keypair(self, **kwargs): |
| 44 | post_body = json.dumps({'keypair': kwargs}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 45 | resp, body = self.post("os-keypairs", body=post_body) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 46 | body = json.loads(body) |
ghanshyam | a1f8713 | 2015-11-13 14:49:27 +0900 | [diff] [blame] | 47 | schema = self.get_schema(self.schema_versions_info) |
Ghanshyam | 44f74a4 | 2014-03-24 19:22:40 +0900 | [diff] [blame] | 48 | self.validate_response(schema.create_keypair, resp, body) |
Ken'ichi Ohmichi | 3ee057e | 2016-03-01 15:58:33 -0800 | [diff] [blame] | 49 | return rest_client.ResponseBody(resp, body) |
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 | a1f8713 | 2015-11-13 14:49:27 +0900 | [diff] [blame] | 53 | schema = self.get_schema(self.schema_versions_info) |
Ghanshyam | 44f74a4 | 2014-03-24 19:22:40 +0900 | [diff] [blame] | 54 | self.validate_response(schema.delete_keypair, resp, body) |
Ken'ichi Ohmichi | 3ee057e | 2016-03-01 15:58:33 -0800 | [diff] [blame] | 55 | return rest_client.ResponseBody(resp, body) |