python实现:for key, nic in data.items(): if isinstance(nic, dict) and nic.get('nics', {}): for br_info in nic["nics"].values(): if br_info.get('physical_network', {}) and br_info["vswitch_type"] in ["dvs", "ovs"]: if br_info['physical_network']['default']['segmentation_type'] == 'vxlan': vtep_ip = br_info['physical_network']['default']['vtep_ip'],检查vtep_ip是否重复?
时间: 2024-02-14 21:13:09 浏览: 136
可以使用一个列表来存储已经出现过的vtep_ip,然后在循环中检查当前的vtep_ip是否已经存在于列表中。具体实现可以参考下面的代码:
```
vtep_ips = []
for key, nic in data.items():
if isinstance(nic, dict) and nic.get('nics', {}):
for br_info in nic["nics"].values():
if br_info.get('physical_network', {}) and br_info["vswitch_type"] in ["dvs", "ovs"]:
if br_info['physical_network']['default']['segmentation_type'] == 'vxlan':
vtep_ip = br_info['physical_network']['default']['vtep_ip']
if vtep_ip in vtep_ips:
print("重复的vtep_ip: ", vtep_ip)
else:
vtep_ips.append(vtep_ip)
```
这段代码会在循环中依次检查每个vtep_ip是否已经存在于vtep_ips列表中,如果存在则会打印出重复的vtep_ip,否则将该vtep_ip添加到vtep_ips列表中以便后续检查。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![whl](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)