使用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)首先按 ...
随机推荐
- Oracle Union Union All 对查询结果集操作
在Oracle中提供了三种类型的集合操作: 并(UNION).交(INTERSECT).差(MINUS) Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序: Union Al ...
- Hadoop集群的各部分常用端口
hadoop集群的各部分一般都会使用到多个端口,有些是daemon之间进行交互之用,有些是用于RPC访问以及HTTP访问.而随着hadoop周边组件的增多,完全记不住哪个端口对应哪个应用,特收集记录如 ...
- intellij-idea+maven搭建scala环境
一 . 安装JDK 1. 下载地址: http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6 ...
- RabbitMQ学习之(一)_初步了解RabbitMQ、RabbitMQ的使用流程、为什么要使用RabbitMQ、RabbitMQ的应用场景
初识RabbitMQ RabbitMQ是一个在AMQP协议基础上实现的消息队列系统, 是一个消息代理.它的核心原理非常简单:接收和发送消息.你可以把它想像成一个邮局:你把信件放入邮箱,邮递员就会把信件 ...
- Python3.x:将数据下载到xls时候用xml格式保存一份读取内容
Python3.x:将数据下载到xls时候用xml格式保存一份读取内容 核心代码: import json import xml.dom.minidom from urllib import requ ...
- s3cmd安装
配置yum.repos cd /etc/yum.repos.d/ vim s3tools.repo [s3tools] name=Tools for managing Amazon S3 - Simp ...
- linux 安装vscode
滚动安装vscode 需要先添加源,然后install 以centos为例: sudo rpm --import https://packages.microsoft.com/keys/microso ...
- 20145240《网络对抗》Web基础
Web基础 实验后回答问题 什么是表单? 表单在网页中主要负责数据采集功能. 一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. 表单域 ...
- Metasploit安装——centos6.5
1:安装ruby yum -y install ruby 2:根据官方文档执行,安装支持包 yum install xorg-x11-server-Xvfb -y 3:官网下载最新版的Metaspl ...
- 使用ubifs作为根文件系统的openwrt如何在进行sysupgrade时保存旧的配置
1.openwrt的默认方案(squashfs + jffs2) sysupgrade脚本直接调用default_do_upgrade更新设备树.内核.根文件系统,那么它是如何保存旧配置的呢?请看de ...