Method: WASP::Aws#initialize

Defined in:
lib/wasp/ec2.rb

#initialize(args) ⇒ Aws

Returns a new instance of Aws.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wasp/ec2.rb', line 18

def initialize (args)
  config_path = ENV["HOME"] + "/.waspaws.yml"
  begin
    AWS.config(YAML.load(File.read(config_path)))
    @ec2 = AWS::EC2.new
  rescue => ex
    puts "[WARN]".yellow + " #{ex.message}"
    puts "[WARN]".yellow + " Please set AWS credential file."
    exit false
  end
  
  # evaluate AWS access_key and secret_access_key
  begin
    print "EC2".green + " Checking access key validation.."
    @ec2.availability_zones.each do |av| 
      av.name 
    end
    puts " OK".green
  rescue => ex
    puts "[WARN]".yellow + " #{ex.message}"
    puts "[WARN]".yellow + " Please copy/paste correct AWS access_key and secret_access_key to config/aws.yml file"
    exit false
  end
  
  @num_wasps = if args[:server].nil? then WASP::Const::DEFAULT_WASPS
              else
                args[:server].to_i
              end
  @group = if args[:group].nil? then WASP::Const::DEFAULT_GROUP
           else
             args[:group]
           end
  @zone = if args[:zone].nil? then WASP::Const::DEFAULT_ZONE
          else
            args[:zone]
          end              
  @ami = if args[:ami].nil? then get_default_ami(@zone)
         else
           args[:ami]
         end
  @login = if args[:login].nil? then WASP::Const::DEFAULT_USER
           else
             args[:login]
           end     
  
  @key = args[:key]
  
  
  @regions = @ec2.regions
  @instance_list = []
  @instances = nil
end