Class: Chef::Knife::SoftlayerServerRelaunch
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::SoftlayerServerRelaunch
- Includes:
- SoftlayerBase
- Defined in:
- lib/chef/knife/softlayer_server_relaunch.rb,
lib/chef/knife/softlayer_server_relaunch.rb
Constant Summary
Constants included from SoftlayerBase
Chef::Knife::SoftlayerBase::USER_AGENT
Instance Method Summary collapse
-
#run ⇒ nil
Run the procedure to list softlayer VM flavors or display all available options.
Methods included from SoftlayerBase
#compute, #connection, included, #locate_config_value, #msg_pair, #network
Instance Method Details
#run ⇒ nil
Run the procedure to list softlayer VM flavors or display all available options.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 |
# File 'lib/chef/knife/softlayer_server_relaunch.rb', line 27 def run $stdout.sync = true if name_args.count < 1 ui.fatal("Server relaunch requires AT LEAST ONE node name.") exit 1; end ident_file = Chef::Config[:knife][:identity_file] || config[:identity_file] Fog.credentials[:private_key_path] = ident_file if ident_file Chef::Search::Query.new.search(:node, "name:#{name_args[0]}") do |object| @vm = connection.servers.select { |s| s.public_ip == object.ipaddress }.first end ui.fatal("Server not found on SoftLayer account.") and exit 1 unless @vm unless @vm.sshable? ui.fatal("Node with name #{name_args[0]} not sshable, relaunch canceled.") exit 1 end # grab the contents of /etc/chef from the target node and stash a local copy begin puts ui.color("Capturing existing node configuration files.", :green) @vm.scp_download("/etc/chef", "/tmp/#{@vm.id}/", :recursive => true) rescue Exception => e puts ui.color(e., :red) ui.fatal('Relaunch canceled.') exit 1 end begin puts ui.color("Relaunching SoftLayer server, this may take a few minutes.", :green) @vm.relaunch! @vm.wait_for { putc '.'; ready? && sshable? } puts '' rescue Exception => e puts ui.color(e., :red) ui.fatal('Relaunch FAILED. You may be missing a server.') exit 1 end # push the locally stashed config items up to new machine begin puts ui.color("Installing node configuration on relaunched server.", :green) @vm.scp("/tmp/#{@vm.id}/chef/", "/etc/", :recursive => true) rescue Exception => e puts ui.color(e., :red) ui.fatal('Relaunch FAILED. You may be missing a chef node.') exit 1 end begin puts ui.color("Installing chef-client executable on relaunched server.", :green) puts @vm.ssh('wget https://www.chef.io/chef/install.sh && sudo bash ./install.sh && rm install.sh').first.stdout rescue Exception => e puts ui.color(e., :red) ui.fatal('Relaunch FAILED. You may be missing a chef node.') exit 1 end # run chef-client on the new machine with the existing config and attributes begin puts ui.color("Initial run of chef-client on relaunched server, this may take a few minutes.", :green) puts @vm.ssh('sudo chef-client').first.stdout rescue Exception => e puts ui.color(e., :red) ui.fatal('Relaunch FAILED on chef run. Your chef node may be misconfigured.') exit 1 end end |