Vladyslav Drok | cb8d0fb | 2018-06-27 19:28:14 +0300 | [diff] [blame^] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | import six.moves.urllib.parse as urllib_parse |
| 14 | |
| 15 | import common |
| 16 | |
| 17 | # Function alias to not shadow built-ins |
| 18 | __func_alias__ = { |
| 19 | 'list_': 'list' |
| 20 | } |
| 21 | |
| 22 | |
| 23 | @common.function_descriptor('create', 'Keypair', 'keypair') |
| 24 | @common.send('post') |
| 25 | def create(name, public_key, **kwargs): |
| 26 | """Create a keypair""" |
| 27 | url = '/os-keypairs' |
| 28 | body = {'name': name, 'public_key': public_key} |
| 29 | body.update(kwargs) |
| 30 | return url, {'json': {'keypair': body}} |
| 31 | |
| 32 | |
| 33 | @common.function_descriptor('delete', 'Keypair') |
| 34 | @common.send('delete') |
| 35 | def delete(name, **kwargs): |
| 36 | """Delete keypair""" |
| 37 | url = '/os-keypairs/{}?{}'.format(name, urllib_parse.urlencode(kwargs)) |
| 38 | return url, {} |
| 39 | |
| 40 | |
| 41 | @common.function_descriptor('find', 'Keypair', 'keypair') |
| 42 | @common.send('get') |
| 43 | def get(name, **kwargs): |
| 44 | """Get a keypair of a project (and user)""" |
| 45 | url = '/os-keypairs/{}?{}'.format(name, urllib_parse.urlencode(kwargs)) |
| 46 | return url, {} |
| 47 | |
| 48 | |
| 49 | @common.function_descriptor('find', 'Keypair', 'keypairs') |
| 50 | @common.send('get') |
| 51 | def list_(**kwargs): |
| 52 | """List keypairs of a project (and user)""" |
| 53 | url = '/os-keypairs?{}'.format(urllib_parse.urlencode(kwargs)) |
| 54 | return url, {} |