knife-softlayer 0.3.12 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjczMGVhNjA5ODNhY2I3NTE4Mjc5YzlmMTg3ZjhlYzVlOGMwZDRmMQ==
4
+ NDViMjM2MDdmMzEyNzc3Yzc2YTk2ZGZlMDBiNTAyM2M3ZGMwNmExYQ==
5
5
  data.tar.gz: !binary |-
6
- ZGNiMDg4NGUzZTcwZDVkM2ZhYzg0N2M4MDcxYWI0Y2Q1ZmI1OGEyYQ==
6
+ Mjg0MjRiNmVmMDJiYTM4M2NjZGRmMTNlYjQxZjdjMGZmNjAwYWEzYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODRlNTJiNTZkNzliMTkwNDk2OTA2ODNiNDMzMWU0ZjM0MDA5ZjI0N2M3MzM0
10
- ZDk4YzFmNjM5ODFlNzk5MjgxYjg4ZGYyNmNiYjhjYzAwNmY5NDkxMjRhNzY3
11
- NzNmOGU2ZDc5YTQ0N2U2NGFhOTE0NjUyOGJlOWI5MmU4ZWIzYWQ=
9
+ ZDc1MzRmMDI2MTk2MTE2NDg3MWY2M2RiZGI3MDlkYjVmNTAzMzJiM2U2NzMw
10
+ OTRlMzkyNzYyODliMjllZWFjZjExYzU4ZDI5NDg3MzIxZjBlODg2NDhlMzdi
11
+ Yjc4YjMzNDNkN2RlOWViMzhjNjk1ZWNhNDQ3YmNlZjhmMDExYjg=
12
12
  data.tar.gz: !binary |-
13
- NWUwZDU3ZTE5YmFlMDA0NTc5ZDkyNzY1YmM3ZGRhMjA2YWJhNDZmMTgyOTEz
14
- YTkyNjQ1OGQxNThhYmFlYmQ0MmVkMGYxZTNiNjM3ZmM4NWFlMmVjY2I5NzJl
15
- N2M5YzM4MDI2MTNmOTQ4OTA3YTg1NjNjYTg2ZDgyNGQzZjQ3ODI=
13
+ MjVjYzI5ZDRmMjM4MjZiZjU5ZjgxMjRlMWNmZThjZGU0ODc0MGExNjEyMTQy
14
+ ZTBkNDNiNWRkNzBiMDRjN2EwZmIxOTYwMmJiZjMyMDNmMWFjODA0MjkzZGRm
15
+ YzFmMzEyMjgwYzg4MjlmNGU2MzVhMThkNDgyOGFjZDI3YmFlZGY=
@@ -25,8 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.test_files = spec.files.grep(%r{^(spec|spec|features)/})
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "fog-softlayer", "0.3.29"
29
- #spec.add_dependency "fog-softlayer", "~> 0.3", ">= 0.3.29"
28
+ spec.add_dependency "fog-softlayer", "~> 0.3.30"
30
29
  spec.add_dependency "knife-windows", "> 0.5.12"
31
30
  spec.add_dependency "net-ssh", "> 2.8.0"
32
31
 
@@ -5,7 +5,7 @@
5
5
  # LICENSE: Apache 2.0 (http://www.apache.org/licenses/)
6
6
  #
7
7
 
8
- require 'chef/knife'
8
+ require 'chef/knife/bootstrap'
9
9
  require 'knife-softlayer/version'
10
10
 
11
11
  class Chef
@@ -32,6 +32,9 @@ class Chef
32
32
  require 'chef/json_compat'
33
33
  end
34
34
 
35
+ # Make the base bootstrap options available on topo bootstrap
36
+ self.options = (Chef::Knife::Bootstrap.options).merge(self.options)
37
+
35
38
  option :softlayer_credential_file,
36
39
  :long => "--softlayer-credential-file FILE",
37
40
  :description => "File containing SoftLayer credentials as used by `softlayer_api` Ruby gem.",
@@ -85,6 +85,11 @@ class Chef
85
85
  :description => 'Flag to be passed when the compute instance should have no public facing network interface.',
86
86
  :boolean => true
87
87
 
88
+ option :use_private_network,
89
+ :long => '--use-private-network',
90
+ :description => 'Flag to be passwed when bootstrap is preferred over the private network.',
91
+ :boolean => true
92
+
88
93
  option :from_file,
89
94
  :long => '--from-file PATH',
90
95
  :description => 'Path to JSON file containing arguments for provisoning and bootstrap.'
@@ -297,7 +302,7 @@ class Chef
297
302
 
298
303
  puts ui.color("Launching SoftLayer VM, this may take a few minutes.", :green)
299
304
  instance = connection.servers.create(opts)
300
- if config[:private_network_only]
305
+ if config[:private_network_only] || config[:use_private_network]
301
306
  instance.ssh_ip_address = Proc.new {|server| server.private_ip_address }
302
307
  end
303
308
  progress Proc.new { instance.wait_for { ready? and sshable? } }
@@ -38,56 +38,68 @@ class Chef
38
38
  $stdout.sync = true
