文章目录
本文章由公号【开发小鸽】发布!欢迎关注!!!
老规矩–妹妹镇楼:
![](https://i-blog.csdnimg.cn/blog_migrate/eac8cddaf63e8708f2618fc814be45dd.jpeg)
1. neutron网络情况查看
(1) 虚拟网桥与虚拟网卡
如上所示,Centos节点上的网卡eth0,创建一个虚拟网桥br0,要创建两个虚拟机,且让每个虚拟机和当前的节点之间能够通信,则为每个虚拟机创建一个虚拟网卡连接到虚拟网桥br0上。
(2) 查看当前节点的网卡和网桥情况
查看网卡情况,可以看到有当前节点的物理网卡ens33,虚拟网桥brq,本地lo,:
[root@controller ~]# ifconfig
brq9d470a6f-3b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.112.146 netmask 255.255.255.0 broadcast 192.168.112.255
inet6 fe80::dcc4:eff:feb9:1b57 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:95:a4:6a txqueuelen 1000 (Ethernet)
RX packets 10434 bytes 2970470 (2.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7774 bytes 2290154 (2.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.112.146 netmask 255.255.255.0 broadcast 192.168.112.255
inet6 fe80::20c:29ff:fe95:a46a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:95:a4:6a txqueuelen 1000 (Ethernet)
RX packets 17249 bytes 7462967 (7.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9717 bytes 4165068 (3.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 61509 bytes 21583175 (20.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 61509 bytes 21583175 (20.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tap3c7aba5e-5c: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 0a:c0:9a:04:fc:b9 txqueuelen 1000 (Ethernet)
RX packets 5 bytes 446 (446.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2083 bytes 200612 (195.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7a:d3:fe txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
查看虚拟网桥连接情况,可以看到虚拟网桥brq上只有一个ens33物理网卡以及一个tap设备:
[root@controller ~]# brctl show
bridge name bridge id STP enabled interfaces
brq9d470a6f-3b 8000.000c2995a46a no ens33
tap3c7aba5e-5c
virbr0 8000.5254007ad3fe yes virbr0-nic
(3) 创建两个虚拟机查看网络情况
启动两个虚拟机,在Compute节点查看网桥情况:
[root@computer ~]# brctl show
bridge name bridge id STP enabled interfaces
brq9d470a6f-3b 8000.000c2987e697 no ens33
tap1af5545c-d1
tape48d13df-31
可以看到,在虚拟网桥brq上连接了三个接口,一个是物理网卡ens33,另外两个就是虚拟机的网卡。因此可以推断出Compute节点和创建的两个虚拟机在同一个网桥下是可以通信的。
连接到其中一个虚拟机192.168.112.214,测试与另一个虚拟机、Compute节点、Controller节点的连通性,可以看到都是可以连通的:
可是我们从本地的Win机上向某一个cirros虚拟机通信时却发现ping不通,这是为啥呢?我们的Controller节点和Compute节点都是通过Vmware 创建的,使用的网络是NAT网络,NAT网络从外部是无法向内部访问的。
(4)virbr0的理解
virbr0是KVM默认创建的一个Bridge,它的作用是为连接其上的虚拟网卡提供NAT访问外网的功能,virbr0默认分配的IP是192.168.122.1,并为连接其上的其他虚拟网卡提供DHCP服务。也就是说使用NAT的虚拟机可以访问外网,与外网通信的虚拟机的IP地址被转换为了宿主机的IP地址,但是外网无法直接访问虚拟机
2.neutron网络服务的API测试
(1) 查看所有network信息
填写如下的request参数:
得到如下的response,主要包括status,子网subnets,项目id,network名称:
{
"networks": [
{
"provider:physical_network": "provider",(实现此网络/网段的物理网络)
"ipv6_address_scope": null,
"revision_number": 2,
"port_security_enabled": true,(网络的端口安全状态)
"mtu": 1500,(用于解决碎片的最大传输单元 (MTU) 值)
"id": "9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"router:external": false,
"availability_zone_hints": [],(可用空间的候选)
"availability_zones": [
"nova"
],
"ipv4_address_scope": null,
"shared": true,(共享)
"project_id": "a7d812868cb74f1a978035530f55f1d0",
"status": "ACTIVE",
"subnets": [
"6702625f-2d76-4074-8c7c-6a87a6b82525"(子网的id)
],
"description": "",
"tags": [],
"updated_at": "2021-09-08T17:27:57Z",
"provider:segmentation_id": null,(物理网络上隔离网段的ID。该network_type属性定义了细分模型。例如,如果network_type值为 vlan,则此 ID 为 vlan 标识符。如果network_type值为 gre,则此 ID 为 gre 键。)
"name": "WAN",
"admin_state_up": true,(网络的管理状态,即启动 ( true) 或关闭 ( false))
"tenant_id": "a7d812868cb74f1a978035530f55f1d0",
"created_at": "2021-09-08T16:39:27Z",
"provider:network_type": "flat"(此网络映射到的物理网络类型。例如,flat,vlan,vxlan,或gre。有效值取决于网络后端。)
}
]
}
(2)查看单个network信息
设置如下的request参数:
得到如下的response:
{
"network": {
"status": "ACTIVE",
"router:external": false,
"availability_zone_hints": [],
"availability_zones": [
"nova"
],
"description": "",
"subnets": [
"6702625f-2d76-4074-8c7c-6a87a6b82525"
],
"shared": true,
"tenant_id": "a7d812868cb74f1a978035530f55f1d0",
"created_at": "2021-09-08T16:39:27Z",
"tags": [],
"ipv6_address_scope": null,
"mtu": 1500,
"updated_at": "2021-09-08T17:27:57Z",
"admin_state_up": true,
"revision_number": 2,
"ipv4_address_scope": null,
"port_security_enabled": true,
"project_id": "a7d812868cb74f1a978035530f55f1d0",
"id": "9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"name": "WAN"
}
}
(3)创建单个网络
(4) 获取所有的port端口
port可以看做是虚拟交换机上的一个端口,port上定义了MAC地址和IP地址,当实例的虚拟网卡VIF绑定到port时,port会将MAC和IP分配给VIF中,相当于一个虚拟网卡对应一个port(MAC和IP),一个实例可以配置多个VIF虚拟网卡。
传入参数:
得到响应是所有的port端口,端口的IP地址,MAC地址,子网id,网络id,可以看到所有的实例分配的port都被显示出来了:
{
"ports": [
{
"allowed_address_pairs": [],
"extra_dhcp_opts": [],
"updated_at": "2021-10-10T01:21:01Z",
"device_owner": "compute:nova",
"revision_number": 7,
"port_security_enabled": true,
"binding:profile": {},
"fixed_ips": [
{
"subnet_id": "6702625f-2d76-4074-8c7c-6a87a6b82525",
"ip_address": "192.168.112.214"
}
],
"id": "1af5545c-d178-48ca-82c9-540bd4e8bbd4",
"security_groups": [
"f71074ff-7cbe-45d9-abba-e62ead7daae7"
],
"binding:vif_details": {
"connectivity": "l2",
"port_filter": true
},
"binding:vif_type": "bridge",
"mac_address": "fa:16:3e:5e:b3:58",
"project_id": "a7d812868cb74f1a978035530f55f1d0",
"status": "ACTIVE",
"binding:host_id": "computer",
"description": "",
"tags": [],
"device_id": "739bd9ea-4b50-46ca-98ba-e0ae01d86119",
"name": "",
"admin_state_up": true,
"network_id": "9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"tenant_id": "a7d812868cb74f1a978035530f55f1d0",
"created_at": "2021-10-09T15:59:19Z",
"binding:vnic_type": "normal"
},
{
"allowed_address_pairs": [],
"extra_dhcp_opts": [],
"updated_at": "2021-10-10T11:12:17Z",
"device_owner": "network:dhcp",
"revision_number": 50,
"port_security_enabled": false,
"binding:profile": {},
"fixed_ips": [
{
"subnet_id": "6702625f-2d76-4074-8c7c-6a87a6b82525",
"ip_address": "192.168.112.200"
}
],
"id": "3c7aba5e-5ce8-49ea-9ad9-5baaf450facf",
"security_groups": [],
"binding:vif_details": {
"connectivity": "l2",
"port_filter": true
},
"binding:vif_type": "bridge",
"mac_address": "fa:16:3e:90:74:f8",
"project_id": "a7d812868cb74f1a978035530f55f1d0",
"status": "ACTIVE",
"binding:host_id": "controller",
"description": "",
"tags": [],
"device_id": "dhcpd3377d3c-a0d1-5d71-9947-f17125c357bb-9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"name": "",
"admin_state_up": true,
"network_id": "9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"tenant_id": "a7d812868cb74f1a978035530f55f1d0",
"created_at": "2021-09-08T17:27:58Z",
"binding:vnic_type": "normal"
},
{
"allowed_address_pairs": [],
"extra_dhcp_opts": [],
"updated_at": "2021-10-10T01:21:26Z",
"device_owner": "compute:nova",
"revision_number": 7,
"port_security_enabled": true,
"binding:profile": {},
"fixed_ips": [
{
"subnet_id": "6702625f-2d76-4074-8c7c-6a87a6b82525",
"ip_address": "192.168.112.201"
}
],
"id": "e48d13df-31ed-4ee0-bd53-46b996d4c15a",
"security_groups": [
"f71074ff-7cbe-45d9-abba-e62ead7daae7"
],
"binding:vif_details": {
"connectivity": "l2",
"port_filter": true
},
"binding:vif_type": "bridge",
"mac_address": "fa:16:3e:52:90:21",
"project_id": "a7d812868cb74f1a978035530f55f1d0",
"status": "ACTIVE",
"binding:host_id": "computer",
"description": "",
"tags": [],
"device_id": "09e84068-de17-4bb4-9bd5-6104357deb00",
"name": "",
"admin_state_up": true,
"network_id": "9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"tenant_id": "a7d812868cb74f1a978035530f55f1d0",
"created_at": "2021-10-09T15:59:07Z",
"binding:vnic_type": "normal"
}
]
}
(5) 获取所有的subnet子网
传入参数:
得到响应,子网的所属网络id,租户id,子网的分配IP范围,网关IP,子网的cidr:
{
"subnets": [
{
"service_types": [],
"description": "",
"enable_dhcp": true,
"tags": [],
"network_id": "9d470a6f-3b69-4105-b0eb-f6ef70a9dec3",
"tenant_id": "a7d812868cb74f1a978035530f55f1d0",
"created_at": "2021-09-08T17:27:57Z",
"dns_nameservers": [
"223.5.5.5"
],
"updated_at": "2021-09-08T17:27:57Z",
"ipv6_ra_mode": null,
"allocation_pools": [
{
"start": "192.168.112.200",
"end": "192.168.112.230"
}
],
"gateway_ip": "192.168.112.254",
"revision_number": 0,
"ipv6_address_mode": null,
"ip_version": 4,
"host_routes": [],
"cidr": "192.168.112.0/24",
"project_id": "a7d812868cb74f1a978035530f55f1d0",
"id": "6702625f-2d76-4074-8c7c-6a87a6b82525",
"subnetpool_id": null,
"name": "subnet-wan"
}
]
}