Backlog #3286
RUBY OCA to_hash returns inconsistant datatypes
Status: | Pending | Start date: | 10/31/2014 | |
---|---|---|---|---|
Priority: | High | Due date: | ||
Assignee: | - | % Done: | 0% | |
Category: | Client API & Library | |||
Target version: | - |
Description
When using the "to_hash" function in the ruby OCA Library it will can different datatypes which will require addtional coding to handle. If a VM has multiple disks for nics it will make an Array, if not it just creates a string. Providing a common and predictable datatype is the goal.
Below is a patch which will always return an Array datatype for NIC and DISK attributes when using the to_hash method.
--- src/oca/ruby/opennebula/xml_element.rb.orig 2014-10-31 16:24:41.614656358 -0400
+++ src/oca/ruby/opennebula/xml_element.rb 2014-10-31 16:29:27.774651454 -0400@ -375,6 +375,7
@
end
key = element.name
+ forcetoarray=["NIC", "DISK"]
if hash.has_key?(key)
if hash[key].instance_of?(Array)
hash[key] << r
@ -382,7 +383,11
@
hash[key] = [hash[key], r]
end
else
- hash[key] = r
+ if forcearray.include?(key)
+ hash[key] = [r]
+ else
+ hash[key] = r
+ end
end
hash
History
#1 Updated by Ruben S. Montero over 6 years ago
- Target version set to Release 4.12
#2 Updated by Ruben S. Montero over 6 years ago
This was somehow intended because of compatibility issues and probably some requirements from the Sunstone app. We'll take a look at it. Thanks for the path :)
#3 Updated by Ruben S. Montero over 6 years ago
- Tracker changed from Bug to Backlog
- Priority changed from Normal to High
- Target version deleted (
Release 4.12)
We have revisited this issue, and:
- This is something we really want to do
- We are afraid of breaking third-party apps
- We prefer to keep the API under control and not add redundant API calls
We are moving these to the backlog and address this for 5.0, where we'll have more room to consider API updates.
Thanks again for your feedback