openStack 调用API方式create router

来源:互联网 发布:华晨中华v5配置数据图 编辑:程序博客网 时间:2024/06/07 13:18

刚接触openStack,先用api进行各个组件的创建,从而创建一台外网可以访问的虚机;

这里记录下创建router时的一些做法,因为刚接触可能会有理解错误的地方,希望各位多多指正。

官方api docs文档http://developer.openstack.org/api-ref-networking-v2-ext.html

这里用的是openStack的Icehouse版本,采用google 的插件Advanced rest Client进行api调用。当然前提是已经部署好了一套openStack的环境。

                                  Advanced rest Client 调用api 操作

network默认端口是9696

1、router在创建时可以指定floating_ip,也可以不指定;
若在语法中不指定时,首先需要提前创建floating_ip, 若无可用的则将返回错误信息如下:
requeset:
<span style="font-size:14px;">{    "router": {        "external_gateway_info": {            "network_id": "1d8b48f2-dc17-48b6-b143-6e21663f9c5f"    // 公网的network_id        }    }}</span>
response:(Error
<span style="font-size:14px;">{    "NeutronError": {        "message": "Bad router request: Specified external ip [] is not a floating ip or there's no remaining floating ip to use in external network 1d8b48f2-dc17-48b6-b143-6e21663f9c5f for tenant 1437b9a6432b48c09e89d2284640d28b",        "type": "BadRequest",        "detail": ""    }}</span>
如果已经创建了多个floating_ip,则自动将会把router与其中一个floating_ip进行绑定;

2、若在创建router时,有多个floating_ip,需要指定某个ip,则可以在语法中进行指定;
首先我们创建多个floating_ip;
request:
<span style="font-size:14px;">    "router": {        "name": "specify the fix floating_ip",        "external_gateway_info": {            "network_id": "1d8b48f2-dc17-48b6-b143-6e21663f9c5f",    //公网的network_id ;            "external_fixed_ips": [                {                              "ip_address": "10.161.111.30"        // 指定的floating_ip地址;                }            ]        }    }}</span>
response:
<span style="font-size:14px;">{    "router": {        "status": "ACTIVE",        "external_gateway_info": {            "network_id": "1d8b48f2-dc17-48b6-b143-6e21663f9c5f",            "external_fixed_ips": [                {                    "subnet_id": "e23fb611-03bf-4b9f-82ae-8cc52eb2f344",                    "ip_address": "10.161.111.30"                }            ]        },        "dedicated": false,        "name": "specify the fix floating_ip",        "admin_state_up": true,        "tenant_id": "1437b9a6432b48c09e89d2284640d28b",        "domain_id": null,        "id": "b0ea9d03-9880-49a8-8008-3e52f3f4e536"    }}</span>
返回信息表明已经创建router成功,并且绑定了floating_ip:10.161.111.30 ;




0 0