quantum命令行创建和删除网络

时间:2022-06-29 05:14:25

作为个人学习笔记分享,有任何问题欢迎交流!


更新记录

3013.8.9 添加命令行创建网络

1. quantum命令行创建网络

列出已创建的用户:

   # keystone  user-list

  +----------------------------------+---------+---------+------------------+

   |                id                |   name | enabled |      email       |

  +----------------------------------+---------+---------+------------------+

   |c815f963fef54f37b0ac84a6a7eca8b4 | admin  |   True |  admin@leju.com  |

   |f30d6d67936e41869117b42e5403255c |  cinder|   True | cinder@leju.com  |

   |5ec7e55586004aabb6a9ecc8247ba751 | glance |   True  | glance@leju.com  |

   |197c373a254749f2b5cec7c91ef14c88 |  nova  |   True |  nova@leju.com   |

   |8fec2c89a87d43f19c9e7d487001efa3 | quantum |  True  | quantum@leju.com |

  +----------------------------------+---------+---------+------------------+

* 列出已创建的租户:

   # keystone tenant-list

  +----------------------------------+---------+---------+

   |                id                |   name | enabled |

  +----------------------------------+---------+---------+

   |8c0104041b034df3a79c17a9517dd3f9 | admin  |   True |

   |2b376839187441c5888d35411e8ff8b0 | service |  True  |

  +----------------------------------+---------+---------+

* 为admin租户创建网络:

   # quantum net-create --tenant-id 8c0104041b034df3a79c17a9517dd3f9 net_admin

   Created anew network:

  +---------------------------+--------------------------------------+

   |Field                     | Value                                |

  +---------------------------+--------------------------------------+

   |admin_state_up            | True                                 |

   | id                        |fed2d721-41d1-428f-b0a3-41ac8f7a51a1 |

   |name                      | net_admin                            |

   |provider:network_type     | gre                                  |

   |provider:physical_network |                                      |

   |provider:segmentation_id  | 1                                    |

   | router:external           | False                                |

   |shared                    | False                                |

   |status                    | ACTIVE                               |

   |subnets                   |                                      |

   |tenant_id                 |8c0104041b034df3a79c17a9517dd3f9     |

  +---------------------------+--------------------------------------+

# 为admin租户创建子网:

   # quantum subnet-create  --tenant-id 8c0104041b034df3a79c17a9517dd3f9 net_admin172.16.100.0/24

   Created anew subnet:

  +------------------+----------------------------------------------------+

   |Field            | Value                                              |

  +------------------+----------------------------------------------------+

   |allocation_pools | {"start": "172.16.100.2","end": "172.16.100.254"} |

   |cidr             | 172.16.100.0/24                                    |

   |dns_nameservers  |                                                   |

   |enable_dhcp      | True                                              |

   |gateway_ip       | 172.16.100.1                                       |

   |host_routes      |                                                   |

   | id               |fb141492-8aa1-437b-8192-315e19e7f4d2               |

   |ip_version       | 4                                                 |

   |name             |                                                   |

   |network_id       | fed2d721-41d1-428f-b0a3-41ac8f7a51a1               |

   |tenant_id        |8c0104041b034df3a79c17a9517dd3f9                   |

  +------------------+----------------------------------------------------+

* 为admin租户创建路由器:

   # quantum router-create --tenant-id 8c0104041b034df3a79c17a9517dd3f9 router_admin

   Created anew router:

  +-----------------------+--------------------------------------+

   |Field                 | Value                                |

  +-----------------------+--------------------------------------+

   |admin_state_up        | True                                 |

   |external_gateway_info |                                      |

   | id                    |76d8ac10-a6df-4dfa-b691-297da374c811 |

   |name                  | router_admin                         |

   |status                | ACTIVE                               |

   |tenant_id             |8c0104041b034df3a79c17a9517dd3f9     |

  +-----------------------+--------------------------------------+

* 列出路由代理类型:

   # quantumagent-list

  +--------------------------------------+--------------------+-----------+-------+----------------+

   | id                                   |agent_type         | host      | alive | admin_state_up |

  +--------------------------------------+--------------------+-----------+-------+----------------+

   |2b68d118-c4bb-44a0-8387-678c5bdb1653 | L3 agent           | openstack | :-)   | True           |

   |7b42460c-cffd-494f-94b1-c6b4f3b5e102 | DHCP agent         | openstack | :-)   | True           |

   |e443fbf2-398c-47ab-89d9-5d9907217379 | Open vSwitch agent | openstack |:-)   | True           |

  +--------------------------------------+--------------------+-----------+-------+----------------+

* 将router_admin设置为L3代理类型:

   # quantum l3-agent-router-add 2b68d118-c4bb-44a0-8387-678c5bdb1653 router_admin

   Addedrouter router_admin to L3 agent

* 将net_admin子网与router_admin路由关联:

   # quantum router-interface-add 76d8ac10-a6df-4dfa-b691-297da374c811  fb141492-8aa1-437b-8192-315e19e7f4d2

   Addedinterface to router 76d8ac10-a6df-4dfa-b691-297da374c811