39
39
 
40
40
  puts ui.color("Decommissioning SoftLayer VM, this may take a few minutes.", :green)
41
-
41
+ connection.servers.each do |server|
42
+ if config[:ip_address]
43
+ if server.public_ip_address == config[:ip_address]
44
+ @instance = server
45
+ break
46
+ end
47
+ elsif config[:chef_node_name]
48
+ if server.name == config[:chef_node_name]
49
+ config[:ip_address] = server.public_ip_address
50
+ @instance = server
51
+ break
52
+ end
53
+ elsif arg = name_args[0]
54
+ if arg =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ # ipv4
55
+ if server.public_ip_address == arg
56
+ @instance = server
57
+ break
58
+ end
59
+ elsif arg =~ /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/ # ipv6
60
+ if server.public_ip_address == arg
61
+ @instance = server
62
+ break
63
+ end
64
+ else
65
+ if server.name == arg
66
+ config[:ip_address] = server.public_ip_address
67
+ @instance = server
68
+ break
69
+ end
70
+ end
71
+ end
72
+ end
73
+ @instance.nil? and raise "#{ui.color('VM instance with IP: ' + (config[:ip_address].to_s) +' not found!', :red)}"
42
74
  @chef = Chef::Search::Query.new
43
-
44
- if config[:chef_node_name]
45
- @chef.search('node', "name:#{config[:chef_node_name]}") do |node|
46
- config[:ip_address] = node.ipaddress
47
- @node = node
48
- end
49
- elsif config[:ip_address]
50
- @chef.search('node', "ipaddress:#{config[:ip_address]}") do |node|
51
- @node = node
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
75
+ @chef.search('node', "name:#{@instance.name}") do |node|
76
+ begin
77
+ @node = node
78
+ rescue
63
79
  end
64
- else
65
- raise "#{ui.color("FATAL: Please supply the node name or IP address.", :red)}"
66
80
  end
67
- @slid = @node.tags.select { |s| s =~ /^slid=/ }.reduce.gsub('slid=', '').to_i
68
- @instance = connection.servers.get(@slid)
69
-
70
- @node.nil? and raise "#{ui.color('Chef node not found!', :red)}"
71
- @instance.nil? and raise "#{ui.color('VM instance with IP: ' + config[:ip_address] +' not found!', :red)}"
72
-
73
81
 
74
82
  begin
75
- begin
76
- destroy_item(Chef::Node, @node.name, "node")
77
- puts ui.color("Chef node successfully deleted.", :green)
78
- rescue Exception => e
79
- err_msg ui.color("ERROR DELETING CHEF NODE", :red)
80
- err_msg ui.color(e.message, :yellow)
81
- err_msg ui.color(e.backtrace, :yellow)
82
- end
83
+ if @node
84
+ begin
85
+ destroy_item(Chef::Node, @node.name, "node")
86
+ puts ui.color("Chef node successfully deleted.", :green)
87
+ rescue Exception => e
88
+ err_msg ui.color("ERROR DELETING CHEF NODE", :red)
89
+ err_msg ui.color(e.message, :yellow)
90
+ err_msg ui.color(e.backtrace.join("\n"), :yellow)
91
+ end
83
92
 
84
- begin
85
- destroy_item(Chef::ApiClient, @node.name, "client")
86
- puts ui.color("Chef client successfully deleted.", :green)
87
- rescue Exception => e
88
- err_msg ui.color("ERROR DELETING CHEF CLIENT", :red)
89
- err_msg ui.color(e.message, :yellow)
90
- err_msg ui.color(e.backtrace, :yellow)
93
+ begin
94
+ destroy_item(Chef::ApiClient, @node.name, "client")
95
+ puts ui.color("Chef client successfully deleted.", :green)
96
+ rescue Exception => e
97
+ err_msg ui.color("ERROR DELETING CHEF CLIENT", :red)
98
+ err_msg ui.color(e.message, :yellow)
99
+ err_msg ui.color(e.backtrace.join("\n"), :yellow)
100
+ end
101
+ else
102
+ "#{ui.color('Chef node: ' + config[:chef_node_name] +' not found! will destroy instance.', :red)}"
91
103
  end
92
104
 
93
105
  begin
@@ -96,7 +108,7 @@ class Chef
96
108
  rescue Exception => e
97
109
  err_msg ui.color("ERROR DELETING SOFTLAYER VM. IT'S POSSIBLE YOU ARE STILL BEING BILLED FOR THIS INSTANCE. PLEASE CONTACT SUPPORT FOR FURTHER ASSISTANCE", :red)
98
110
  err_msg ui.color(e.message, :yellow)
99
- err_msg ui.color(e.backtrace, :yellow)
111
+ err_msg ui.color(e.backtrace.join("\n"), :yellow)
100
112
  end
101
113
  ensure
102
114
  unless err_msg.empty?
