class Vominator::EC2Info::InstanceInfo
Attributes
filepath[RW]
instances[RW]
Public Class Methods
new(file=nil)
click to toggle source
# File lib/vominator/ec2info.rb, line 21 def initialize(file=nil) self.filepath = file || filepath_from_config # Get the source file from @@uri if it's too old or missing get_instance_info if refresh_info? # Load the json data load_instances() end
Public Instance Methods
get_instance(type)
click to toggle source
# File lib/vominator/ec2info.rb, line 31 def get_instance(type) Instance.new(@@instances.detect {|i| i['instance_type'] == type}) end
get_instance_info()
click to toggle source
# File lib/vominator/ec2info.rb, line 49 def get_instance_info() File.open(self.filepath, 'w+') { |f| f.write(Net::HTTP.get(@@uri)) } end
load_instances()
click to toggle source
# File lib/vominator/ec2info.rb, line 35 def load_instances() get_instance_info() if refresh_info? instances = JSON.load(File.read(self.filepath)) @@instances = instances if instances.kind_of?(Array) end
refresh_info?()
click to toggle source
# File lib/vominator/ec2info.rb, line 42 def refresh_info? return true if not File.exist?(self.filepath) or File.zero?(self.filepath) last_updated = File.ctime(self.filepath) (Time.now - last_updated) > 86400 end
Private Instance Methods
filepath_from_config()
click to toggle source
# File lib/vominator/ec2info.rb, line 53 def filepath_from_config file = VOMINATOR_CONFIG['instances_file'] if File.exist?(file) file = File.expand_path(file) end file end