mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
F #1750: added method xmlelement to set content F #1750: replace method works for all one objects
This commit is contained in:
parent
650e4be863
commit
2e46a4043f
@ -234,6 +234,26 @@ module OpenNebula
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
# Replace the xml pointed by xpath using a Hash object
|
||||
# one object will be modified taking hash object pairs
|
||||
#
|
||||
# @param [String] xpath
|
||||
# @param [Hash] options object containing pair key-value
|
||||
#
|
||||
# @returns the new xml representation
|
||||
def replace(opts, xpath = "TEMPLATE")
|
||||
if self[xpath]
|
||||
opts.each do |att, value|
|
||||
xpath_u = xpath+"/#{att}"
|
||||
docs = retrieve_xmlelements(xpath_u)
|
||||
if docs.size == 1
|
||||
docs[0].set_content(value)
|
||||
end
|
||||
end
|
||||
update(template_like_str(xpath))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Processes the monitoring data in XML returned by OpenNebula
|
||||
@ -265,7 +285,6 @@ module OpenNebula
|
||||
return hash
|
||||
end
|
||||
|
||||
|
||||
# Alternative method with better performance for huge number of timestamps.
|
||||
# For reasonable amounts of data, the current method is quicker
|
||||
=begin
|
||||
|
@ -325,6 +325,9 @@ module OpenNebula
|
||||
end
|
||||
end
|
||||
|
||||
def replace(opts = {})
|
||||
super(opts, "USER_TEMPLATE")
|
||||
end
|
||||
|
||||
# Initiates the instance of the VM on the target host.
|
||||
#
|
||||
|
@ -145,6 +145,15 @@ module OpenNebula
|
||||
}
|
||||
end
|
||||
|
||||
# Update the content of the current doc
|
||||
def set_content(content)
|
||||
if NOKOGIRI
|
||||
@xml.content = content
|
||||
else
|
||||
@xml.text = content
|
||||
end
|
||||
end
|
||||
|
||||
# Gets an array of text from elements extracted
|
||||
# using the XPATH expression passed as filter
|
||||
def retrieve_elements(filter)
|
||||
|
Loading…
x
Reference in New Issue
Block a user