module Fog::Libvirt::Compute::Shared

Private Instance Methods

boot_order(xml) click to toggle source
# File lib/fog/libvirt/requests/compute/list_domains.rb, line 47
def boot_order xml
  xml_elements(xml, "domain/os/boot", "dev")
end
domain_display(xml) click to toggle source
# File lib/fog/libvirt/requests/compute/list_domains.rb, line 33
def domain_display xml
  attrs = {}
  [:type, :port, :password, :listen].each do |element|
    attrs[element] = xml_element(xml, "domain/devices/graphics",element.to_s) rescue nil
  end
  attrs.reject{|k,v| v.nil? or v == ""}
end
domain_interfaces(xml) click to toggle source
# File lib/fog/libvirt/requests/compute/list_domains.rb, line 51
def domain_interfaces xml
  ifs = xml_elements(xml, "domain/devices/interface")
  ifs.map { |i|
    nics.new({
      :type    => i['type'],
      :mac     => (i/'mac').first[:address],
      :network => ((i/'source').first[:network] rescue nil),
      :bridge  => ((i/'source').first[:bridge] rescue nil),
      :model   => ((i/'model').first[:type] rescue nil),
    }.reject{|k,v| v.nil?})
  }
end
domain_to_attributes(dom) click to toggle source
# File lib/fog/libvirt/requests/compute/list_domains.rb, line 64
def domain_to_attributes(dom)
  states= %w(nostate running blocked paused shutting-down shutoff crashed pmsuspended)

  begin
    {
      :id              => dom.uuid,
      :uuid            => dom.uuid,
      :name            => dom.name,
      :max_memory_size => dom.info.max_mem,
      :cputime         => dom.info.cpu_time,
      :memory_size     => dom.info.memory,
      :cpus            => dom.info.nr_virt_cpu,
      :autostart       => dom.autostart?,
      :os_type         => dom.os_type,
      :active          => dom.active?,
      :display         => domain_display(dom.xml_desc),
      :boot_order      => boot_order(dom.xml_desc),
      :nics            => domain_interfaces(dom.xml_desc),
      :volumes_path    => domain_volumes(dom.xml_desc),
      :state           => states[dom.info.state]
    }
  rescue ::Libvirt::RetrieveError, ::Libvirt::Error
    # Catch libvirt exceptions to avoid race conditions involving
    # concurrent libvirt operations (like from another process)
    return nil
  end
end
domain_volumes(xml) click to toggle source
# File lib/fog/libvirt/requests/compute/list_domains.rb, line 41
def domain_volumes xml
  xml_elements(xml, "domain/devices/disk/source").map do |element|
    element[:file] || element[:dev] || element[:name]
  end
end
pool_to_attributes(pool, include_inactive = nil) click to toggle source
# File lib/fog/libvirt/requests/compute/list_pools.rb, line 7
def pool_to_attributes(pool, include_inactive = nil)
  return nil unless pool.active? || include_inactive

  states=[:inactive, :building, :running, :degrated, :inaccessible]
  {
    :uuid           => pool.uuid,
    :persistent     => pool.persistent?,
    :autostart      => pool.autostart?,
    :active         => pool.active?,
    :name           => pool.name,
    :allocation     => pool.info.allocation,
    :capacity       => pool.info.capacity,
    :num_of_volumes => pool.active? ? pool.num_of_volumes : nil,
    :state          => states[pool.info.state]
  }
end