Class: Chef::Knife::ClusterLaunch

Inherits:
Chef::Knife show all
Includes:
Ironfan::KnifeCommon
Defined in:
lib/chef/knife/cluster_launch.rb

Instance Attribute Summary

Attributes included from Ironfan::KnifeCommon

#broker, #problems

Instance Method Summary collapse

Methods included from Ironfan::KnifeCommon

#all_computers, #bootstrapper, #configure_dry_run, #confirm_execution, #confirm_or_exit, #die, #discover_computers, #display, #exit_if_unhealthy!, #gemfile, #get_relevant_slice, #get_slice, #has_problem, #healthy?, included, load_deps, #load_ironfan, #pick_apart, #predicate_str, #progressbar_for_threads, #relevant?, #run, #run_bootstrap, #section, #sub_command, #wait_for_ssh

Instance Method Details

#_runObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/chef/knife/cluster_launch.rb', line 66

def _run
  load_ironfan
  die(banner) if @name_args.empty?
  configure_dry_run

  #
  # Load the facet
  #
  full_target = get_slice(*@name_args)
  display(full_target)
  target = full_target.select(&:launchable?)

  warn_or_die_on_bogus_servers(full_target) unless full_target.select(&:bogus?).empty?

  die("", "#{ui.color("All computers are running -- not launching any.",:blue)}", "", 0) if target.empty?

  # If a bootstrap was requested, ensure that we will be able to perform the
  # bootstrap *before* trying to launch all of the servers in target. This
  # will save the user a lot of time if they've made a configuration mistake
  if config[:bootstrap]
    ensure_common_environment(target)
  end

  # Pre-populate information in chef
  section("Syncing to chef")
  target.save :providers => :chef

  unless target.empty?
    ui.info "Preparing shared resources:"
    all_computers(*@name_args).prepare
  end

  # Launch computers
  ui.info("")
  section("Launching computers", :green)
  display(target)
  launched = target.launch

  # As each server finishes, configure it. If we received an
  # exception launching any of the machines, remember it.

  launch_succeeded = true
  Ironfan.parallel(launched) do |computer|
    if (computer.is_a?(Exception)) then
      ui.error "Error launching #{computer.inspect}; skipping after-launch tasks.";
      launch_succeeded = false
    else
      perform_after_launch_tasks(computer) if computer.machine.perform_after_launch_tasks?
    end
  end

  if healthy? and launch_succeeded
    section('All computers launched correctly', :white)
    section('Applying aggregations:')
    all_computers(*@name_args).aggregate
  else
    section('Some computers could not be launched')
    exit 1
  end

  display(target)
end

#perform_after_launch_tasks(computer) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/chef/knife/cluster_launch.rb', line 129

def perform_after_launch_tasks(computer)
  # Try SSH
  unless config[:dry_run]
    if config[:wait_ssh]
      Ironfan.step(computer.name, 'trying ssh', :white)
      nil until wait_for_ssh(computer){ sleep @initial_sleep_delay ||= 10  }
    end
  end
  
  # Run Bootstrap
  if config[:bootstrap]
    Ironfan.step(computer.name, 'bootstrapping', :green)
    run_bootstrap(computer)
  end
end

#warn_or_die_on_bogus_servers(target) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/chef/knife/cluster_launch.rb', line 145

def warn_or_die_on_bogus_servers(target)
  ui.info("")
  ui.info "Cluster has servers in a transitional or undefined state (shown as 'bogus'):"
  ui.info("")
  display(target)
  ui.info("")
  unless config[:force]
    die(
      "Launch operations may be unpredictable under these circumstances.",
      "You should wait for the cluster to stabilize, fix the undefined server problems",
      "(run \"knife cluster show CLUSTER\" to see what the problems are), or launch",
      "the cluster anyway using the --force option.", "", -2)
  end
  ui.info("")
  ui.info "--force specified"
  ui.info "Proceeding to launch anyway. This may produce undesired results."
  ui.info("")
end