Sha256: bcac4db7b6ebf0cab0105805ad0675d41824bf98c7bb9ac6f98b30bf41be56ad

Contents?: true

Size: 954 Bytes

Versions: 80

Compression:

Stored size: 954 Bytes

Contents

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

module Fog
  module Compute
    module LibvirtUtil

      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

80 entries across 80 versions & 13 rubygems

Version Path
fog-1.22.0 lib/fog/libvirt/models/compute/util/util.rb
fog-1.21.0 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/libvirt/models/compute/util/util.rb
fog-1.20.0 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/libvirt/models/compute/util/util.rb
fog-1.19.0 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/libvirt/models/compute/util/util.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/libvirt/models/compute/util/util.rb