knife-softlayer 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjY0ZTQ0ZTI5NzNkNWVkNGE5YWE1YmFhMWM4ZDY2YmE0NzNjZDAxZA==
4
+ ZjczMGVhNjA5ODNhY2I3NTE4Mjc5YzlmMTg3ZjhlYzVlOGMwZDRmMQ==
5
5
  data.tar.gz: !binary |-
6
- MDRkMDZlODBkM2UwMDYyMmI4YmZhNzEzZWU2ZDliOTU2NzMyNmEwMA==
6
+ ZGNiMDg4NGUzZTcwZDVkM2ZhYzg0N2M4MDcxYWI0Y2Q1ZmI1OGEyYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzNkNjE5NWFlMTY0OGE5NGFiYmQ4MTI0ODk4OTUwYzExYzYyYzc1MGI3YThh
10
- OTFlMzBjODAzNDgyOTgxY2ZlYmU2MGRmZmI0NmQyNTRiOTIxMmNiNWJlZTQ1
11
- OTNiZTAxMTUwZmQ5MzliNWYyZjAxNTVmNjVmMDc4YmNhZWUxY2E=
9
+ ODRlNTJiNTZkNzliMTkwNDk2OTA2ODNiNDMzMWU0ZjM0MDA5ZjI0N2M3MzM0
10
+ ZDk4YzFmNjM5ODFlNzk5MjgxYjg4ZGYyNmNiYjhjYzAwNmY5NDkxMjRhNzY3
11
+ NzNmOGU2ZDc5YTQ0N2U2NGFhOTE0NjUyOGJlOWI5MmU4ZWIzYWQ=
12
12
  data.tar.gz: !binary |-
13
- ODczMjIyMGU0MTNkNzBjYTI4Nzg5YTBhN2M0MDg4ZWY1YzM4ZTUyMWE1YWVi
14
- N2E4MzVjYWFlNTlmNzU3OGViNGRiZjVhMWRlNWQ1YTdmMzdmOWNjYzIxMTI2
15
- OWI3ZmZkMTBjNDhhMTJjNmFmZWRiODQ1MWM4NzQyM2ZlNzM4YWQ=
13
+ NWUwZDU3ZTE5YmFlMDA0NTc5ZDkyNzY1YmM3ZGRhMjA2YWJhNDZmMTgyOTEz
14
+ YTkyNjQ1OGQxNThhYmFlYmQ0MmVkMGYxZTNiNjM3ZmM4NWFlMmVjY2I5NzJl
15
+ N2M5YzM4MDI2MTNmOTQ4OTA3YTg1NjNjYTg2ZDgyNGQzZjQ3ODI=
@@ -239,6 +239,10 @@ class Chef
239
239
  Chef::Config[:knife][:hints][name] = path ? JSON.parse(::File.read(path)) : Hash.new
240
240
  }
241
241
 
242
+ require 'chef/knife/bootstrap'
243
+ # Make the base bootstrap options available on topo bootstrap
244
+ self.options = (Chef::Knife::Bootstrap.options).merge(self.options)
245
+
242
246
  ##
243
247
  # Run the procedure to create a SoftLayer VM and bootstrap it.
244
248
  # @return [nil]
@@ -50,6 +50,17 @@ class Chef
50
50
  @chef.search('node', "ipaddress:#{config[:ip_address]}") do |node|
51
51
  @node = node
52
52
  end
53
+ elsif arg = name_args[0]
54
+ if arg =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ # ipv4
55
+ query = "ipaddress:#{arg}"
56
+ elsif arg =~ /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/ # ipv6
57
+ query = "ipaddress:#{arg}"
58
+ else
59
+ query = "name:#{arg}"
60
+ end
61
+ @chef.search('node', query) do |node|
62
+ @node = node
63
+ end
53
64
  else
54
65
  raise "#{ui.color("FATAL: Please supply the node name or IP address.", :red)}"
55
66
  end
