Skip to content

Commit

Permalink
F OpenNebula#1750: replace method works for all one objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Semedi committed Feb 16, 2018
1 parent 6945fd7 commit 3b349ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
57 changes: 39 additions & 18 deletions src/oca/ruby/opennebula/pool_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,6 @@ def chmod_octet(xml_method, octet)
other_m, other_a)
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(xpath, opts)
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
end
end

# Calls to the corresponding chmod method to modify
# the object's permission bits
Expand Down Expand Up @@ -253,6 +235,26 @@ def to_str

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
Expand Down Expand Up @@ -283,6 +285,25 @@ def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expres

return hash
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


# Alternative method with better performance for huge number of timestamps.
Expand Down
3 changes: 1 addition & 2 deletions src/oca/ruby/opennebula/virtual_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ def user_template_xml
end

def replace(opts = {})
super("USER_TEMPLATE", opts)
update(user_template_str)
super(opts, "USER_TEMPLATE")
end

# Initiates the instance of the VM on the target host.
Expand Down
1 change: 1 addition & 0 deletions src/oca/ruby/opennebula/xml_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def add_element(xpath, elems)
}
end

# Update the content of the current doc
def set_content(content)
if NOKOGIRI
@xml.content = content
Expand Down

0 comments on commit 3b349ae

Please sign in to comment.