Class: Commands::MaintInstances

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/maint_instances.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject

holds the options that were passed you can set any initial defaults here



6
7
8
9
10
11
# File 'lib/commands/maint_instances.rb', line 6

def options
  @options ||= {
      :migrate_command => '',
      :downtime => false
  }
end

#register(opts, global_options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/commands/maint_instances.rb', line 21

def register(opts, global_options)
  opts.banner = "Usage: maint [options]"
  opts.description = "Put up or take down the maintenance page."

  opts.on('-g', "--group name", "Required - Name of this deploy group.") do |v|
    options[:group] = v
  end

  opts.on('-m', "--[no-]maint", "Required - Use --maint if you want the maint page, --no-maint to remove the maint page.") do |v|
    options[:maint] = v
  end

  opts.on('-p', "--print path", "The directory into which we output the data as a file per host.") do |v|
    options[:result_path] = v
  end
end

#required_optionsObject

required options



14
15
16
17
18
19
# File 'lib/commands/maint_instances.rb', line 14

def required_options
  @required_options ||= Set.new [
      :group,
      :maint,
  ]
end

#run(global_options, amazon) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/commands/maint_instances.rb', line 39

def run(global_options, amazon)
  ec2 = amazon.ec2
  utils = ZZSharedLib::Utils.new(amazon)

  group_name = options[:group]
  maint = options[:maint]

  # first see if already exists
  deploy_group = amazon.find_deploy_group(group_name)

  instances = amazon.find_and_sort_named_instances(group_name)

  # see if already deploying
  if !options[:force]
    # raises an exception if not all in the ready or error state
    utils.check_deploy_state(instances, [:deploy_chef, :deploy_app])
  end


  # put up or take down the maint page
  BuildDeployConfig.do_maint_deploy(utils, amazon, instances, group_name, deploy_group, maint, options[:result_path])

end