下面是从YAML文件创建的列表。我想将每个memserver的以下内容与列表中的其他merserves进行比较:
代码应该是通用的,也就是说,它应该适用于任意数量的服务器。
provider: sockets
delayed_free_threads: 0
ATL_threads: 0
ATL_queue_size: 1000
ATL_data_size: 1024
Memservers:
0:
memory_type: volatile
fam_path: /dev/shm/vol_path
rpc_interface: fam5:8793
libfabric_port: 7500
if_device: eth0
1:
memory_type: volatile
fam_path: /dev/shm/vol_path
rpc_interface: fam4:8793
libfabric_port: 7500
if_device: eth1
2:
memory_type: volatile
fam_path: /dev/shm/vol_path
rpc_interface: fam3:8793
libfabric_port: 7500
if_device: eth1发布于 2022-06-12 08:59:49
对于每个需求,您只需将值(不应重复)映射到您在其中找到的计算机编号。在刚刚完成的第一项要求中:
from pathlib import Path
import ruamel.yaml
host_port = {}
file_in = Path('fam_memoryserver_config.yaml')
yaml = ruamel.yaml.YAML(typ='safe') # faster than using yaml.safe_load()
data = yaml.load(file_in)
for machine_nr, config in data.items():
host_port.setdefault(config['rpc_interface'], set()).add(machine_nr)
# now check if host_port has any values that have more than one machine_nr
for hp, machine_nrs in host_port.items():
if len(machine_nrs) == 1:
continue
print(f'found {hp} in machines: {", ".join([str(x) for x in machine_nrs])}')这意味着:
found fam3:8793 in machines: 1, 2你应该弄清楚你的术语,或者至少在你的问题中定义这些术语。通用术语将帮助您更容易地找到答案(在这里,在这里,或谷歌)。
您没有任何列表,您可以在YAML文档的根级进行映射,并对每个键的值进行映射。嵌套在dict中的dicts负载。没有任何地方的列表。
上面还假设键rpc_interfaces的值就是您所称的ip:port,但是fam5:8793中的:之前的部分看起来不像IPv4或IPv6地址。看上去更像是个主机名。
您还提到了所有文件之间的检查,但是只有两个文件: YAML输入和源代码。而比较这两者没有多大意义。
https://stackoverflow.com/questions/72583858
复制相似问题