diff --git a/lib/puppet/provider/libvirt_network/virsh.rb b/lib/puppet/provider/libvirt_network/virsh.rb index 41a298c..7988f72 100644 --- a/lib/puppet/provider/libvirt_network/virsh.rb +++ b/lib/puppet/provider/libvirt_network/virsh.rb @@ -96,7 +96,16 @@ def content formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true output = ''.dup - formatter.write(recursive_sort(xml.root), output) + + xml = recursive_sort(xml.root) + sorted_portgroups = xml.root.get_elements('//portgroup').sort_by { |obj| obj.attributes['name'] } + + REXML::XPath.match(xml, '//portgroup').each(&:remove) + sorted_portgroups.each do |pg| + xml.root.add_element pg + end + + formatter.write(xml.root, output) output end diff --git a/lib/puppet/type/libvirt_network.rb b/lib/puppet/type/libvirt_network.rb index a8f123c..0492e7c 100644 --- a/lib/puppet/type/libvirt_network.rb +++ b/lib/puppet/type/libvirt_network.rb @@ -46,6 +46,22 @@ raise ArgumentError, 'content needs to be a XML string' unless value.is_a?(String) end + def change_to_s(current, desire) + if @resource[:show_diff] + current_exp = Tempfile.new("current", "/tmp").open + current_exp.write(current.to_s) + current_exp.close + current_path = current_exp.path + desire_exp = Tempfile.new("desire", "/tmp").open + desire_exp.write(desire.to_s) + desire_exp.close + desire_path = desire_exp.path + system "diff -u #{current_path} #{desire_path}" + else + '{md5}' + Digest::MD5.hexdigest(current.to_s) + " to: " + '{md5}' + Digest::MD5.hexdigest(desire.to_s) + end + end + def should_to_s(value) if @resource[:show_diff] ":\n" + value + "\n"