Module: Libvirt

Defined in:
lib/fog/bin/libvirt.rb

Overview

deviates from other bin stuff to accomodate gem

Class Method Summary collapse

Class Method Details

.[](service) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/bin/libvirt.rb', line 12

def [](service)
  @@connections ||= Hash.new do |hash, key|
    hash[key] = case key
    when :compute
      Fog::Logger.warning("Libvirt[:compute] is not recommended, use Compute[:libvirt] for portability")
      Fog::Compute.new(:provider => 'Libvirt')
    else
      raise ArgumentError, "Unrecognized service: #{key.inspect}"
    end
  end
  @@connections[service]
end

.available?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/bin/libvirt.rb', line 25

def available?
  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
        unless self.respond_to?(collection)
          self.class_eval <<-EOS, __FILE__, __LINE__
            def self.#{collection}
              self[:#{service}].#{collection}
            end
          EOS
        end
      end
    end
  end
  availability
end

.class_for(key) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/fog/bin/libvirt.rb', line 3

def class_for(key)
  case key
  when :compute
    Fog::Compute::Libvirt
  else
    raise ArgumentError, "Unrecognized service: #{key}"
  end
end

.collectionsObject



50
51
52
# File 'lib/fog/bin/libvirt.rb', line 50

def collections
  services.map {|service| self[service].collections}.flatten.sort_by {|service| service.to_s}
end

.servicesObject



54
55
56
# File 'lib/fog/bin/libvirt.rb', line 54

def services
  Fog::Libvirt.services
end