OneGate json output format

Hi,

We are using the same version of OpenNebula (4.1.0.2) in two different environments. When requesting information about the VM or the Service from OneGate the format of the json is different between environments, specially in the USER_TEMPLATE section:

(1)

   "USER_TEMPLATE": [

        [
            "SUNSTONE_CAPACITY_SELECT",
            "YES"
        ],
        [
            "ROLE_NAME",
            "db01"
        ],
        [
            "FROM_APP_NAME",
            "Centos 6x"
        ],
        [
            "SERVICE_ID",
            "4"
        ],
        [
            "FROM_APP",
            "54b3f2d5cf723241e8000002"
        ],
        [
            "SUNSTONE_NETWORK_SELECT",
            "YES"
        ],
        [
            "HYPERVISOR",
            "kvm"
        ]
    ]

(2)
`

"USER_TEMPLATE": {

    "FROM_APP": "54c1682f9376371a1a000003",
    "FROM_APP_NAME": "Centos 6x",
    "HYPERVISOR": "kvm",
    "READY": "YES",
    "ROLE_NAME": "db01",
    "SCHED_REQUIREMENTS": "CLUSTER_ID=\"101\"",
    "SERVICE_ID": "71",
    "SUNSTONE_CAPACITY_SELECT": "YES",
    "SUNSTONE_NETWORK_SELECT": "YES
}

The example in the documentation is similar to the environment (2) : http://docs.opennebula.org/4.10/advanced_administration/application_insight/onegate_usage.html

Seemed to me something related to the version of the json gem . In environment (1) we have ruby 1.8 and json 1.6.3 and in (2) we have ruby 1.9 and json 1.8.2 . As (1) is a production environment we cannot update ruby without testing first the impact, but in (2) we downgrade ruby-json to 1.6.3 but still getting the same format.

Any ideas why this is happening?

Thanks!

Digging a little more in the issue I found out the reason behind the difference in the json between both environemnts. It’s the version of ruby. One has 1.8 and the other has 1.9. Why different versions of Ruby return a different json in OneGate?

As I said before the differences are in the USER_TEMPLATE section, in the OneGate code : /usr/lib/one/onegate/onegate-server.rb , we have this:

        "USER_TEMPLATE" => vm_hash["USER_TEMPLATE"].select {|k,v|

                                !USER_TEMPLATE_INVALID_KEYS.include?(k)

Well, according to different sources:

Hash#select returns an array of arrays in Ruby 1.8.7, but a proper Hash in Ruby 1.9.3.

And when converted to json , the array of arrays wil be [ [a,b] , [c,d], [e,f] …] and the hash will be {a:b, c:d, e:f, …} which are the same patterns in our results.

The solution, apart from upgrade the ruby version,is add Hash in the code where Hash#select is used, Hash is compatible between 1.8 and 1.9

   "USER_TEMPLATE" => Hash[vm_hash["USER_TEMPLATE"].select {|k,v|}
                      !USER_TEMPLATE_INVALID_KEYS.include?(k)
                      }]

Not sure if this could be considered a bug.

Thanks

Hi,

Indeed it is a bug, it should be the same format for both versions. We will fix it for the next release.

Thank you for your feedback