Class: ResourceIn::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/resource_in/driver.rb

Direct Known Subclasses

RacktablesDriver, UCSDriver, VMwareDriver

Constant Summary collapse

FORMAT =
['name', 'address', 'status', 'location', 'boottime', 'created_by']
DETAIL_FORMAT =
['name', 'address', 'status', 'location', 'boottime', 'created_by', 'cores', 'RAM', 'OS', 'Alarm']
VALID_PATTERN =
/^[0-9A-Za-z[:space:]_\-\.]+$/

Instance Method Summary collapse

Instance Method Details

#invoke(command, cachepath = '/dev/null') ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/resource_in/driver.rb', line 13

def invoke(command, cachepath = '/dev/null')
  cachepath.gsub!(' ', '_')

  if !!cachepath and FileTest.exists?(cachepath) and not FileTest.zero?(cachepath)
    JSON.parse(File.read(cachepath)) unless FileTest.zero? cachepath
  else
    JSON.parse(`#{command} 2> /dev/null | tee '#{cachepath}'`)
  end
end

#validate_condition(argument) ⇒ Object

Raises:



9
10
11
# File 'lib/resource_in/driver.rb', line 9

def validate_condition(argument)
  raise InvalidArgument.new("Invalid Argument: #{argument}") unless !!(argument =~ VALID_PATTERN)
end