knife-softlayer 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +19 -19
  3. data/.travis.yml +20 -20
  4. data/CHANGELOG.md +19 -19
  5. data/CONTRIBUTING.md +31 -31
  6. data/CONTRIBUTORS.md +2 -2
  7. data/Gemfile +4 -4
  8. data/LICENSE.txt +72 -72
  9. data/README.md +83 -83
  10. data/Rakefile +37 -37
  11. data/docs/cla-corporate.md +133 -133
  12. data/docs/cla-individual.md +84 -84
  13. data/examples/datacenter.md +94 -94
  14. data/examples/flavor.md +58 -58
  15. data/examples/global_ip.md +22 -22
  16. data/examples/image.md +34 -34
  17. data/examples/key_pair.md +56 -56
  18. data/examples/server.md +82 -82
  19. data/examples/vlan.md +85 -85
  20. data/knife-softlayer.gemspec +39 -39
  21. data/lib/chef/knife/flavor/base.rb +52 -52
  22. data/lib/chef/knife/softlayer.rb +14 -14
  23. data/lib/chef/knife/softlayer_base.rb +112 -112
  24. data/lib/chef/knife/softlayer_datacenter_list.rb +28 -28
  25. data/lib/chef/knife/softlayer_datacenter_show.rb +45 -45
  26. data/lib/chef/knife/softlayer_delete.rb +6 -6
  27. data/lib/chef/knife/softlayer_flavor_list.rb +53 -53
  28. data/lib/chef/knife/softlayer_global_ip_list.rb +34 -34
  29. data/lib/chef/knife/softlayer_image_list.rb +26 -26
  30. data/lib/chef/knife/softlayer_key_pair_create.rb +37 -37
  31. data/lib/chef/knife/softlayer_key_pair_list.rb +28 -28
  32. data/lib/chef/knife/softlayer_list.rb +6 -6
  33. data/lib/chef/knife/softlayer_server_create.rb +462 -458
  34. data/lib/chef/knife/softlayer_server_destroy.rb +146 -146
  35. data/lib/chef/knife/softlayer_server_list.rb +27 -27
  36. data/lib/chef/knife/softlayer_server_relaunch.rb +208 -208
  37. data/lib/chef/knife/softlayer_vlan_create.rb +37 -37
  38. data/lib/chef/knife/softlayer_vlan_list.rb +28 -28
  39. data/lib/chef/knife/softlayer_vlan_show.rb +40 -40
  40. data/lib/knife-softlayer/version.rb +12 -12
  41. data/spec/spec_helper.rb +21 -21
  42. data/spec/unit/softlayer_base_spec.rb +26 -26
  43. data/spec/unit/softlayer_server_create_spec.rb +105 -105
  44. data/spec/unit/softlayer_server_destroy_spec.rb +47 -47
  45. metadata +27 -27
