OpenStack命令行添加网卡
添加网卡在控制端创建,也可以在dashboard创建,下面我们在命令添加
查看network,添加ip用到
test@controller:~$ openstack network list +--------------------------------------+--------------+--------------------------------------+ | ID | Name | Subnets | +--------------------------------------+--------------+--------------------------------------+ | 0cbeef7b-9014-43fe-9103-66da4c03f54a | vxlan_172.30 | 39667cc6-503c-4b65-a4e5-17c116763502 | | 993bbc0a-fed2-4186-bb7d-64644c9ad8bf | public | 46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef | +--------------------------------------+--------------+--------------------------------------+
确认子网
test@controller:~$ openstack subnet list
+--------------------------------------+-----------------+--------------------------------------+---------------+
| ID | Name | Network | Subnet |
+--------------------------------------+-----------------+--------------------------------------+---------------+
| 39667cc6-503c-4b65-a4e5-17c116763502 | subnet_172.30.0 | 0cbeef7b-9014-43fe-9103-66da4c03f54a | 172.30.0.0/24 |
| 46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef | subnet_10.0.20 | 993bbc0a-fed2-4186-bb7d-64644c9ad8bf | 10.0.20.0/24 |
+--------------------------------------+-----------------+--------------------------------------+---------------+
查看已有的接口地址,以便检测需要添加的网卡的ip是否会冲突
test@controller:~$ openstack port list
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
| ID | Name | MAC Address | Fixed IP Addresses | Status |
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
| 0405f520-9c86-4e52-a05e-e4966c577505 | | fa:16:3e:a0:d9:3c | ip_address='172.30.0.1', subnet_id='39667cc6-503c-4b65-a4e5-17c116763502' | ACTIVE |
| 21300369-d9b6-4093-a1b3-3e97f57d274b | | fa:16:3e:17:5d:a7 | ip_address='10.0.20.137', subnet_id='46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef' | N/A |
| 3dec888e-6332-4a2f-be1c-7bc5482770fa | | fa:16:3e:dd:43:a7 | ip_address='10.0.20.110', subnet_id='46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef' | ACTIVE |
| 6130bc60-b34b-4392-96ce-1abc0f8ac4c4 | | fa:16:3e:e8:bc:dd | ip_address='10.0.20.130', subnet_id='46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef' | ACTIVE |
| 6371c74a-4055-4850-803e-1968246f69eb | | fa:16:3e:a0:c7:61 | ip_address='10.0.20.134', subnet_id='46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef' | DOWN |
| b89b6a3f-2ee9-4bb4-8fdd-711f94953e2c | | fa:16:3e:17:de:cc | ip_address='172.30.0.16', subnet_id='39667cc6-503c-4b65-a4e5-17c116763502' | ACTIVE |
| cf51f718-fdab-4077-a0bd-3bf8b114645f | | fa:16:3e:0c:46:9a | ip_address='172.30.0.245', subnet_id='39667cc6-503c-4b65-a4e5-17c116763502' | ACTIVE |
| d86cb39e-8463-46c2-baa0-99f14b9a6d55 | | fa:16:3e:9e:7b:31 | ip_address='172.30.0.2', subnet_id='39667cc6-503c-4b65-a4e5-17c116763502' | ACTIVE |
| e6f0f2ec-692c-461a-914f-1ff94a637537 | | fa:16:3e:5e:bc:5d | ip_address='10.0.20.121', subnet_id='46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef' | N/A |
| f5cf7b83-7bb0-4cb9-8fe4-53b80468fc49 | | fa:16:3e:53:12:0b | ip_address='10.0.20.139', subnet_id='46a17ab6-c67d-4be3-b1cb-4efe6aeb4fef' | ACTIVE |
+--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
创建指定ip的接口,注意不要冲突,当然你也可以不需要指定IP,DHCP自己分配
语法: openstack port create name --network networkname --fixed-ip subnet=subname,ip-address=X.X.X.X
注意后面这里的--fixed-ip到结尾是一体的,2个key value 详情查看帮助 openstack port create
test@controller:~$ openstack port create 172.30.0.88 --network vxlan_172.30 --fixed-ip subnet=subnet_172.30.0,ip-address=172.30.0.88
+-------------------------+----------------------------------------------------------------------------+
| Field | Value |
+-------------------------+----------------------------------------------------------------------------+
| admin_state_up | UP |
| allowed_address_pairs | |
| binding_host_id | |
| binding_profile | |
| binding_vif_details | |
| binding_vif_type | unbound |
| binding_vnic_type | normal |
| created_at | 2022-06-26T09:08:57Z |
| data_plane_status | None |
| description | |
| device_id | |
| device_owner | |
| device_profile | None |
| dns_assignment | None |
| dns_domain | None |
| dns_name | None |
| extra_dhcp_opts | |
| fixed_ips | ip_address='172.30.0.88', subnet_id='39667cc6-503c-4b65-a4e5-17c116763502' |
| id | 70223854-45a1-44c7-aeb9-8d7be2328948 |
| ip_allocation | None |
| mac_address | fa:16:3e:a8:0b:90 |
| name | 172.30.0.88 |
| network_id | 0cbeef7b-9014-43fe-9103-66da4c03f54a |
| numa_affinity_policy | None |
| port_security_enabled | True |
| project_id | e34951c632d84b9ba0435d8659da5f54 |
| propagate_uplink_status | None |
| qos_network_policy_id | None |
| qos_policy_id | None |
| resource_request | None |
| revision_number | 1 |
| security_group_ids | e176a0ea-d009-46e8-abbd-2be2ae2d83d7 |
| status | DOWN |
| tags | |
| trunk_details | None |
| updated_at | 2022-06-26T09:08:57Z |
+-------------------------+----------------------------------------------------------------------------+
记一下我们刚刚创建的IP的id,挂载用到
查看虚拟机列表,记下需要挂载的机器的ID,挂载用到
test@controller:~$ nova list
+--------------------------------------+-------+---------+------------+-------------+----------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+-------+---------+------------+-------------+----------------------------------------+
| 91574259-7691-4c95-b1dd-79a6ff5dcf5f | demo1 | SHUTOFF | - | Shutdown | public=10.0.20.134 |
| 73f96db8-7a11-4b91-aa16-b37058f9b0cb | demo3 | ACTIVE | - | Running | vxlan_172.30=172.30.0.245, 10.0.20.121 |
| 5680b384-7449-4a63-a874-9991f01dde4e | demo4 | ACTIVE | - | Running | vxlan_172.30=172.30.0.16 |
| 089361b7-f223-4fd4-b40b-ee1d306d7497 | test | ACTIVE | - | Running | public=10.0.20.139 |
+--------------------------------------+-------+---------+------------+-------------+----------------------------------------+
ip绑定到虚机
语法nova interface-attach --port-id portid serverid
test@controller:~$ nova interface-attach --port-id 70223854-45a1-44c7-aeb9-8d7be2328948 5680b384-7449-4a63-a874-9991f01dde4e
+------------+--------------------------------------+
| Property | Value |
+------------+--------------------------------------+
| ip_address | 172.30.0.88 |
| mac_addr | fa:16:3e:a8:0b:90 |
| net_id | 0cbeef7b-9014-43fe-9103-66da4c03f54a |
| port_id | 70223854-45a1-44c7-aeb9-8d7be2328948 |
| port_state | DOWN |
| tag | - |
+------------+--------------------------------------+
查看,已挂上
test@controller:~$ nova list +--------------------------------------+-------+---------+------------+-------------+----------------------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+-------+---------+------------+-------------+----------------------------------------+ | 91574259-7691-4c95-b1dd-79a6ff5dcf5f | demo1 | SHUTOFF | - | Shutdown | public=10.0.20.134 | | 73f96db8-7a11-4b91-aa16-b37058f9b0cb | demo3 | ACTIVE | - | Running | vxlan_172.30=172.30.0.245, 10.0.20.121 | | 5680b384-7449-4a63-a874-9991f01dde4e | demo4 | ACTIVE | - | Running | vxlan_172.30=172.30.0.16, 172.30.0.88 | | 089361b7-f223-4fd4-b40b-ee1d306d7497 | test | ACTIVE | - | Running | public=10.0.20.139 | +--------------------------------------+-------+---------+------------+-------------+----------------------------------------+
我们拿一个cirros虚机测试看看,发现eth1没有IP
编辑网卡配置信息,自动获取就行了。
重启,然后就发现啦
卸载网卡 nova interface-detach serverid portid
test@controller:~$ nova interface-detach 5680b384-7449-4a63-a874-9991f01dde4e 70223854-45a1-44c7-aeb9-8d7be2328948
删除网卡 openstack port delete portid
test@controller:~$ openstack port delete 70223854-45a1-44c7-aeb9-8d7be2328948