Module: Fog::Compute::LibvirtUtil

Included in:
Fog::Compute::Libvirt::Network, Fog::Compute::Libvirt::Server, Fog::Compute::Libvirt::Shared, Fog::Compute::Libvirt::Volume
Defined in:
lib/fog/libvirt/models/compute/util/uri.rb,
lib/fog/libvirt/models/compute/util/util.rb

Defined Under Namespace

Classes: URI

Instance Method Summary collapse

Instance Method Details

#randomized_nameObject



28
29
30
# File 'lib/fog/libvirt/models/compute/util/util.rb', line 28

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

#to_xml(template_name = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/fog/libvirt/models/compute/util/util.rb', line 20

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

#xml_element(xml, path, attribute = nil) ⇒ Object



10
11
12
13
# File 'lib/fog/libvirt/models/compute/util/util.rb', line 10

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

#xml_elements(xml, path, attribute = nil) ⇒ Object



15
16
17
18
# File 'lib/fog/libvirt/models/compute/util/util.rb', line 15

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