@@ -1,37 +1,37 @@
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 SoftlayerVlanCreate < Knife
13
-
14
- include Knife::SoftlayerBase
15
-
16
- banner 'knife softlayer vlan create'
17
-
18
- def run
19
-
20
- $stdout.sync = true
21
-
22
- opts = {
23
- :name => ui.ask_question("Enter a vlan name: "),
24
- :datacenter => connection(:network).datacenters.by_name(ui.ask_question("Enter a datacenter name: ")),
25
- :router => {'hostname' => ui.ask_question("Enter a router hostname: ")},
26
- :network_space => ui.ask_question("Enter a network space: ", :default => 'PUBLIC'),
27
- }
28
-
29
- vlan = connection(:network).networks.create(opts)
30
-
31
- !!vlan and puts "#{ui.color("VLAN successfully created. Provisioning may take a few minutes to complete.", :green)}"
32
-
33
- end
34
-
35
- end
36
- end
37
- end
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 SoftlayerVlanCreate < Knife
13
+
14
+ include Knife::SoftlayerBase
15
+
16
+ banner 'knife softlayer vlan create'
17
+
18
+ def run
19
+
20
+ $stdout.sync = true
21
+
22
+ opts = {
23
+ :name => ui.ask_question("Enter a vlan name: "),
24
+ :datacenter => connection(:network).datacenters.by_name(ui.ask_question("Enter a datacenter name: ")),
25
+ :router => {'hostname' => ui.ask_question("Enter a router hostname: ")},
26
+ :network_space => ui.ask_question("Enter a network space: ", :default => 'PUBLIC'),
27
+ }
28
+
29
+ vlan = connection(:network).networks.create(opts)
30
+
31
+ !!vlan and puts "#{ui.color("VLAN successfully created. Provisioning may take a few minutes to complete.", :green)}"
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -1,28 +1,28 @@
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 SoftlayerVlanList < Knife
13
-
14
- include Knife::SoftlayerBase
15
-
16
- banner 'knife softlayer vlan list (options)'
17
-
18
- def run
19
- $stdout.sync = true
20
- table_data = connection(:network).networks.map do |net|
21
- {:id => net.id, :name => net.name ? net.name : '[none]', :datacenter => net.datacenter.long_name, :network_space => net.network_space, :router => net.router['hostname'] }
22
- end
23
- puts Formatador.display_table(table_data, [:id, :name, :datacenter, :network_space, :router])
24
- end
25
-
26
- end
27
- end
28
- end
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 SoftlayerVlanList < Knife
13
+
14
+ include Knife::SoftlayerBase
15
+
16
+ banner 'knife softlayer vlan list (options)'
17
+
18
+ def run
19
+ $stdout.sync = true
20
+ table_data = connection(:network).networks.map do |net|
21
+ {:id => net.id, :name => net.name ? net.name : '[none]', :datacenter => net.datacenter.long_name, :network_space => net.network_space, :router => net.router['hostname'] }
22
+ end
23
+ puts Formatador.display_table(table_data, [:id, :name, :datacenter, :network_space, :router])
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -1,40 +1,40 @@
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 SoftlayerVlanShow < Knife
13
-
14
- include Knife::SoftlayerBase
15
-
16
- banner 'knife softlayer vlan show ID (options)'
17
-
18
- def run
19
- unless name_args.size == 1
20
- puts ui.color("Specify exactly one vlan to show.", :red)
21
- show_usage
22
- exit 1
23
- end
24
-
25
- $stdout.sync = true
26
- vlan = connection(:network).networks.get(name_args[0])
27
-
28
- puts "#{ui.color("ID:", :green)} #{vlan.id}"
29
- puts "#{ui.color("Name:", :green)} #{vlan.name ? vlan.name : '[none]'}"
30
- puts "#{ui.color("Datacenter:", :green)} #{vlan.datacenter.name}"
31
- puts "#{ui.color("Network Space:", :green)} #{vlan.network_space}"
32
- puts "#{ui.color("Router:", :green)} #{vlan.router['hostname']}"
33
- puts "#{ui.color("Subnets:", :green)}"
34
- puts Formatador.display_table(vlan.subnets.map { |s| s.attributes.reject { |k,v| k.is_a?(String) } }, [:id, :cidr, :gateway_ip, :network_id, :broadcast, :type, :datacenter, :ip_version])
35
-
36
- end
37
-
38
- end
39
- end
40
- end
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 SoftlayerVlanShow < Knife
13
+
14
+ include Knife::SoftlayerBase
15
+
16
+ banner 'knife softlayer vlan show ID (options)'
17
+
18
+ def run
19
+ unless name_args.size == 1
20
+ puts ui.color("Specify exactly one vlan to show.", :red)
21
+ show_usage
22
+ exit 1
23
+ end
24
+
25
+ $stdout.sync = true
26
+ vlan = connection(:network).networks.get(name_args[0])
27
+
28
+ puts "#{ui.color("ID:", :green)} #{vlan.id}"
29
+ puts "#{ui.color("Name:", :green)} #{vlan.name ? vlan.name : '[none]'}"
30
+ puts "#{ui.color("Datacenter:", :green)} #{vlan.datacenter.name}"
31
+ puts "#{ui.color("Network Space:", :green)} #{vlan.network_space}"
32
+ puts "#{ui.color("Router:", :green)} #{vlan.router['hostname']}"
33
+ puts "#{ui.color("Subnets:", :green)}"
34
+ puts Formatador.display_table(vlan.subnets.map { |s| s.attributes.reject { |k,v| k.is_a?(String) } }, [:id, :cidr, :gateway_ip, :network_id, :broadcast, :type, :datacenter, :ip_version])
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -1,12 +1,12 @@
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
- module Knife
9
- module Softlayer
10
- VERSION = "0.4.5"
11
- end
12
- end
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
+ module Knife
9
+ module Softlayer
10
+ VERSION = "0.4.6"
11
+ end
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,21 +1,21 @@
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
- $:.unshift File.expand_path('../../lib', __FILE__)
9
- require 'chef'
10
- require 'chef/knife/winrm_base'
11
- require 'chef/knife/softlayer_server_create'
12
- require 'chef/knife/softlayer_server_destroy'
13
-
14
- # Clear config between each example
15
- # to avoid dependencies between examples
16
- RSpec.configure do |c|
17
- c.before(:each) do
18
- Chef::Config.reset
19
- Chef::Config[:knife] ={}
20
- end
21
- end
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
+ $:.unshift File.expand_path('../../lib', __FILE__)
9
+ require 'chef'
10
+ require 'chef/knife/winrm_base'
11
+ require 'chef/knife/softlayer_server_create'
12
+ require 'chef/knife/softlayer_server_destroy'
13
+
14
+ # Clear config between each example
15
+ # to avoid dependencies between examples
16
+ RSpec.configure do |c|
17
+ c.before(:each) do
18
+ Chef::Config.reset
19
+ Chef::Config[:knife] ={}
20
+ end
21
+ end
@@ -1,26 +1,26 @@
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 File.expand_path('../../spec_helper', __FILE__)
9
- require 'chef/knife/bootstrap'
10
- require 'fog/softlayer'
11
- Fog.mock!
12
-
13
-
14
- describe Chef::Knife::SoftlayerBase do
15
-
16
- describe "connection" do
17
- it "should successfully create a connection using fog" do
18
- Chef::Config[:knife][:softlayer_username] = 'username'
19
- Chef::Config[:knife][:softlayer_api_key] = 'key'
20
- Chef::Knife::SoftlayerServerCreate.new.connection
21
- Chef::Knife::SoftlayerServerCreate.new.connection.should be_a(Fog::Compute::Softlayer::Mock)
22
- end
23
- end
24
-
25
-
26
- end
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 File.expand_path('../../spec_helper', __FILE__)
9
+ require 'chef/knife/bootstrap'
10
+ require 'fog/softlayer'
11
+ Fog.mock!
12
+
13
+
14
+ describe Chef::Knife::SoftlayerBase do
15
+
16
+ describe "connection" do
17
+ it "should successfully create a connection using fog" do
18
+ Chef::Config[:knife][:softlayer_username] = 'username'
19
+ Chef::Config[:knife][:softlayer_api_key] = 'key'
20
+ Chef::Knife::SoftlayerServerCreate.new.connection
21
+ Chef::Knife::SoftlayerServerCreate.new.connection.should be_a(Fog::Compute::Softlayer::Mock)
22
+ end
23
+ end
24
+
25
+
26
+ end
@@ -1,105 +1,105 @@
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 File.expand_path('../../spec_helper', __FILE__)
9
- require 'chef/knife/bootstrap'
10
- require 'fog/softlayer'
11
- Fog.mock!
12
-
13
-
14
- describe Chef::Knife::SoftlayerServerCreate do
15
- before(:each) do
16
- Chef::Config[:knife][:softlayer_username] = 'username'
17
- Chef::Config[:knife][:softlayer_api_key] = 'key'
18
-
19
- @server_create = Chef::Knife::SoftlayerServerCreate.new
20
- @server_create.stub(:tcp_test_ssh).and_return(true)
21
-
22
- @server_create.config[:ram] = 4096
23
- @server_create.config[:cores] = 4
24
- @server_create.config[:hostname] = 'test'
25
- @server_create.config[:domain] = 'ibm.com'
26
- @server_create.config[:datacenter] = 'hkg02'
27
- @server_create.config[:os_code] = 'UBUNTU_LATEST'
28
- @server_create.config[:block_storage] = '0:100'
29
- end
30
-
31
- describe "go-wrong cases for .run" do
32
- it "should raise an exception if we try to create/bootstrap a windows instance" do
33
- @server_create.config[:os_code] = 'WIN_2012-STD_64'
34
- expect { @server_create.run }.to raise_exception(Chef::Knife::SoftlayerServerCreateError)
35
- end
36
-
37
-
38
- [':ram', ':cores', ':hostname', ':domain', ':datacenter', ':os_code', ':block_storage'].each do |opt|
39
- class_eval <<EOS, __FILE__, __LINE__
40
- it "should should raise an exception if missing #{opt} option" do
41
- @server_create.config.delete(#{opt})
42
- expect { @server_create.run }.to raise_exception
43
- end
44
- EOS
45
- end
46
- end
47
-
48
- describe "go-right cases for .run" do
49
- before do
50
- @server_create.stub(:apply_tags).and_return(Proc.new{})
51
- Chef::Knife::Bootstrap.any_instance.stub(:run)
52
- Fog::Compute::Softlayer::Server.any_instance.stub(:ready?).and_return(true)
53
- Fog::Compute::Softlayer::Server.any_instance.stub(:sshable?).and_return(true)
54
- end
55
-
56
- it "defaults to a distro of 'chef-full' for a linux instance" do
57
- @server_create.config[:distro] = @server_create.options[:distro][:default]
58
- bootstrap = @server_create.linux_bootstrap(double('instance', :id => 42, :ssh_ip_address => '3.3.3.3', :private_ip_address => '3.3.3.3'))
59
- bootstrap.config[:distro].should == 'chef-full'
60
- end
61
-
62
- it "creates an VM instance and bootstraps it" do
63
- @server_create.run
64
- @server_create.connection.virtual_guests.count.should == 1
65
- end
66
-
67
- it "sets ssh_user value by using -x option" do
68
- #default value of config[:ssh_user] is root
69
- @server_create.config[:ssh_user] = "tim-eah!"
70
-
71
- @server_create.run
72
- @server_create.config[:ssh_user].should == "tim-eah!"
73
- @server_create.connection.virtual_guests.count.should == 1
74
- end
75
-
76
- it "sets ssh_password value by using -P option" do
77
- # default value of config[:ssh_password] is nil
78
- @server_create.config[:ssh_password] = "passw0rd"
79
-
80
- @server_create.run
81
- @server_create.config[:ssh_password].should == "passw0rd"
82
- @server_create.connection.virtual_guests.count.should == 1
83
- end
84
-
85
- it "sets ssh_port value by using -p option" do
86
- # default value of config[:ssh_port] is 22
87
- @server_create.config[:ssh_port] = "86"
88
-
89
- @server_create.run
90
- @server_create.config[:ssh_port].should == "86"
91
- @server_create.connection.virtual_guests.count.should == 1
92
- end
93
-
94
- it "sets identity_file value by using -i option for ssh bootstrap protocol or linux image" do
95
- # default value of config[:identity_file] is nil
96
- @server_create.config[:identity_file] = "~/.ssh/mah_key_file.pem"
97
-
98
- @server_create.run
99
- @server_create.config[:identity_file].should == "~/.ssh/mah_key_file.pem"
100
- @server_create.connection.virtual_guests.count.should == 1
101
- end
102
-
103
- end
104
-
105
- end
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 File.expand_path('../../spec_helper', __FILE__)
9
+ require 'chef/knife/bootstrap'
10
+ require 'fog/softlayer'
11
+ Fog.mock!
12
+
13
+
14
+ describe Chef::Knife::SoftlayerServerCreate do
15
+ before(:each) do
16
+ Chef::Config[:knife][:softlayer_username] = 'username'
17
+ Chef::Config[:knife][:softlayer_api_key] = 'key'
18
+
19
+ @server_create = Chef::Knife::SoftlayerServerCreate.new
20
+ @server_create.stub(:tcp_test_ssh).and_return(true)
21
+
22
+ @server_create.config[:ram] = 4096
23
+ @server_create.config[:cores] = 4
24
+ @server_create.config[:hostname] = 'test'
25
+ @server_create.config[:domain] = 'ibm.com'
26
+ @server_create.config[:datacenter] = 'hkg02'
27
+ @server_create.config[:os_code] = 'UBUNTU_LATEST'
28
+ @server_create.config[:block_storage] = '0:100'
29
+ end
30
+
31
+ describe "go-wrong cases for .run" do
32
+ it "should raise an exception if we try to create/bootstrap a windows instance" do
33
+ @server_create.config[:os_code] = 'WIN_2012-STD_64'
34
+ expect { @server_create.run }.to raise_exception(Chef::Knife::SoftlayerServerCreateError)
35
+ end
36
+
37
+
38
+ [':ram', ':cores', ':hostname', ':domain', ':datacenter', ':os_code', ':block_storage'].each do |opt|
39
+ class_eval <<EOS, __FILE__, __LINE__
40
+ it "should should raise an exception if missing #{opt} option" do
41
+ @server_create.config.delete(#{opt})
42
+ expect { @server_create.run }.to raise_exception
43
+ end
44
+ EOS
45
+ end
46
+ end
47
+
48
+ describe "go-right cases for .run" do
49
+ before do
50
+ @server_create.stub(:apply_tags).and_return(Proc.new{})
51
+ Chef::Knife::Bootstrap.any_instance.stub(:run)
52
+ Fog::Compute::Softlayer::Server.any_instance.stub(:ready?).and_return(true)
53
+ Fog::Compute::Softlayer::Server.any_instance.stub(:sshable?).and_return(true)
54
+ end
55
+
56
+ it "defaults to a distro of 'chef-full' for a linux instance" do
57
+ @server_create.config[:distro] = @server_create.options[:distro][:default]
58
+ bootstrap = @server_create.linux_bootstrap(double('instance', :id => 42, :ssh_ip_address => '3.3.3.3', :private_ip_address => '3.3.3.3'))
59
+ bootstrap.config[:distro].should == 'chef-full'
60
+ end
61
+
62
+ it "creates an VM instance and bootstraps it" do
63
+ @server_create.run
64
+ @server_create.connection.virtual_guests.count.should == 1
65
+ end
66
+
67
+ it "sets ssh_user value by using -x option" do
68
+ #default value of config[:ssh_user] is root
69
+ @server_create.config[:ssh_user] = "tim-eah!"
70
+
71
+ @server_create.run
72
+ @server_create.config[:ssh_user].should == "tim-eah!"
73
+ @server_create.connection.virtual_guests.count.should == 1
74
+ end
75
+
76
+ it "sets ssh_password value by using -P option" do
77
+ # default value of config[:ssh_password] is nil
78
+ @server_create.config[:ssh_password] = "passw0rd"
79
+
80
+ @server_create.run
81
+ @server_create.config[:ssh_password].should == "passw0rd"
82
+ @server_create.connection.virtual_guests.count.should == 1
83
+ end
84
+
85
+ it "sets ssh_port value by using -p option" do
86
+ # default value of config[:ssh_port] is 22
87
+ @server_create.config[:ssh_port] = "86"
88
+
89
+ @server_create.run
90
+ @server_create.config[:ssh_port].should == "86"
91
+ @server_create.connection.virtual_guests.count.should == 1
92
+ end
93
+
94
+ it "sets identity_file value by using -i option for ssh bootstrap protocol or linux image" do
95
+ # default value of config[:identity_file] is nil
96
+ @server_create.config[:identity_file] = "~/.ssh/mah_key_file.pem"
97
+
98
+ @server_create.run
99
+ @server_create.config[:identity_file].should == "~/.ssh/mah_key_file.pem"
100
+ @server_create.connection.virtual_guests.count.should == 1
101
+ end
102
+
103
+ end
104
+
105
+ end