Class: Fog::Compute::Libvirt::Servers

Inherits:
Fog::Collection show all
Defined in:
lib/fog/libvirt/models/compute/servers.rb

Instance Attribute Summary

Attributes inherited from Fog::Collection

#connection

Instance Method Summary collapse

Methods inherited from Fog::Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#all(filter = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/libvirt/models/compute/servers.rb', line 12

def all(filter=nil)
  data=[]
  filter={} if filter.nil?
  include_defined=filter.has_key?(:defined) ? filter[:defined] : true  
  include_active=filter.has_key?(:active) ? filter[:active] : true  

  unless filter.has_key?(:name) || filter.has_key?(:uuid)
    if include_defined
      connection.raw.list_defined_domains.map do |domain|
        data << { :raw => connection.raw.lookup_domain_by_name(domain) }
      end
    end
    if include_active
      connection.raw.list_domains.each do |domain|
        data << { :raw => connection.raw.lookup_domain_by_id(domain) }
      end
    end
  else
    domain=nil
    begin
      domain=self.get_by_name(filter[:name]) if filter.has_key?(:name)
      domain=self.get_by_uuid(filter[:uuid]) if filter.has_key?(:uuid)

    rescue ::Libvirt::RetrieveError
      return nil
    end
    unless domain.nil?
      data << { :raw => domain }
    end
  end

  load(data)
end

#bootstrap(new_attributes = {}) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/fog/libvirt/models/compute/servers.rb', line 51

def bootstrap(new_attributes = {})
  raise 'Not Implemented'
  # server = create(new_attributes)
  # server.start
  # server.wait_for { ready? }
  # server.setup(:password => server.password)
  # server
end

#get(uuid) ⇒ Object



46
47
48
49
# File 'lib/fog/libvirt/models/compute/servers.rb', line 46

def get(uuid)
  vm = all(:uuid => uuid)
  vm.first if vm
end

#get_by_name(name) ⇒ Object

Retrieve the server by name



70
71
72
73
74
# File 'lib/fog/libvirt/models/compute/servers.rb', line 70

def get_by_name(name)
  server=connection.raw.lookup_domain_by_name(name)
  return server
  #          new(:raw => machine)
end

#get_by_uuid(uuid) ⇒ Object

Retrieve the server by uuid



63
64
65
66
67
# File 'lib/fog/libvirt/models/compute/servers.rb', line 63

def get_by_uuid(uuid)
  server=connection.raw.lookup_domain_by_uuid(uuid)
  return server
  #          new(:raw => machine)
end