ruby-qa/lib/resource.rb

66 lines
1.3 KiB
Ruby

module RubyQA
class Resource
attr_reader :name, :data
REQUIREMENTS = {}
def initialize (host)
@host = host
@data = Hash.new
@gather_command = ""
end
def gather
if not @gather_command.empty?
output = @host.exec(@gather_command)
parse(output)
else
raise "@gather_command was not defined on Resource[#{@name}]"
end
end
def parse(output)
raise "parse not yet implemented on Resource[#{@name}]"
end
## This will allow me to iterate through all subclasses without
## having to manually define them elsewhere
def self.all_resources
ObjectSpace.each_object(Class).select{|klass| klass < self}
end
end
## Gathers the facts from the remote machine via the facter utility
require 'json'
class Facts < Resource
REQUIREMENTS = {}
def initialize (host)
super host
@name = 'facts'
@gather_command = "facter -j"
end
def parse (output)
@data = JSON.load(output)
end
end
class DRDB < Resource
REQUIREMENTS = {
:cluster => true
}
def initialize (host)
super host
@name = 'facts'
@gather_command = "sudo drbdadm"
end
def parse (output)
@data = output
end
end
end