* 创建外网net_external,注意设置--router:external=True:

   # quantum net-create net_external --router:external=True --shared

   Created anew network:

   +---------------------------+--------------------------------------+

   |Field                     | Value                                |

  +---------------------------+--------------------------------------+

   |admin_state_up            | True                                 |

   | id                        |7a7acad8-cabf-49f8-804f-ce6871d9cd63 |

   |name                      |net_external                         |

   |provider:network_type     | gre                                  |

   | provider:physical_network|                                      |

   |provider:segmentation_id  | 2                                    |

   |router:external           | True                                 |

   |shared                    | True                                 |

   |status                    | ACTIVE                               |

   |subnets                   |                                      |

   |tenant_id                 |8c0104041b034df3a79c17a9517dd3f9     |

   +---------------------------+--------------------------------------+

* 为net_external创建子网,注意设置的gateway必须在给到的网段内:

   # quantum subnet-create net_external --gateway 192.168.100.1 192.168.100.0/24--enable_dhcp=False

   Created anew subnet:

  +------------------+------------------------------------------------------+

   |Field            | Value                                               |

  +------------------+------------------------------------------------------+

   |allocation_pools | {"start": "192.168.100.2","end": "192.168.100.254"} |

   |cidr             | 192.168.100.0/24                                     |

   |dns_nameservers  |                                                     |

   |enable_dhcp      | False                                                |

   |gateway_ip       | 192.168.100.1                                        |

   |host_routes      |                                                     |

   | id               |837ad514-3c05-4357-9a36-0b18adcfb354                 |

   | ip_version       | 4                                                   |

   |name             |                                                     |

   |network_id       |7a7acad8-cabf-49f8-804f-ce6871d9cd63                 |

   |tenant_id        | 8c0104041b034df3a79c17a9517dd3f9                     |

  +------------------+------------------------------------------------------+

* 将net_external与router_admin路由器关联:

   # quantum router-gateway-set router_admin net_external

   Setgateway for router router_admin

* 创建floating ip:

   # quantum floatingip-create net_external

   Created anew floatingip:

  +---------------------+--------------------------------------+

   |Field               | Value                                |

  +---------------------+--------------------------------------+

   |fixed_ip_address    |                                      |

   |floating_ip_address | 192.168.100.3                        |

   |floating_network_id | 7a7acad8-cabf-49f8-804f-ce6871d9cd63 |

   | id                  |15bb69fa-972d-4e86-91fc-250dc1b20fe2 |

   |port_id             |                                      |

   |router_id           |                                      |

   |tenant_id           | 8c0104041b034df3a79c17a9517dd3f9     |

  +---------------------+--------------------------------------+

   # quantum floatingip-create net_external

   Created anew floatingip:

  +---------------------+--------------------------------------+

   |Field               | Value                                |

  +---------------------+--------------------------------------+

   |fixed_ip_address    |                                      |

   |floating_ip_address | 192.168.100.4                        |

   |floating_network_id | 7a7acad8-cabf-49f8-804f-ce6871d9cd63 |

   | id                  |561e3530-d543-427f-986a-aaff64cb1a87 |

   |port_id             |                                      |

   |router_id           |                                      |

   |tenant_id           |8c0104041b034df3a79c17a9517dd3f9     |

  +---------------------+--------------------------------------+



2.quantum命令行删除网络

root@ozg:~# quantum net-list

+--------------------------------------+--------------+-------------------------------------------------------+

| id                                   | name         | subnets                                              |

+--------------------------------------+--------------+-------------------------------------------------------+

| 0cbdf13c-f3c8-48cf-9ae6-fb90fa55a59a | net_01_admin |993397d7-64e4-420f-b357-ffe1c5e93233 10.0.3.0/24      |

| 2b1d11c9-e625-424e-aaa5-f8f6f8fd210d | net_admin    | 949d811d-2543-40c9-a697-6c5d1e9380b710.0.6.0/24      |

| 9726a3ce-7aae-486c-af7a-c36e4d34eb2a | net_ozg      | 237babd9-a95e-4d88-8d2b-0d6a3171784a10.0.2.0/24      |

| dd5d297d-be13-4dfe-aa24-5f1256ef2f9f | net_external |8677e06e-9d37-4bdd-8cc2-44ea9204d6f8 192.168.100.0/24 |

+--------------------------------------+--------------+-------------------------------------------------------+

root@ozg:~# quantum net-delete2b1d11c9-e625-424e-aaa5-f8f6f8fd210d

Unable to complete operation on network2b1d11c9-e625-424e-aaa5-f8f6f8fd210d. There are one or more ports still in useon the network.

root@ozg:~# quantum port-list

+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+

| id                                   | name |mac_address       | fixed_ips                                                                            |

+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+

| 29539162-d82d-4119-954b-c2699b87e3d7 |      | fa:16:3e:f7:80:8b |{"subnet_id": "993397d7-64e4-420f-b357-ffe1c5e93233","ip_address": "10.0.3.6"}      |