@@ -0,0 +1,27 @@
1
+ require 'chef/knife/softlayer_base'
2
+ require 'chef/search/query'
3
+ require 'chef/api_client'
4
+
5
+ class Chef
6
+ class Knife
7
+ class SoftlayerServerList < Knife
8
+
9
+ include Knife::SoftlayerBase
10
+
11
+ banner 'knife softlayer server list (options)'
12
+
13
+ ##
14
+ # Run the procedure to list all of the Softlayer VM's
15
+ # @return [nil]
16
+ def run
17
+
18
+ $stdout.sync = true
19
+ fmt = "%-20s %-8s %-15s %-15s %-10s"
20
+ puts ui.color(sprintf(fmt, "Name", "Location", "Public IP", "Private IP", "Status"), :green)
21
+ connection.servers.each do |server|
22
+ puts sprintf fmt, server.name, server.datacenter, server.public_ip_address, server.private_ip_address, server.created_at ? 'Running' : 'Starting'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -7,6 +7,108 @@
7
7
 
8
8
  require 'chef/knife/softlayer_base'
9
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
+ ##
25
+ # Run the procedure to list softlayer VM flavors or display all available options.
26
+ # @return [nil]
27
+ def run
28
+ $stdout.sync = true
29
+ if name_args.count < 1
30
+ ui.fatal("Server relaunch requires AT LEAST ONE node name.")
31
+ exit 1;
32
+ end
33
+
34
+ ident_file = Chef::Config[:knife][:identity_file] || config[:identity_file]
35
+ Fog.credentials[:private_key_path] = ident_file if ident_file
36
+
37
+ Chef::Search::Query.new.search(:node, "name:#{name_args[0]}") do |object|
38
+ @vm = connection.servers.select { |s| s.public_ip == object.ipaddress }.first
39
+ end
40
+ ui.fatal("Server not found on SoftLayer account.") and exit 1 unless @vm
41
+
42
+ unless @vm.sshable?
43
+ ui.fatal("Node with name #{name_args[0]} not sshable, relaunch canceled.")
44
+ exit 1
45
+ end
46
+
47
+ # grab the contents of /etc/chef from the target node and stash a local copy
48
+ begin
49
+ puts ui.color("Capturing existing node configuration files.", :green)
50
+ @vm.scp_download("/etc/chef", "/tmp/#{@vm.id}/", :recursive => true)
51
+ rescue Exception => e
52
+ puts ui.color(e.message, :red)
53
+ ui.fatal('Relaunch canceled.')
54
+ exit 1
55
+ end
56
+
57
+ begin
58
+ puts ui.color("Relaunching SoftLayer server, this may take a few minutes.", :green)
59
+ @vm.relaunch!
60
+ @vm.wait_for { putc '.'; ready? && sshable? }
61
+ puts ''
62
+ rescue Exception => e
63
+ puts ui.color(e.message, :red)
64
+ ui.fatal('Relaunch FAILED. You may be missing a server.')
65
+ exit 1
66
+ end
67
+
68
+ # push the locally stashed config items up to new machine
69
+ begin
70
+ puts ui.color("Installing node configuration on relaunched server.", :green)
71
+ @vm.scp("/tmp/#{@vm.id}/chef/", "/etc/", :recursive => true)
72
+ rescue Exception => e
73
+ puts ui.color(e.message, :red)
74
+ ui.fatal('Relaunch FAILED. You may be missing a chef node.')
75
+ exit 1
76
+ end
77
+
78
+ begin
79
+ puts ui.color("Installing chef-client executable on relaunched server.", :green)
80
+ puts @vm.ssh('wget https://www.chef.io/chef/install.sh && sudo bash ./install.sh && rm install.sh').first.stdout
81
+ rescue Exception => e
82
+ puts ui.color(e.message, :red)
83
+ ui.fatal('Relaunch FAILED. You may be missing a chef node.')
84
+ exit 1
85
+ end
86
+
87
+ # run chef-client on the new machine with the existing config and attributes
88
+ begin
89
+ puts ui.color("Initial run of chef-client on relaunched server, this may take a few minutes.", :green)
90
+ puts @vm.ssh('sudo chef-client').first.stdout
91
+ rescue Exception => e
92
+ puts ui.color(e.message, :red)
93
+ ui.fatal('Relaunch FAILED on chef run. Your chef node may be misconfigured.')
94
+ exit 1
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+
103
+ #
104
+ # Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
105
+ # © Copyright IBM Corporation 2014.
106
+ #
107
+ # LICENSE: Apache 2.0 (http://www.apache.org/licenses/)
108
+ #
109
+
110
+ require 'chef/knife/softlayer_base'
111
+
10
112
  class Chef
11
113
  class Knife
12
114
  class SoftlayerServerRelaunch < Knife
@@ -7,6 +7,6 @@
7
7
 
8
8
  module Knife
9
9
  module Softlayer
10
- VERSION = "0.3.12"
10
+ VERSION = "0.4.0"
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-softlayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.4.0
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-22 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-softlayer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.29
19
+ version: 0.3.30
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.29
26
+ version: 0.3.30
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: knife-windows
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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_list.rb
194
195
  - lib/chef/knife/softlayer_server_relaunch.rb
195
196
  - lib/chef/knife/softlayer_vlan_create.rb
196
197
  - lib/chef/knife/softlayer_vlan_list.rb