Class: Ec2::Cli::Resources

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Resources



9
10
11
# File 'lib/ec2/cli/resources.rb', line 9

def initialize(argv)
  @argv = argv
end

Instance Method Details

#configObject



35
36
37
# File 'lib/ec2/cli/resources.rb', line 35

def config
  @config ||= ::Ec2::Config.new("ec2.rb").config
end

#init_awsObject



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

def init_aws
  if not config[:use_iam]
    credentials = Aws::Credentials.new(config[:aws_key], config[:aws_secret])
    Aws.config[:credentials] = credentials
  end
  Aws.config[:region] = config[:region]
end

#lockObject



23
24
25
# File 'lib/ec2/cli/resources.rb', line 23

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

#optsObject



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

def opts
  OptionParser.new do |opts|

    opts.banner = "Usage: ec2 resources [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



13
14
15
16
17
18
19
20
21
# File 'lib/ec2/cli/resources.rb', line 13

def run
  lock.acquire
  opts.parse!(@argv)
  init_aws
  @argv.each do |file|
    resources = ::Ec2::Resources.new(file)
    resources.apply
  end
end