使用curl调试openstack的api
一 系统环境
OpenStack: Mitaka
工具: 最简单的工具:restclient,本次使用curl
二 开搞
访问openstack的API之前,用户使用用户名和密码向keystone进行认证。在通过keystone认证后,keystone会在返回数据中包含一个ServiceCatalog。此ServiceCatalog中包含keystone中的所有service endpoints。用户即可根据这些endpoint来进行后续的RestAPI调用。
本文主要示例如何调用V3版本API。对于V2版本,使用openstack命令加--debug参数,可以看到keystone调用curl的具体写法:
如果不知道该怎么取调用可以使用--debug查看
[root@controller01 ~]# openstack --debug role list
START with options: ['--debug', 'role', 'list']
options: Namespace(access_token_endpoint='', auth_type='', auth_url='http://controller:35357/v3', cacert='', client_id='', client_secret='***', cloud='', debug=True, default_domain='default', deferred_help=False, domain_id='', domain_name='', endpoint='', identity_provider='', identity_provider_url='', insecure=None, interface='', log_file=None, os_compute_api_version='', os_data_processing_api_version='1.1', os_data_processing_url='', os_dns_api_version='2', os_identity_api_version='3', os_image_api_version='2', os_network_api_version='', os_object_api_version='', os_orchestration_api_version='1', os_project_id=None, os_project_name=None, os_volume_api_version='', password='***', profile=None, project_domain_id='', project_domain_name='default', project_id='', project_name='admin', protocol='', region_name='', scope='', service_provider_endpoint='', timing=False, token='***', trust_id='', url='', user_domain_id='', user_domain_name='default', user_id='', username='admin', verbose_level=3, verify=None)
defaults: {u'auth_type': 'password', u'compute_api_version': u'2', 'key': None, u'database_api_version': u'1.0', 'api_timeout': None, u'baremetal_api_version': u'1', u'image_api_version': u'2', 'cacert': None, u'image_api_use_tasks': False, u'floating_ip_source': u'neutron', u'orchestration_api_version': u'1', u'interface': None, u'network_api_version': u'2', u'image_format': u'qcow2', u'key_manager_api_version': u'v1', u'metering_api_version': u'2', 'verify': True, u'identity_api_version': u'2.0', u'volume_api_version': u'2', 'cert': None, u'secgroup_source': u'neutron', u'container_api_version': u'1', u'dns_api_version': u'2', u'object_store_api_version': u'1', u'disable_vendor_agent': {}}
cloud cfg: {'auth_type': 'password', u'compute_api_version': u'2', 'key': None, u'database_api_version': u'1.0', 'data_processing_api_version': '1.1', u'network_api_version': u'2', u'image_format': u'qcow2', u'image_api_version': '2', 'verify': True, u'dns_api_version': '2', u'object_store_api_version': u'1', 'verbose_level': 3, 'region_name': '', 'api_timeout': None, u'baremetal_api_version': u'1', 'auth': {'username': 'admin', 'project_name': 'admin', 'user_domain_name': 'default', 'auth_url': 'http://controller:35357/v3', 'password': '***', 'project_domain_name': 'default'}, 'default_domain': 'default', u'container_api_version': u'1', u'image_api_use_tasks': False, u'floating_ip_source': u'neutron', u'orchestration_api_version': '1', 'timing': False, 'cacert': None, u'key_manager_api_version': u'v1', u'metering_api_version': u'2', 'deferred_help': False, u'identity_api_version': '3', u'volume_api_version': u'2', 'cert': None, u'secgroup_source': u'neutron', 'debug': True, u'interface': None, u'disable_vendor_agent': {}}
compute API version 2, cmd group openstack.compute.v2
network API version 2, cmd group openstack.network.v2
image API version 2, cmd group openstack.image.v2
volume API version 2, cmd group openstack.volume.v2
identity API version 3, cmd group openstack.identity.v3
object_store API version 1, cmd group openstack.object_store.v1
data_processing API version 1.1, cmd group openstack.data_processing.v1
orchestration API version 1, cmd group openstack.orchestration.v1
dns API version 2, cmd group openstack.dns.v2
command: role list -> openstackclient.identity.v3.role.ListRole
Auth plugin password selected
auth_type: password
Using auth plugin: password
Using parameters {'username': 'admin', 'project_name': 'admin', 'auth_url': 'http://controller:35357/v3', 'user_domain_name': 'default', 'password': '***', 'project_domain_name': 'default'}
Get auth_ref
REQ: curl -g -i -X GET http://controller:35357/v3 -H "Accept: application/json" -H "User-Agent: python-openstackclient keystoneauth1/2.4.1 python-requests/2.10.0 CPython/2.7.5"
Starting new HTTP connection (1): controller
"GET /v3 HTTP/1.1" 200 250
RESP: [200] Date: Tue, 20 Mar 2018 03:06:46 GMT Server: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 Vary: X-Auth-Token x-openstack-request-id: req-7730d910-9c4f-4ba3-956f-1dbdb8fc63fb Content-Length: 250 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: application/json
RESP BODY: {"version": {"status": "stable", "updated": "2016-04-04T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v3+json"}], "id": "v3.6", "links": [{"href": "http://controller:35357/v3/", "rel": "self"}]}} Making authentication request to http://controller:35357/v3/auth/tokens
"POST /v3/auth/tokens HTTP/1.1" 201 5362
run(Namespace(columns=[], domain=None, formatter='table', group=None, group_domain=None, inherited=False, max_width=0, noindent=False, project=None, project_domain=None, quote_mode='nonnumeric', user=None, user_domain=None))
Instantiating identity client: <class 'keystoneclient.v3.client.Client'>
Making authentication request to http://controller:35357/v3/auth/tokens
"POST /v3/auth/tokens HTTP/1.1" 201 5362
REQ: curl -g -i -X GET http://controller:35357/v3/roles -H "User-Agent: python-keystoneclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}84424885abb0746761572e750c8c8add1685ac37"
"GET /v3/roles HTTP/1.1" 200 790
RESP: [200] Date: Tue, 20 Mar 2018 03:06:47 GMT Server: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 Vary: X-Auth-Token x-openstack-request-id: req-bac27bef-ee3f-415b-b448-84a4f7ba73cc Content-Length: 790 Keep-Alive: timeout=5, max=97 Connection: Keep-Alive Content-Type: application/json
RESP BODY: {"links": {"self": "http://controller:35357/v3/roles", "previous": null, "next": null}, "roles": [{"domain_id": null, "id": "0bf276f24ffe4aa9a4c217879a43216c", "links": {"self": "http://controller:35357/v3/roles/0bf276f24ffe4aa9a4c217879a43216c"}, "name": "heat_stack_user"}, {"domain_id": null, "id": "129b07bb445d42ae81fad8aa36d77d1f", "links": {"self": "http://controller:35357/v3/roles/129b07bb445d42ae81fad8aa36d77d1f"}, "name": "admin"}, {"domain_id": null, "id": "71d924953a3141c4955839020dd8aba8", "links": {"self": "http://controller:35357/v3/roles/71d924953a3141c4955839020dd8aba8"}, "name": "heat_stack_owner"}, {"domain_id": null, "id": "c797f238b7fc4f4a990879619afe758b", "links": {"self": "http://controller:35357/v3/roles/c797f238b7fc4f4a990879619afe758b"}, "name": "user"}]} +----------------------------------+------------------+
| ID | Name |
+----------------------------------+------------------+
| 0bf276f24ffe4aa9a4c217879a43216c | heat_stack_user |
| 129b07bb445d42ae81fad8aa36d77d1f | admin |
| 71d924953a3141c4955839020dd8aba8 | heat_stack_owner |
| c797f238b7fc4f4a990879619afe758b | user |
+----------------------------------+------------------+
clean_up ListRole:
END return value: 0
1 获取token和catalog
[root@controller01 ~]# curl -i -X POST http://controller:35357/v3/auth/tokens -H "Content-type: application/json" -d '{"auth": {"identity": {"methods": ["password"],"password": {"user": {"domain": {"name": "Default"},"name": "admin","password": "trendy123"}}},"scope": {"project": {"domain": {"name": "Default"},"name": "admin"}}}}'
HTTP/1.1 201 Created
Date: Tue, 20 Mar 2018 03:18:20 GMT
Server: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5
X-Subject-Token: 30494bb13fa746a8a8752acd280f06d0
Vary: X-Auth-Token
x-openstack-request-id: req-88e73a96-32af-49fb-92bb-d05e595fd284
Content-Length: 5362
Content-Type: application/json
{"token": {"methods": ["password"], "roles": [{"id": "129b07bb445d42ae81fad8aa36d77d1f", "name": "admin"}], "expires_at": "2018-03-20T04:18:20.962364Z", "project": {"domain": {"id": "bb1b0223fdc84934af86523729e4502a", "name": "default"}, "id": "4a3b38b999da4c37bd049a2d5c37920f", "name": "admin"}, "catalog": [{"endpoints": [{"region_id": "RegionOne", "url": "http://controller:9696", "region": "RegionOne", "interface": "internal", "id": "221ef83c7064464e9c4059fdb120a524"}, {"region_id": "RegionOne", "url": "http://controller:9696", "region": "RegionOne", "interface": "public", "id": "7558ce17648e42309a713a296883b7b5"}, {"region_id": "RegionOne", "url": "http://controller:9696", "region": "RegionOne", "interface": "admin", "id": "8dc2142351d24c88ac7cc34ae1d1298f"}], "type": "network", "id": "1e8988a8279144ee94d00d6fd050af84", "name": "neutron"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:9292", "region": "RegionOne", "interface": "public", "id": "433b2acf9a1440879f2d7608563fb950"}, {"region_id": "RegionOne", "url": "http://controller:9292", "region": "RegionOne", "interface": "admin", "id": "64aec5873b2d4b93909d86846fddd198"}, {"region_id": "RegionOne", "url": "http://controller:9292", "region": "RegionOne", "interface": "internal", "id": "8bddd1fba6144709b7864c007e430acc"}], "type": "image", "id": "3ee10bb8c3cc4dfcba0094b0f2609547", "name": "glance"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:8776/v1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "admin", "id": "7b2bb710d2ff40a38bef331835787855"}, {"region_id": "RegionOne", "url": "http://controller:8776/v1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "public", "id": "808e9ec2276c43279b9318efc983c1a6"}, {"region_id": "RegionOne", "url": "http://controller:8776/v1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "internal", "id": "ea239eb9e1934183aea8de7e2fa4b50d"}], "type": "volume", "id": "45b6f11db6104e0284af07e013866a32", "name": "cinder"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:8776/v2/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "public", "id": "3730e124b62b4c2290728a5f3d7c3172"}, {"region_id": "RegionOne", "url": "http://controller:8776/v2/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "admin", "id": "b2aab32788e5435d930193332bf68d42"}, {"region_id": "RegionOne", "url": "http://controller:8776/v2/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "internal", "id": "c0395d0d8bd34dbcb1f587b13cc68b1b"}], "type": "volumev2", "id": "478e853e09b5421ab141fbd98c0346ed", "name": "cinderv2"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:8774/v2.1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "public", "id": "2942c4fd810144c1be14028dffa83c91"}, {"region_id": "RegionOne", "url": "http://controller:8774/v2.1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "admin", "id": "336396d3d5954410b5940e8f1bcb48e7"}, {"region_id": "RegionOne", "url": "http://controller:8774/v2.1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "internal", "id": "c3ace97f947b45238ba29ed831a21dd3"}], "type": "compute", "id": "6b598898644647fca69840ea2963aefc", "name": "nova"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:5000/v3", "region": "RegionOne", "interface": "public", "id": "336fc0683cf44d5c85a1e56efcce0aaa"}, {"region_id": "RegionOne", "url": "http://controller:35357/v3", "region": "RegionOne", "interface": "admin", "id": "ac31a17c6abd46a4bfafb9ccf0f7c38e"}, {"region_id": "RegionOne", "url": "http://controller:5000/v3", "region": "RegionOne", "interface": "internal", "id": "fdd2e827f6ef45538c1aa360df913280"}], "type": "identity", "id": "78e660c901c545c7b065bc35e8351d0b", "name": "keystone"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:8004/v1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "admin", "id": "2e7259d915ba4a51ae4ca3327bcfe2ef"}, {"region_id": "RegionOne", "url": "http://controller:8004/v1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "internal", "id": "4f1dbaa50be94b29ad492ba6b632ca0c"}, {"region_id": "RegionOne", "url": "http://controller:8004/v1/4a3b38b999da4c37bd049a2d5c37920f", "region": "RegionOne", "interface": "public", "id": "f17603f93de24e1aacb6d74759ecb700"}], "type": "orchestration", "id": "bce75791740843c09e4c9ef09be5a668", "name": "heat"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller:8000/v1", "region": "RegionOne", "interface": "public", "id": "411f9576ac874cbf818808342546823a"}, {"region_id": "RegionOne", "url": "http://controller:8000/v1", "region": "RegionOne", "interface": "admin", "id": "5116b8f7a49d46cb8024d297e352e98f"}, {"region_id": "RegionOne", "url": "http://controller:8000/v1", "region": "RegionOne", "interface": "internal", "id": "63d8906e594f45a29fb2f2a833bc2e17"}], "type": "cloudformation", "id": "f5539459039f4fc090d091b37d17c187", "name": "heat-cfn"}], "user": {"domain": {"id": "bb1b0223fdc84934af86523729e4502a", "name": "default"}, "id": "69d239d3f58147ef8ff679bdb352c19d", "name": "admin"}, "audit_ids": ["1U5BTGV4SKi7x4S-cUkrFA"], "issued_at": "2018-03-20T03:18:20.962421Z"}}[root@controller01 ~]# clear
[root@controller01 ~]#
[root@controller01 ~]#
[root@controller01 ~]#
[root@controller01 ~]# curl -i -X POST http://controller:35357/v3/auth/tokens -H "Content-type: application/json" -d '{"auth": {"identity": {"methods": ["password"],"password": {"user": {"domain": {"name": "Default"},"name": "admin","password": "trendy123"}}},"scope": {"project": {"domain": {"name": "Default"},"name": "admin"}}}}'|grep X-Subject-Token
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5575 100 5362 100 213 12924 513 --:X-Subject-Token: a0e8c4b32a324caf9ce6e6d77d67edd8
--:-- --:--:-- --:--:-- 12920
2 get方法(获取虚拟机)
[root@controller01 ~]# curl -i http://controller:8774/v2.1/4a3b38b999da4c37bd049a2d5c37920f/servers -v -H "X-Auth-Token:a0e8c4b32a324caf9ce6e6d77d67edd8"
* About to connect() to controller port 8774 (#0)
* Trying 172.20.1.13...
* Connected to controller (172.20.1.13) port 8774 (#0)
> GET /v2.1/4a3b38b999da4c37bd049a2d5c37920f/servers HTTP/1.1
> User-Agent: curl/7.29.0
> Host: controller:8774
> Accept: */*
> X-Auth-Token:a0e8c4b32a324caf9ce6e6d77d67edd8
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Length: 706
Content-Length: 706
< Content-Type: application/json
Content-Type: application/json
< X-Openstack-Nova-Api-Version: 2.1
X-Openstack-Nova-Api-Version: 2.1
< Vary: X-OpenStack-Nova-API-Version
Vary: X-OpenStack-Nova-API-Version
< X-Compute-Request-Id: req-60e0c85d-55ce-4771-977d-1a7513dfd3e8
X-Compute-Request-Id: req-60e0c85d-55ce-4771-977d-1a7513dfd3e8
< Date: Tue, 20 Mar 2018 03:27:23 GMT
Date: Tue, 20 Mar 2018 03:27:23 GMT <
* Connection #0 to host controller left intact
{"servers": [{"id": "7e2993be-10bd-4481-929c-b6adff09d72c", "links": [{"href": "http://controller:8774/v2.1/4a3b38b999da4c37bd049a2d5c37920f/servers/7e2993be-10bd-4481-929c-b6adff09d72c", "rel": "self"}, {"href": "http://controller:8774/4a3b38b999da4c37bd049a2d5c37920f/servers/7e2993be-10bd-4481-929c-b6adff09d72c", "rel": "bookmark"}], "name": "Lidb_test"}, {"id": "d9413831-756c-43dd-a027-57b45749f085", "links": [{"href": "http://controller:8774/v2.1/4a3b38b999da4c37bd049a2d5c37920f/servers/d9413831-756c-43dd-a027-57b45749f085", "rel": "self"}, {"href": "http://controller:8774/4a3b38b999da4c37bd049a2d5c37920f/servers/d9413831-756c-43dd-a027-57b45749f085", "rel": "bookmark"}], "name": "LTM-test"}]}
3 post方法(举例启动虚拟机)
curl -i 'http://mycontroller:8774/v2.1/tenant-id/servers/server-id/action' -X POST -d '{"os-start": null}' -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token:token-id"
使用curl调试openstack的api的更多相关文章
- curl调用openstack API总结
curl命令是Linux下一个可以使用多种协议收发数据的工具,包括http协议.openstack的API接口都是URL地址:http://controller:35357/v3可以使用curl命令进 ...
- 使用curl操作openstack swift
openstack官网有专门的开发者文档介绍如何使用curl操作swift(http://docs.openstack.org/api/openstack-object-storage/1.0/con ...
- OpenStack REST API使用
以前一直想写博客,但因各种因素一直没写.最近在做OpenStack,而OpenStack对外提供REST API,今天就简要介绍一下OpenStack REST API 使用,关于什么是REST AP ...
- 用pdb调试OpenStack Havana
作为个人学习笔记分享,有任何问题欢迎交流! Note:若是想要用pdb调试OpenStack,必须通过Devstack安装它. Devstack安装Havana过程 1. 使用一般用户(非root ...
- Openstack python api 学习文档 api创建虚拟机
Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...
- python调用openstack的api,create_instance的程序解析
python调用openstack的api,create_instance的程序解析 2017年10月17日 15:27:24 CloudXli 阅读数:848 版权声明:本文为博主原创文章,未经 ...
- (弃)解读Openstack Identity API v2.0
目前OpenStack社区提供了详尽的API文档,并配有丰富的说明和示例,关于Identity API v2查看这里, 关于Identity API v3请查看这里. 尽管现在官方已经不建议OpenS ...
- 远程调试openstack
之前一直没有找到方法调试openstack的horizon代码,现在终于找到方法了,特别感谢下面这篇博客,讲解非常清晰: http://blog.csdn.net/tantexian/article/ ...
- 利用pycharm远程调试openstack代码
1.安装pycharm专业版 本文安装pycharm 2016.2.3专业版.网上教程较多,这里不做详细介绍,只要到pycharm官网上下载应用程序进行安装即可. 2.pycharm配置 (1)首先按 ...
随机推荐
- 06 swap命令,进程管理,rmp命令与yum命令,源码安装python
作业一: 1)开启Linux系统前添加一块大小为15G的SCSI硬盘 2)开启系统,右击桌面,打开终端 3)为新加的硬盘分区,一个主分区大小为5G,剩余空间给扩展分区,在扩展分区上划分1个逻辑分区,大 ...
- Oracle 分组函数
分组函数的介绍 分组函数作用于一组数据,并对一组数据返回一个值. (引用网上的一张图) 分组函数的使用规则 SELECT [column,] group_function(column) FROM t ...
- HDFS datanode心跳与运维中的实际案例
分布式系统的节点之间常采用心跳来维护节点的健康状态,如yarn的rm与nm之间,hdfs的nn与dn之间.DataNode会定期(dfs.heartbeat.interval配置项配置,默认是3秒)向 ...
- Linux下修改时间
修改linux的时间可以使用date指令 date命令的功能是显示和设置系统日期和时间. 输入date 查看目前系统时间. 修改时间需要 date -功能字符 修改内容 命令中各选项的含义分别为: - ...
- Glide Picasso和Fresco的对比
比较Picasso.Glide 和 Fresco 三种图片加载库 比较 Picasso 与 Glide 总体来说二者极为相似,有着近乎相同的 API 的使用风格,但 Glide 在缓存策略和加载 gi ...
- ElasticSearch(三) ElasticSearch中文分词插件IK的安装
正因为Elasticsearch 内置的分词器对中文不友好,会把中文分成单个字来进行全文检索,所以我们需要借助中文分词插件来解决这个问题. 一.安装maven管理工具 Elasticsearch 要使 ...
- Android系统启动过程[典☆☆☆]
Android系统启动过程 首先Android框架架构图:(来自网上,我觉得这张图看起来很清晰) Linux内核启动之后就到Android Init进程,进而启动Android相关的服务和应用. 启动 ...
- mysql系列之多实例介绍
介绍: mysql多实例,简单理解就是在一台服务器上,mysql服务开启多个不同的端口(如3306.3307),运行多个服务进程.这些 mysql 服务进程通过不同的 socket来监听不同的数据端口 ...
- gerrit代码审核工具之“error unpack failed error Missing unknown”错误解决思路
使用gerrit代码审核工具时遇到error: unpack failed: error Missing unknown d6d7c89bd1d77f44c5c8e99437aaffbfc0684e7 ...
- 简单的dos命令
cd .. 进入上一层目录cd /.. 进入当前盘所有根目录d: 进入d盘dir 查看下一级目录d:>d:\abc.txt 新建一个文档hostname 主机名SET 查看环境变 ...