@@ -0,0 +1,106 @@
1
+ #
2
+ # Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: Apache 2.0 (http://www.apache.org/licenses/)
6
+ #
7
+
8
+ require 'chef/knife/softlayer_base'
9
+
10
+ class Chef
11
+ class Knife
12
+ class SoftlayerServerRelaunch < Knife
13
+
14
+ include Knife::SoftlayerBase
15
+
16
+ banner 'knife softlayer server relaunch <NODE NAME> [<NODE NAME>]'
17
+
18
+ option :all,
19
+ :short => "-a",
20
+ :long => "--all",
21
+ :description => "Display all available configuration options for launching an instance.",
22
+ :default => false
23
+
24
+ require 'chef/knife/bootstrap'
25
+ # Make the base bootstrap options available on topo bootstrap
26
+ self.options = (Chef::Knife::Bootstrap.options).merge(self.options)
27
+
28
+ ##
29
+ # Run the procedure to list softlayer VM flavors or display all available options.
30
+ # @return [nil]
31
+ def run
32
+ $stdout.sync = true
33
+ if name_args.count < 1
34
+ ui.fatal("Server relaunch requires AT LEAST ONE node name.")
35
+ exit 1;
36
+ end
37
+
38
+ ident_file = Chef::Config[:knife][:identity_file] || config[:identity_file]
39
+ Fog.credentials[:private_key_path] = ident_file if ident_file
40
+
41
+ Chef::Search::Query.new.search(:node, "name:#{name_args[0]}") do |object|
42
+ @vm = connection.servers.select { |s| s.public_ip == object.ipaddress }.first
43
+ end
44
+ ui.fatal("Server not found on SoftLayer account.") and exit 1 unless @vm
45
+
46
+ unless @vm.sshable?
47
+ ui.fatal("Node with name #{name_args[0]} not sshable, relaunch canceled.")
48
+ exit 1
49
+ end
50
+
51
+ # grab the contents of /etc/chef from the target node and stash a local copy
52
+ begin
53
+ puts ui.color("Capturing existing node configuration files.", :green)
54
+ @vm.scp_download("/etc/chef", "/tmp/#{@vm.id}/", :recursive => true)
55
+ rescue Exception => e
56
+ puts ui.color(e.message, :red)
57
+ ui.fatal('Relaunch canceled.')
58
+ exit 1
59
+ end
60
+
61
+ begin
62
+ puts ui.color("Relaunching SoftLayer server, this may take a few minutes.", :green)
63
+ @vm.relaunch!
64
+ @vm.wait_for { putc '.'; ready? && sshable? }
65
+ puts ''
66
+ rescue Exception => e
67
+ puts ui.color(e.message, :red)
68
+ ui.fatal('Relaunch FAILED. You may be missing a server.')
69
+ exit 1
70
+ end
71
+
72
+ # push the locally stashed config items up to new machine
73
+ begin
74
+ puts ui.color("Installing node configuration on relaunched server.", :green)
75
+ @vm.scp("/tmp/#{@vm.id}/chef/", "/etc/", :recursive => true)
76
+ rescue Exception => e
77
+ puts ui.color(e.message, :red)
78
+ ui.fatal('Relaunch FAILED. You may be missing a chef node.')
79
+ exit 1
80
+ end
81
+
82
+ begin
83
+ puts ui.color("Installing chef-client executable on relaunched server.", :green)
84
+ puts @vm.ssh('wget https://www.chef.io/chef/install.sh && sudo bash ./install.sh && rm install.sh').first.stdout
85
+ rescue Exception => e
86
+ puts ui.color(e.message, :red)
87
+ ui.fatal('Relaunch FAILED. You may be missing a chef node.')
88
+ exit 1
89
+ end
90
+
91
+ # run chef-client on the new machine with the existing config and attributes
92
+ begin
93
+ puts ui.color("Initial run of chef-client on relaunched server, this may take a few minutes.", :green)
94
+ puts @vm.ssh('sudo chef-client -j /etc/chef/first-boot.json').first.stdout
95
+ rescue Exception => e
96
+ puts ui.color(e.message, :red)
97
+ ui.fatal('Relaunch FAILED on chef run. Your chef node may be misconfigured.')
98
+ exit 1
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+
@@ -7,6 +7,6 @@
7
7
 
8
8
  module Knife
9
9
  module Softlayer
10
- VERSION = "0.3.11"
10
+ VERSION = "0.3.12"
11
11
  end
12
12
  end
@@ -34,11 +34,12 @@ describe Chef::Knife::SoftlayerServerCreate do
34
34
  expect { @server_create.run }.to raise_exception(Chef::Knife::SoftlayerServerCreateError)
35
35
  end
36
36
 
37
+
37
38
  [':ram', ':cores', ':hostname', ':domain', ':datacenter', ':os_code', ':block_storage'].each do |opt|
38
39
  class_eval <<EOS, __FILE__, __LINE__
39
- it "should should raise an ArgumentError if missing #{opt} option" do
40
+ it "should should raise an exception if missing #{opt} option" do
40
41
  @server_create.config.delete(#{opt})
41
- expect { @server_create.run }.to raise_exception(ArgumentError)
42
+ expect { @server_create.run }.to raise_exception
42
43
  end
43
44
  EOS
44
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-softlayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Eldridge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-softlayer
@@ -191,6 +191,7 @@ files:
191
191
  - lib/chef/knife/softlayer_list.rb
192
192
  - lib/chef/knife/softlayer_server_create.rb
193
193
  - lib/chef/knife/softlayer_server_destroy.rb
194
+ - lib/chef/knife/softlayer_server_relaunch.rb
194
195
  - lib/chef/knife/softlayer_vlan_create.rb
195
196
  - lib/chef/knife/softlayer_vlan_list.rb
196
197
  - lib/chef/knife/softlayer_vlan_show.rb