| 345f4e71-75b1-4633-aee5-571a3e2b163f |      | fa:16:3e:b4:e4:f6 |{"subnet_id": "993397d7-64e4-420f-b357-ffe1c5e93233","ip_address": "10.0.3.5"}      |

| 38ead750-fd9a-402e-a223-91567e1f8c26 |      | fa:16:3e:8c:e6:cc |{"subnet_id": "237babd9-a95e-4d88-8d2b-0d6a3171784a","ip_address": "10.0.2.3"}      |

| 4c5d9138-784d-48d0-a98a-eeed57af57e7 |      | fa:16:3e:74:b2:2a |{"subnet_id": "949d811d-2543-40c9-a697-6c5d1e9380b7","ip_address": "10.0.6.1"}      |

| 67175139-4e28-4d23-9f8a-f67796661cea |      | fa:16:3e:44:04:d2 |{"subnet_id": "237babd9-a95e-4d88-8d2b-0d6a3171784a","ip_address": "10.0.2.2"}      |

| 672f5ca8-f21c-4026-9267-ca5a80957b4b |      | fa:16:3e:eb:97:7d |{"subnet_id": "8677e06e-9d37-4bdd-8cc2-44ea9204d6f8","ip_address": "192.168.100.3"} |

| 68de6a2c-2c49-4a9a-b6b2-507a53696c2d |      | fa:16:3e:56:57:57 |{"subnet_id": "8677e06e-9d37-4bdd-8cc2-44ea9204d6f8","ip_address": "192.168.100.4"} |

| 7a6b4637-5401-4920-b75c-edc2b9b5ea32 |      | fa:16:3e:a8:20:3b |{"subnet_id": "993397d7-64e4-420f-b357-ffe1c5e93233","ip_address": "10.0.3.4"}      |

| 7cab092f-f82b-439a-8106-caba93272e00 |      | fa:16:3e:73:b6:89 |{"subnet_id": "993397d7-64e4-420f-b357-ffe1c5e93233","ip_address": "10.0.3.2"}      |

| 7e51a6a9-1ede-4bd3-b9f4-1a11a42416c5 |      | fa:16:3e:77:80:44 |{"subnet_id": "8677e06e-9d37-4bdd-8cc2-44ea9204d6f8","ip_address": "192.168.100.2"} |

| 823bca46-e66d-4ff6-8502-1fa1650135f2 |      | fa:16:3e:54:95:a4 |{"subnet_id": "993397d7-64e4-420f-b357-ffe1c5e93233","ip_address": "10.0.3.3"}      |

| 8244b7b6-d30d-45d6-a86e-39368e885bea |      | fa:16:3e:5b:3e:05 |{"subnet_id": "8677e06e-9d37-4bdd-8cc2-44ea9204d6f8","ip_address": "192.168.100.6"} |

| 9591895b-1db0-4753-baaa-27859e25dc23 |      | fa:16:3e:bd:1e:4c |{"subnet_id": "993397d7-64e4-420f-b357-ffe1c5e93233","ip_address": "10.0.3.1"}      |

| a094c888-fbb7-44a1-a65e-f94f5c445f32 |      | fa:16:3e:e6:cd:e7 |{"subnet_id": "237babd9-a95e-4d88-8d2b-0d6a3171784a","ip_address": "10.0.2.1"}      |

| d07a238b-8d03-4c60-81ac-7fceab734d52 |      | fa:16:3e:3e:43:52 |{"subnet_id": "8677e06e-9d37-4bdd-8cc2-44ea9204d6f8","ip_address": "192.168.100.5"} |

+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+

root@ozg:~# quantum port-delete4c5d9138-784d-48d0-a98a-eeed57af57e7

Port 4c5d9138-784d-48d0-a98a-eeed57af57e7 has ownernetwork:router_interface and therefore cannot be deleted directly via the portAPI.

root@ozg:~# quantum router-list

+--------------------------------------+----------------+--------------------------------------------------------+

| id                                   | name           | external_gateway_info                                  |

+--------------------------------------+----------------+--------------------------------------------------------+

| 1b57e77f-194f-4bee-98d3-c4f953ec8191 | router_ozg_com| {"network_id": "dd5d297d-be13-4dfe-aa24-5f1256ef2f9f"} |

| 2175e4dd-6c94-4223-b68c-c5e5b14eed8e |router_admin   | {"network_id":"dd5d297d-be13-4dfe-aa24-5f1256ef2f9f"} |

+--------------------------------------+----------------+--------------------------------------------------------+

root@ozg:~# quantum router-interface-delete2175e4dd-6c94-4223-b68c-c5e5b14eed8e 949d811d-2543-40c9-a697-6c5d1e9380b7(subnet_id)

Removed interface from router2175e4dd-6c94-4223-b68c-c5e5b14eed8e

root@ozg:~# quantum net-delete2b1d11c9-e625-424e-aaa5-f8f6f8fd210d

Deleted network: 2b1d11c9-e625-424e-aaa5-f8f6f8fd210d