2011-06-28 09:47:16 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-29 11:24:39 -04:00
|
|
|
require 'fog/libvirt/models/compute/server'
|
2011-06-28 09:47:16 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Libvirt
|
|
|
|
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Libvirt::Server
|
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
def all(filter=nil)
|
|
|
|
data=[]
|
2011-08-22 04:51:34 -04:00
|
|
|
filter={} if filter.nil?
|
2011-08-22 03:16:06 -04:00
|
|
|
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.list_defined_domains.map do |domain|
|
|
|
|
data << { :raw => connection.lookup_domain_by_name(domain) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if include_active
|
|
|
|
connection.list_domains.each do |domain|
|
|
|
|
data << { :raw => connection.lookup_domain_by_id(domain) }
|
|
|
|
end
|
2011-08-03 06:48:44 -04:00
|
|
|
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)
|
2011-06-28 09:47:16 -04:00
|
|
|
|
2011-08-03 06:48:44 -04:00
|
|
|
rescue ::Libvirt::RetrieveError
|
|
|
|
return nil
|
|
|
|
end
|
2011-08-22 03:16:06 -04:00
|
|
|
unless domain.nil?
|
|
|
|
data << { :raw => domain }
|
|
|
|
end
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
2011-08-08 17:18:03 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
load(data)
|
|
|
|
end
|
2011-08-08 17:18:03 -04:00
|
|
|
|
2011-08-03 08:28:40 -04:00
|
|
|
def get(uuid)
|
|
|
|
self.all(:uuid => uuid).first
|
2011-08-03 06:48:44 -04:00
|
|
|
end
|
2011-06-28 09:47:16 -04:00
|
|
|
|
|
|
|
def bootstrap(new_attributes = {})
|
|
|
|
raise 'Not Implemented'
|
|
|
|
# server = create(new_attributes)
|
|
|
|
# server.start
|
|
|
|
# server.wait_for { ready? }
|
|
|
|
# server.setup(:password => server.password)
|
|
|
|
# server
|
|
|
|
end
|
2011-08-08 17:18:03 -04:00
|
|
|
|
2011-08-03 08:28:40 -04:00
|
|
|
# private #making these internals private screws up reload
|
2011-08-08 17:18:03 -04:00
|
|
|
|
2011-06-28 09:47:16 -04:00
|
|
|
# Retrieve the server by uuid
|
2011-08-03 06:48:44 -04:00
|
|
|
def get_by_uuid(uuid)
|
|
|
|
server=connection.lookup_domain_by_uuid(uuid)
|
|
|
|
return server
|
2011-08-08 17:30:09 -04:00
|
|
|
# new(:raw => machine)
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieve the server by name
|
|
|
|
def get_by_name(name)
|
2011-08-03 06:48:44 -04:00
|
|
|
server=connection.lookup_domain_by_name(name)
|
2011-08-08 17:18:03 -04:00
|
|
|
return server
|
2011-08-08 17:30:09 -04:00
|
|
|
# new(:raw => machine)
|
2011-06-28 09:47:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end #class
|
|
|
|
end #Class
|
|
|
|
end #module
|
|
|
|
end #Module
|