我想将字典写入 YAML 文件,这就是我现在正在做的事情
from ruamel.yaml import YAML
Flavor_Details = {'Flavor_Details':{
'type': 'OS::Nova::Flavor',
'properties': {
'name': 'test-flavor',
'extra_specs': {"hw:cpu_policy": 'shared'},
'ram': 4096,
'vcpus': 4,
'disk': 8
}
}}
output_section = {
'server_public_ip':{
'description': 'Floating IP address of server',
'value': { 'get_attr': [ 'server_floating_ip', 'ip' ] }
}
}
resources_dict = {}
resources_dict.update(Flavor_Details)
resources_dict.update(output_section)
yaml = YAML(typ= 'safe')
with open('test.yaml', 'w') as outfile:
yaml.dump(resources_dict,outfile)
这是 YAML 文件中的结果
Flavor_Details:
properties:
disk: 8
extra_specs: {hw:cpu_policy: shared}
name: test-flavor
ram: 4096
vcpus: 4
type: OS::Nova::Flavor
server_public_ip:
description: Floating IP address of server
value:
get_attr: [server__floating_ip, ip]
但我想要这样的结果:
Flavor_Details:
properties:
disk: 8
extra_specs: {"hw:cpu_policy": shared}
name: test-flavor
ram: 4096
vcpus: 4
type: OS::Nova::Flavor
server_public_ip:
description: Floating IP address of server
value: {get_attr: [server__floating_ip, ip]}
我想要"hw:cpu_policy"
作为一个字符串,因为在和之间:
我想成为这样。hw
cpu_policy
value
{get_attr: [server__floating_ip, ip]}
有没有办法得到这样的东西?