Sha256: 448ba7504e1069b987582904616a4d33ba6abf5fe163a329508388f78741c812

Contents?: true

Size: 946 Bytes

Versions: 11

Compression:

Stored size: 946 Bytes

Contents

require 'nokogiri'
require 'erb'
require 'ostruct'
require 'securerandom'

module Fog
  module Libvirt
    module Util
      def xml_element(xml, path, attribute=nil)
        xml = Nokogiri::XML(xml)
        attribute.nil? ? (xml/path).first.text : (xml/path).first[attribute.to_sym]
      end

      def xml_elements(xml, path, attribute=nil)
         xml = Nokogiri::XML(xml)
         attribute.nil? ? (xml/path).map : (xml/path).map{|element| element[attribute.to_sym]}
      end

      def to_xml template_name = nil
        # figure out our ERB template filename
        erb = template_name || self.class.to_s.split("::").last.downcase
        path     = File.join(File.dirname(__FILE__), "..", "templates", "#{erb}.xml.erb")
        template = File.read(path)
        ERB.new(template, nil, '-').result(binding)
      end

      def randomized_name
        "fog-#{(SecureRandom.random_number*10E14).to_i.round}"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
fog-libvirt-0.12.2 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.12.1 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.12.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.11.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.10.1 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.10.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-csem-0.9.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.9.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.8.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.7.0 lib/fog/libvirt/models/compute/util/util.rb
fog-libvirt-0.6.0 lib/fog/libvirt/models/compute/util/util.rb