Class: Awsom::Cli::Resources

Inherits:
Object
  • Object
show all
Defined in:
lib/awsom/cli/resources.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Resources

Returns a new instance of Resources.



8
9
10
# File 'lib/awsom/cli/resources.rb', line 8

def initialize(argv)
  @argv = argv
end

Instance Method Details

#init_aws(config) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/awsom/cli/resources.rb', line 27

def init_aws(config)
  require 'aws-sdk-core'
  if config.key?(:aws_key) && config.key?(:aws_secret)
    credentials = Aws::Credentials.new(config.fetch(:aws_key), config.fetch(:aws_secret))
    Aws.config[:credentials] = credentials
  end
  Aws.config[:region] = config.fetch(:region)
  require_relative '../ec2'
end

#lockObject



37
38
39
# File 'lib/awsom/cli/resources.rb', line 37

def lock
  @lock ||= ::Awsom::Lock.new
end

#optsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/awsom/cli/resources.rb', line 41

def opts
  OptionParser.new do |opts|

    opts.banner = "Usage: awsom create [options] [target]"
    
    opts.on("-f", "--file FILE", "Specify hosts file") do |f|
      salt.hosts_file = f
    end
    
    opts.on("-h", "--help", "Help") do
      puts opts
      exit
    end
  end
end

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/awsom/cli/resources.rb', line 12

def run
  lock.acquire
  opts.parse!(@argv)
  config = Config.new("config.rb").config

  init_aws(config)

  vpc_id = config.fetch :vpc_id
  region = config.fetch :region

  require 'awsom/application'
  app = Application.new(vpc_id: vpc_id, region: region)
  app.run(@argv)
end