openstack(keypair API)

keypair的操作只有四种,即创建,删除,查询,显示详情四种

  keypair create
  keypair delete
  keypair list
  keypair show
 

一配置环境变量

[root@master02 ~]# source /etc/kolla/admin-openrc.sh 

二创建生成keypair

[root@master02 ~]# openstack keypair create shiyanshi
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA8ps3el//3tXf50aUu/C3n9Iq0pWpESPygOC1qeCgSKFVLNtt
Pwd6i0qhgJTB/xygyJM0Xx+mNY1fTnVjRieTFE/nOEWJoMa0nDr0HBkzmPi3SYmj
6ECmXtC4GRBGSuH0B/hdnXBspkFNh9vA4aWzweEJFvMWmwLxWNY/vGk8NlvkNZhb
0NIp8v0GY674zuB2ZFEvq9/yA324a0/B/VwjltsLLqN6WahwEjeficXr+Pc3b/Do
xr1CZZ+xYaD2LsqaTo4cw+xonspVtlT73VfCe04+meSFvML1t7YxoqmzgipaSv77
vi2DnJqkzAmedT4rM11Vpmak/RZGyA2rgEJPPwIDAQABAoIBAGjapwawGSGRZH1L
5xq3dlWP+0wavQCYfcYv2LQ8Tmo1uF9z0uqr683qCpVNNe9xyxgFb1wxjJ+Wo3uA
ImRZiJcvJckEk0gqs24Ubm59mhWOUbXcL9zZ2JCirFYBpditDZS7GR7tLgGN4mZa
Ca5Rm0MfLunbpasL3NW+aK5RUN0xJsUMxFVNQEkZqtjusxJ16O7J1X8MgTPmrDVA
VlG+Q6kCgYEA+bdRKOjpXWzBHA7/McCUEEr9E35Tqy8byGg2PqWe9yDYWuarZRxe
4bpLklFgGw46gwy8ldBTZCv/V5yLOpKslHVjeM7g+5lDPfYvHf2TliLcM8dVlEhR
YLJSk+FYUuIv4BxDZ5171UFmylq2hp2HJO+F4ZEhvd+SgvJSkVPwepMCgYEA+LYZ
JQ0vVyAo05J+X9SputfuuuFvGpE5M4thKAvGkIzAmnZGuoAtaA03MpV6spWKr6sH
qTht7B8B6BWYWcVk/t0qC5hd44VFZ8U9yjRLsStxBUp4BvfL5kH6M+e2DK9TIYJm
t8OEO6JlGgBMz8y3RiORtssTm4b4fTjYXKokCCUCgYAHrIiD91RkmJj+ob9Z6g8i
yQsp9DHiCtqRuBIirrhJ4+qCMKCHxO1thmoYHwQTEMbfjB6ng/VsGKYKLTdiH2vK
TCk4ZzMmyDj2yH/+LfLBJGUb+j45Blfp3tEG1l/+fBD4lCXGI2LQ1OexxEPjsyea
DPpSSkF9MkewWn4LFUdInQKBgFOM2OWZiE28f/qTO+D1kA80ev5MvQYvwweNyxWo
3wuwPQOmuBvu81IBHonfrVhQ5EYfLnOqgULRJ9LPbl658TOtGHLMvL2yB57Uo+1J
pCPgdBdS7P9qPxUbFPJa5M1eGI8pP1h8Ve+ynkQd1a/5FZh6WnkNv4h/zvpCHm0C
uxgBAoGBAJ8Jf2T+ABu3juD1qEseGoV67NB+rlJgi7ejzAfqxYeELhMzohRXWQzz
7OrnOa5N1EWXtq8cW6hvew9N8O67daPuPYKBPkaVhHACgxY3XUCayBnVLhztR7i3
3LMbD84PNVMDea3y0Etw8uAmAkrdHfB9aC0vHi8FhJIGyc2RNMM9
-----END RSA PRIVATE KEY-----

三返回的字符串保存到shiyanshi.pem文件中

[root@master02 ~]# vi shiyanshi.pem  #把生成的key拷贝放入到shiyanshi.pem中

四修改shiyanshi.pem权限

[root@master02 ~]# chmod 0400 shiyanshi.pem  

五查询所有的keypair

