diff --git a/lib/fog/bin/libvirt.rb b/lib/fog/bin/libvirt.rb index b42ae67d9..6e64b9c46 100644 --- a/lib/fog/bin/libvirt.rb +++ b/lib/fog/bin/libvirt.rb @@ -24,7 +24,14 @@ module Libvirt # deviates from other bin stuff to accomodate gem end def available? - availability = !Gem.source_index.find_name('ruby-libvirt').empty? + begin + availability=true unless Gem::Specification::find_by_name("ruby-libvirt").nil? + rescue Gem::LoadError + availability=false + rescue + availability_gem=Gem.available?("ruby-libvirt") + end + if availability for service in services for collection in self.class_for(service).collections diff --git a/lib/fog/compute/libvirt.rb b/lib/fog/compute/libvirt.rb index d059d9dcb..698ebc92a 100644 --- a/lib/fog/compute/libvirt.rb +++ b/lib/fog/compute/libvirt.rb @@ -17,6 +17,8 @@ module Fog collection :volumes model :pool collection :pools + model :node + collection :nodes class Mock diff --git a/lib/fog/compute/models/libvirt/node.rb b/lib/fog/compute/models/libvirt/node.rb new file mode 100644 index 000000000..d4d77d534 --- /dev/null +++ b/lib/fog/compute/models/libvirt/node.rb @@ -0,0 +1,45 @@ +require 'fog/core/model' + +module Fog + module Compute + class Libvirt + + class Node < Fog::Model + + identity :uri + + attribute :model + attribute :memory + attribute :cpus + attribute :mhz + attribute :nodes + attribute :sockets + attribute :cores + attribute :threads + + attribute :type + attribute :version + attribute :uri + attribute :node_free_memory + attribute :max_vcpus + + private + + def raw + @raw + end + + def raw=(new_raw) + @raw = new_raw + + raw_attributes = new_raw + + merge_attributes(raw_attributes) + end + + end + + end + end + +end diff --git a/lib/fog/compute/models/libvirt/nodes.rb b/lib/fog/compute/models/libvirt/nodes.rb new file mode 100644 index 000000000..38d571b14 --- /dev/null +++ b/lib/fog/compute/models/libvirt/nodes.rb @@ -0,0 +1,40 @@ +require 'fog/core/collection' +require 'fog/compute/models/libvirt/node' + +module Fog + module Compute + class Libvirt + + class Nodes < Fog::Collection + + model Fog::Compute::Libvirt::Node + + def all(filter=nil) + data=[] + node_info=Hash.new + [:model, :memory, :cpus, :mhz, :nodes, :sockets, :cores, :threads].each do |param| + begin + node_info[param]=connection.node_get_info.send(param) + rescue ::Libvirt::RetrieveError + node_info[param]=nil + end + end + [:type, :version, :node_free_memory, :max_vcpus].each do |param| + begin + node_info[param] = connection.send(param) + rescue ::Libvirt::RetrieveError + node_info[param]=nil + end + end + node_info[:uri]=connection.connection.uri + data << { :raw => node_info } + require 'pp' + pp node_info + load(data) + end + + + end #class + end #Class + end #module +end #Module diff --git a/lib/fog/compute/models/libvirt/server.rb b/lib/fog/compute/models/libvirt/server.rb index 85e2c9844..1ee0d9963 100644 --- a/lib/fog/compute/models/libvirt/server.rb +++ b/lib/fog/compute/models/libvirt/server.rb @@ -255,7 +255,7 @@ module Fog when 0 then "nostate" when 1 then "running" when 2 then "paused" - when 3 then "shuttingdown" + when 3 then "shutting-down" when 4 then "shutoff" when 5 then "crashed" end