如何以所需的yaml格式获取列表元素

时间:2014-10-22 14:34:04

标签: python yaml openstack-heat

我遇到了yaml dump的问题。

我的输入:

{"Controller_node1_external_port": {"block_device_mapping": [{"device_name": "/dev/vda1", "volume_id": "helloooo", "delete_on_termination": "False"}],"properties": {"fixed_ips": [{"ip_address": "12.0.0.1"}],"network_id": {"get_param": ["ex_net_map_param",{"get_param": "ex_net_param"}]}},"type": "OS::Neutron::Port"}}

这里block_device_mapping是一个列表。

yaml.dump(test,default_flow_style = False)给出了以下输出:

  Controller_node1_external_port: 
    block_device_mapping: 
      - device_name: "/dev/vda1"
      - volume_id: "helloooo"
      - delete_on_termination: "False"
    properties:
      fixed_ips:
      - ip_address: 12.0.0.1
      network_id:
        get_param:
        - ex_net_map_param
        - {get_param: ex_net_param}
    type: OS::Neutron::Port

期望的输出:

  Controller_node1_external_port: 
    block_device_mapping: 
      - device_name: "/dev/vda1"
        volume_id: "helloooo"
        delete_on_termination: "False"
    properties:
      fixed_ips:
      - ip_address: 12.0.0.1
      network_id:
        get_param:
        - ex_net_map_param
        - {get_param: ex_net_param}
    type: OS::Neutron::Port

0 个答案:

没有答案