[root@master02 ~]# openstack keypair list
+-----------+-------------------------------------------------+
| Name      | Fingerprint                                     |
+-----------+-------------------------------------------------+
| mykey     | cb:2f:ca:47:0a:16:2d:fb:dd:5c:55:df:5b:3c:e9:56 |
| shiyanshi | 4e:ed:89:d3:1f:ef:11:00:a5:72:f5:d7:15:3f:7b:5b |
+-----------+-------------------------------------------------+

六展示详情

[root@master02 ~]# openstack keypair show mykey
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | 2018-08-29T09:23:30.000000                      |
| deleted     | False                                           |
| deleted_at  | None                                            |
| fingerprint | cb:2f:ca:47:0a:16:2d:fb:dd:5c:55:df:5b:3c:e9:56 |
| id          | 1                                               |
| name        | mykey                                           |
| updated_at  | None                                            |
| user_id     | 00bdab9f777c4be7aa4fdf002d89b77e                |
+-------------+-------------------------------------------------+
[root@master02 ~]# 

七删除[root@master02 ~]# openstack keypair delete shiyanshi

八官方文档API

https://developer.openstack.org/api-ref/compute/

九实际API例子

9.1创建

REQ: curl -g -i -X POST http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}1a281f5bd32714e1a547b22e0fd68b322a8e0216" -d '{"keypair": {"name": "shiyanshi"}}'
Starting new HTTP connection (1): 10.1.2.204
http://10.1.2.204:8774 "POST /v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs HTTP/1.1" 200 2288
RESP: [200] Content-Length: 2288 Content-Type: application/json Openstack-Api-Version: compute 2.1 X-Openstack-Nova-Api-Version: 2.1 Vary: OpenStack-API-Version, X-OpenStack-Nova-API-Version X-Compute-Request-Id: req-c59e8b7e-1452-4154-ae2e-9e96e041590e Date: Thu, 01 Nov 2018 06:24:49 GMT 
RESP BODY: {"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZPYh9hMLP6QUaYrdn9AM7V4j6ssYgmsQGDM5EQNiycBX96vnFLdbo1nModlbQ6XKoIYoz06NAJRYUvMmEys56hqkpy+/0JAM1TcJBLr/wJuMohyu0Rt4QWw/DLfOpDsCMXorjdtIXAmtkkIg96l6w1DfAHqhKAzZgMTXcIcbZgHYfxfNFUoawdMmtVlZ09+YLjdRIa+QrerYV7p/MRRe4Gqu+SwunG3jMLAYi6DyAZcE3sqcDUvH9/y3R+8Vmr2tY/oZrnTMJ82e1FqM5AsiFBIJuOOl/9IFW2alwt+GC7fdv+WQRXmSgGQQ3uNEFM4gzd8+ayRsJgztQp96TGuiT Generated-by-Nova", "private_key": "-----BEGIN RS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NhVaAaDrL/ZIlA2HJA0hh7+vCFp7IQur6nAcUCgYEArqHw/GlEDs6FJV/vHneg\nzSLYc10AJgULK/P3FzbiHarpr77YHhjn89xBPtM/P+LCG+dBCDR0pH9RScHWma6F\nXONg6GbFKTJQrb52u70vMFaU1TzX6+8rk+8fgrJE0rp5yoirXvauKveWnxYxfzV1\noKQFVPVISyy2eXT8Z/c0Jh8CgYEAhWc4gE28AdLIbVIKE4sudBT6E56Ubz3TXz5W\n/LG6GdF67cqrb7604sgcK/mPWoo2Z9NZ5Xqp9cnk65QvGhijSluab9kti5416WkP\nLZtawZRpE+eEggR+mBf6kzS04QQzX+oLJf3U23R5oQjIrbrvQ/AIIRpzavo7TLHG\nkn46/RkCgYEA8GiWEe/s79p5JMlwymAWLo3EA7Vkzrs+Whq8t3+wL6d/ZfS/suaF\nzOFgKLYhM/2PdI2NRr/X1cPQ4DJLt6SuOnLBPrsnqbtODjCNpmJmNMZDMJSFYjTU\n2feV5Fhv6VbB14JtyzJgRQvwkx/tEffHvT+w1WHouBYZqxRgt230yLo=\n-----END RSA PRIVATE KEY-----\n", "user_id": "00bdab9f777c4be7aa4fdf002d89b77e", "name": "shiyanshi", "fingerprint": "00:a5:46:ee:66:00:62:eb:63:f7:8e:57:10:c9:4c:a0"}}

