module RubyQA class Host DEFAULT_HOSTDATA={ :hostname => "", :ip => "", :port => 22, :user => ENV["USER"], :password => "", :site => "", :cluster => false, :sudo_password => "", :runner => SSH_Runner } attr_reader :client, :data, :resources def initialize( data = {} ) @resources = Hash.new @data = DEFAULT_HOSTDATA.merge data if not @data[:hostname].empty? and @data[:site].empty? data[:site]=@data[:hostname][0,3] end ## initialize client for usage tests @client = @data[:runner].new(@data) end def exec (command) ## Send a command from the host @client.exec(command) end def exec_sudo (command) ## Send a sudo command from the host @client.exec_sudo(command) end def [](key) ## Provide Access to data (:ip, etc) @data[key] end def name if @data[:hostname] != "" @data[:hostname] elsif @resources['facts'].data['hostname'] != "" @resources['facts'].data['hostname'] else self.exec('hostname') end end def add_resource (object) ## If the requirements are met by the host, add the resource if object::REQUIREMENTS.all?{|key,val| @data[key] == val} resource = object.new(self) @resources[resource.name]=resource end end def update_resources @resources.each_value(&:gather) end end end