mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
4740174f12
Because the initial provider was copied from the virtualbox example we ended up with a notation connection.connection for the raw provider The function of the raw are injected on the connection object. Still in analogy with the raw for server , volume, ... it makes sense to rename connection.connection to connection.raw Also all calls to the raw connection are now explicit
78 lines
2.2 KiB
Ruby
78 lines
2.2 KiB
Ruby
require 'fog/core/collection'
|
|
require 'fog/libvirt/models/compute/server'
|
|
|
|
module Fog
|
|
module Compute
|
|
class Libvirt
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
model Fog::Compute::Libvirt::Server
|
|
|
|
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
|
|
|
|
def get(uuid)
|
|
self.all(:uuid => uuid).first
|
|
end
|
|
|
|
def bootstrap(new_attributes = {})
|
|
raise 'Not Implemented'
|
|
# server = create(new_attributes)
|
|
# server.start
|
|
# server.wait_for { ready? }
|
|
# server.setup(:password => server.password)
|
|
# server
|
|
end
|
|
|
|
# private #making these internals private screws up reload
|
|
|
|
# Retrieve the server by uuid
|
|
def get_by_uuid(uuid)
|
|
server=connection.raw.lookup_domain_by_uuid(uuid)
|
|
return server
|
|
# new(:raw => machine)
|
|
end
|
|
|
|
# Retrieve the server by name
|
|
def get_by_name(name)
|
|
server=connection.raw.lookup_domain_by_name(name)
|
|
return server
|
|
# new(:raw => machine)
|
|
end
|
|
|
|
end #class
|
|
end #Class
|
|
end #module
|
|
end #Module
|