POST call to compute for http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs used request id req-c59e8b7e-1452-4154-ae2e-9e96e041590e
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA2T2IfYTCz+kFGmK3Z/QDO1eI+rLGIJrEBgzOREDYsnAV/er5
xS3W6NZzKHZW0OlyqCGKM9OjQCUWFLzJhMrOeoapKcvv9CQDNU3CQS6/8CbjKIcr
tEbeEFsPwy3zqQ7AjF6K43bSFwJrZJCIPepesNQ3wB6oSgM2YDE13CHG2YB2H8Xz
RVKGsHTJrVZWdPfmC43USGvkK3q2Fe6fzEUXuBqrvksLpxt4zCwGIug8gGXBN7Kn
A1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vGhijSluab9kti5416WkP
LZtawZRpE+eEggR+mBf6kzS04QQzX+oLJf3U23R5oQjIrbrvQ/AIIRpzavo7TLHG
kn46/RkCgYEA8GiWEe/s79p5JMlwymAWLo3EA7Vkzrs+Whq8t3+wL6d/ZfS/suaF
zOFgKLYhM/2PdI2NRr/X1cPQ4DJLt6SuOnLBPrsnqbtODjCNpmJmNMZDMJSFYjTU
2feV5Fhv6VbB14JtyzJgRQvwkx/tEffHvT+w1WHouBYZqxRgt230yLo=
-----END RSA PRIVATE KEY-----

clean_up CreateKeypair: 
END return value: 0
 

9.2列出所有的key list

REQ: curl -g -i -X GET http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}dae0d12117b44c1dfc3a9e69e11a9927ffd60c2c"
Starting new HTTP connection (1): 10.1.2.204
http://10.1.2.204:8774 "GET /v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs HTTP/1.1" 200 1044
RESP: [200] Content-Length: 1044 Content-Type: application/json Openstack-Api-Version: compute 2.1 X-Openstack-Nova-Api-Version: 2.1 Vary: OpenStack-API-Version, X-OpenStack-Nova-API-Version X-Compute-Request-Id: req-b564ff2f-cfe1-4012-85c4-f52eb8f640fc Date: Thu, 01 Nov 2018 06:26:12 GMT 
RESP BODY: {"keypairs": [{"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCXnv/umdoWGPsxXTSnML2Vk7kAA3tNtA7qUDOflA+DAr8rjk6l9Lu5k+hF1Nj8uhY03Ym/K2qpqkIGTL1/4+sGQxoVlIoNqJUs6yXxGeiEGJpisH9Roi+wcG+wYm1PA7Nj3lLV36L17D42FIdv8Qics4qP+BYbxRmpS0wq/VzuBOhFmg5S3LVEMBuU2NUk5DuJ+i3S9Wl0vaW7UV0sK6KUizgpsGlJIomfix4K+4QMyqMKNzYCSETd3tu8yGXuLwJwd9hFnUpEbAUkmEO5TpmImU/uXBqvHpyRLq8539f0CaXYa57IkAmY8ffsGCY6dGwUHsCusQzw5hRHxB2I4aeB root@master02\n", "name": "mykey", "fingerprint": "cb:2f:ca:47:0a:16:2d:fb:dd:5c:55:df:5b:3c:e9:56"}}, {"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZPYh9hMLP6QUaYrdn9AM7V4j6ssYgmsQGDM5EQNiycBX96vnFLdbo1nModlbQ6XKoIYoz06NAJRYUvMmEys56hqkpy+/0JAM1TcJBLr/wJuMohyu0Rt4QWw/DLfOpDsCMXorjdtIXAmtkkIg96l6w1DfAHqhKAzZgMTXcIcbZgHYfxfNFUoawdMmtVlZ09+YLjdRIa+QrerYV7p/MRRe4Gqu+SwunG3jMLAYi6DyAZcE3sqcDUvH9/y3R+8Vmr2tY/oZrnTMJ82e1FqM5AsiFBIJuOOl/9IFW2alwt+GC7fdv+WQRXmSgGQQ3uNEFM4gzd8+ayRsJgztQp96TGuiT Generated-by-Nova", "name": "shiyanshi", "fingerprint": "00:a5:46:ee:66:00:62:eb:63:f7:8e:57:10:c9:4c:a0"}}]}

