0

I am facing an issue with yaml dump.

My Input :

{"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"}}

Here block_device_mapping is a list.

yaml.dump(test,default_flow_style=False) is giving me the following output :

  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

Desired Output:

  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
Sasikiran Vaddi
  • 2,199
  • 4
  • 23
  • 29
  • What version of the yaml lib are you using? My 3.10 version outputs the desired output you've shown using Python 2. – VooDooNOFX Oct 25 '14 at 02:47
  • # dpkg -l | grep yaml ii libyaml-0-2 0.1.4-2ubuntu0.12.04.3 ii python-yaml 3.10-2 Python Version is 2.7.3 – Sasikiran Vaddi Oct 27 '14 at 11:54
  • Interesting. I'm using the same packages as you (except i'm at `python-yaml 3.10` and not `3.10-2`), and getting your desired output. I recommend setting up a virtualenv, and loading the yaml lib from pip to ensure it's not some ubuntu packaging artifact. – VooDooNOFX Oct 27 '14 at 22:03
  • I also get the desired output with pyyaml 3.11, in both Python 2.7.8 and Python 3.4.2. Maybe re-try this with 3.11 just to be sure? – marshall.ward Nov 03 '14 at 04:48

0 Answers0