blob: 045f03c3b6be12c81c13e9cd99a2790245d4f47c [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
dwallecke62b9f02012-10-10 23:34:42 -05002# 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 Treinish21905512015-07-13 10:33:35 -040016from oslo_serialization import jsonutils as json
kavan-patil2eb350f2012-01-19 11:17:26 +000017
ghanshyama1f87132015-11-13 14:49:27 +090018from tempest.api_schema.response.compute.v2_1 import keypairs as schemav21
19from tempest.api_schema.response.compute.v2_2 import keypairs as schemav22
Ken'ichi Ohmichi3ee057e2016-03-01 15:58:33 -080020from tempest.lib.common import rest_client
Ghanshyambbdb33b2016-01-08 11:51:07 +090021from tempest.services.compute.json import base_compute_client
Matthew Treinisha83a16e2012-12-07 13:44:02 -050022
kavan-patil2eb350f2012-01-19 11:17:26 +000023
Ghanshyambbdb33b2016-01-08 11:51:07 +090024class KeyPairsClient(base_compute_client.BaseComputeClient):
ghanshyama1f87132015-11-13 14:49:27 +090025
26 schema_versions_info = [{'min': None, 'max': '2.1', 'schema': schemav21},
27 {'min': '2.2', 'max': None, 'schema': schemav22}]
kavan-patil2eb350f2012-01-19 11:17:26 +000028
29 def list_keypairs(self):
chris fattarsi5098fa22012-04-17 13:27:00 -070030 resp, body = self.get("os-keypairs")
kavan-patil2eb350f2012-01-19 11:17:26 +000031 body = json.loads(body)
ghanshyama1f87132015-11-13 14:49:27 +090032 schema = self.get_schema(self.schema_versions_info)
ghanshyamdf7a3002015-03-20 12:09:07 +090033 self.validate_response(schema.list_keypairs, resp, body)
Ken'ichi Ohmichi3ee057e2016-03-01 15:58:33 -080034 return rest_client.ResponseBody(resp, body)
kavan-patil2eb350f2012-01-19 11:17:26 +000035
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000036 def show_keypair(self, keypair_name):
37 resp, body = self.get("os-keypairs/%s" % keypair_name)
kavan-patil2eb350f2012-01-19 11:17:26 +000038 body = json.loads(body)
ghanshyama1f87132015-11-13 14:49:27 +090039 schema = self.get_schema(self.schema_versions_info)
Ghanshyam2af64af2014-03-24 11:45:42 +090040 self.validate_response(schema.get_keypair, resp, body)
Ken'ichi Ohmichi3ee057e2016-03-01 15:58:33 -080041 return rest_client.ResponseBody(resp, body)
kavan-patil2eb350f2012-01-19 11:17:26 +000042
Ken'ichi Ohmichie364bce2015-07-17 10:27:59 +000043 def create_keypair(self, **kwargs):
44 post_body = json.dumps({'keypair': kwargs})
vponomaryovf4c27f92014-02-18 10:56:42 +020045 resp, body = self.post("os-keypairs", body=post_body)
kavan-patil2eb350f2012-01-19 11:17:26 +000046 body = json.loads(body)
ghanshyama1f87132015-11-13 14:49:27 +090047 schema = self.get_schema(self.schema_versions_info)
Ghanshyam44f74a42014-03-24 19:22:40 +090048 self.validate_response(schema.create_keypair, resp, body)
Ken'ichi Ohmichi3ee057e2016-03-01 15:58:33 -080049 return rest_client.ResponseBody(resp, body)
kavan-patil2eb350f2012-01-19 11:17:26 +000050
Ken'ichi Ohmichi9509b962015-07-07 05:30:15 +000051 def delete_keypair(self, keypair_name):
52 resp, body = self.delete("os-keypairs/%s" % keypair_name)
ghanshyama1f87132015-11-13 14:49:27 +090053 schema = self.get_schema(self.schema_versions_info)
Ghanshyam44f74a42014-03-24 19:22:40 +090054 self.validate_response(schema.delete_keypair, resp, body)
Ken'ichi Ohmichi3ee057e2016-03-01 15:58:33 -080055 return rest_client.ResponseBody(resp, body)