GET call to compute for http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs used request id req-b564ff2f-cfe1-4012-85c4-f52eb8f640fc
+-----------+-------------------------------------------------+
| Name      | Fingerprint                                     |
+-----------+-------------------------------------------------+
| mykey     | cb:2f:ca:47:0a:16:2d:fb:dd:5c:55:df:5b:3c:e9:56 |
| shiyanshi | 00:a5:46:ee:66:00:62:eb:63:f7:8e:57:10:c9:4c:a0 |
+-----------+-------------------------------------------------+
clean_up ListKeypair: 
END return value: 0
 

9.3 展示shiyanshi 的详情

 curl -g -i -X GET http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs/shiyanshi -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}d6e27b46a7584eff99d758ae4c1c54c1e1926fc2"
Starting new HTTP connection (1): 10.1.2.204
http://10.1.2.204:8774 "GET /v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs/shiyanshi HTTP/1.1" 200 674
RESP: [200] Content-Length: 674 Content-Type: application/json Openstack-Api-Version: compute 2.1 X-Openstack-Nova-Api-Version: 2.1 Vary: OpenStack-API-Version, X-OpenStack-Nova-API-Version X-Compute-Request-Id: req-7a16ef36-2efc-48e9-b206-d919fe386431 Date: Thu, 01 Nov 2018 06:27:08 GMT 
RESP BODY: {"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZPYh9hMLP6QUaYrdn9AM7V4j6ssYgmsQGDM5EQNiycBX96vnFLdbo1nModlbQ6XKoIYoz06NAJRYUvMmEys56hqkpy+/0JAM1TcJBLr/wJuMohyu0Rt4QWw/DLfOpDsCMXorjdtIXAmtkkIg96l6w1DfAHqhKAzZgMTXcIcbZgHYfxfNFUoawdMmtVlZ09+YLjdRIa+QrerYV7p/MRRe4Gqu+SwunG3jMLAYi6DyAZcE3sqcDUvH9/y3R+8Vmr2tY/oZrnTMJ82e1FqM5AsiFBIJuOOl/9IFW2alwt+GC7fdv+WQRXmSgGQQ3uNEFM4gzd8+ayRsJgztQp96TGuiT Generated-by-Nova", "user_id": "00bdab9f777c4be7aa4fdf002d89b77e", "name": "shiyanshi", "deleted": false, "created_at": "2018-11-01T06:24:49.000000", "updated_at": null, "fingerprint": "00:a5:46:ee:66:00:62:eb:63:f7:8e:57:10:c9:4c:a0", "deleted_at": null, "id": 8}}

GET call to compute for http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs/shiyanshi used request id req-7a16ef36-2efc-48e9-b206-d919fe386431
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | 2018-11-01T06:24:49.000000                      |
| deleted     | False                                           |
| deleted_at  | None                                            |
| fingerprint | 00:a5:46:ee:66:00:62:eb:63:f7:8e:57:10:c9:4c:a0 |
| id          | 8                                               |
| name        | shiyanshi                                       |
| updated_at  | None                                            |
| user_id     | 00bdab9f777c4be7aa4fdf002d89b77e                |
+-------------+-------------------------------------------------+
clean_up ShowKeypair: 
END return value: 0
 

9.4删除shiyanshi key

REQ: curl -g -i -X DELETE http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs/shiyanshi -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}0887813d1b8edda742c0a4c7e3d79fbea6f9c2a9"
http://10.1.2.204:8774 "DELETE /v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs/shiyanshi HTTP/1.1" 202 0
RESP: [202] Content-Length: 0 Content-Type: application/json Openstack-Api-Version: compute 2.1 X-Openstack-Nova-Api-Version: 2.1 Vary: OpenStack-API-Version, X-OpenStack-Nova-API-Version X-Compute-Request-Id: req-f2d4c42f-5157-4471-93d7-a2542fdbe812 Date: Thu, 01 Nov 2018 06:28:11 GMT
DELETE call to compute for http://10.1.2.204:8774/v2.1/cdbcd047f8b84755958248c36ded1e73/os-keypairs/shiyanshi used request id req-f2d4c42f-5157-4471-93d7-a2542fdbe812
clean_up DeleteKeypair: 
END return value: 0
 

 

你可能感兴趣的:(OpenStack)