Class: Ec2::Cli::Hosts

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Hosts

Returns a new instance of Hosts.



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

def initialize(argv)
  @argv = argv
end

Instance Method Details

#configObject



29
30
31
# File 'lib/ec2/cli/hosts.rb', line 29

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

#lockObject



25
26
27
# File 'lib/ec2/cli/hosts.rb', line 25

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

#optsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ec2/cli/hosts.rb', line 33

def opts
  OptionParser.new do |opts|

    opts.banner = "Usage: ec2 hosts [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
# File 'lib/ec2/cli/hosts.rb', line 13

def run
  lock.acquire
  opts.parse!(@argv)
  salt.config = config
  salt.run
  puts "ran hosts"
end

#saltObject



21
22
23
# File 'lib/ec2/cli/hosts.rb', line 21

def salt
  @salt ||= ::Ec2::SaltCloud.new
end