knife-softlayer 0.1.3 → 0.2.0.pre.f0ba31b95
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/knife-softlayer.gemspec +1 -1
- data/lib/chef/knife/flavor/base.rb +9 -134
- data/lib/chef/knife/softlayer_base.rb +31 -95
- data/lib/chef/knife/softlayer_datacenter_list.rb +28 -0
- data/lib/chef/knife/softlayer_datacenter_show.rb +45 -0
- data/lib/chef/knife/softlayer_flavor_list.rb +16 -7
- data/lib/chef/knife/softlayer_global_ip_list.rb +34 -0
- data/lib/chef/knife/softlayer_image_list.rb +26 -0
- data/lib/chef/knife/softlayer_server_create.rb +170 -77
- data/lib/chef/knife/softlayer_server_destroy.rb +5 -6
- data/lib/chef/knife/softlayer_vlan_create.rb +42 -0
- data/lib/chef/knife/softlayer_vlan_list.rb +28 -0
- data/lib/chef/knife/softlayer_vlan_show.rb +40 -0
- data/lib/knife-softlayer/version.rb +1 -1
- data/spec/unit/softlayer_base_spec.rb +5 -4
- data/spec/unit/softlayer_server_create_spec.rb +52 -84
- data/spec/unit/softlayer_server_destroy_spec.rb +29 -53
- metadata +14 -7
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -7,17 +7,18 @@
|
|
7
7
|
|
8
8
|
require File.expand_path('../../spec_helper', __FILE__)
|
9
9
|
require 'chef/knife/bootstrap'
|
10
|
-
require '
|
10
|
+
require 'fog/softlayer'
|
11
|
+
Fog.mock!
|
11
12
|
|
12
13
|
|
13
14
|
describe Chef::Knife::SoftlayerBase do
|
14
15
|
|
15
16
|
describe "connection" do
|
16
|
-
it "should
|
17
|
+
it "should successfully create a connection using fog" do
|
17
18
|
Chef::Config[:knife][:softlayer_username] = 'username'
|
18
19
|
Chef::Config[:knife][:softlayer_api_key] = 'key'
|
19
|
-
|
20
|
-
|
20
|
+
Chef::Knife::SoftlayerServerCreate.new.connection
|
21
|
+
Chef::Knife::SoftlayerServerCreate.new.connection.should be_a(Fog::Compute::Softlayer::Mock)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
@@ -7,128 +7,96 @@
|
|
7
7
|
|
8
8
|
require File.expand_path('../../spec_helper', __FILE__)
|
9
9
|
require 'chef/knife/bootstrap'
|
10
|
-
require '
|
10
|
+
require 'fog/softlayer'
|
11
|
+
Fog.mock!
|
11
12
|
|
12
13
|
|
13
14
|
describe Chef::Knife::SoftlayerServerCreate do
|
14
15
|
before(:each) do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
'maxCpu' => 4,
|
29
|
-
'maxCpuUnits' => 'CORE',
|
30
|
-
'maxMemory' => 4096,
|
31
|
-
'metricPollDate' => nil,
|
32
|
-
'modifyDate' => nil,
|
33
|
-
'startCpus' => 4,
|
34
|
-
'statusId' => 1001,
|
35
|
-
'globalIdentifier' => '93f3bfb6-3f48-4e9c-82ab-25e8b5dd14ce'
|
36
|
-
})
|
37
|
-
|
38
|
-
@softlayer_servers = double("servers")
|
39
|
-
@cci = double("cci")
|
40
|
-
|
41
|
-
@softlayer_server_attribs = { :id => '1234567',
|
42
|
-
:public_ip_address => '33.33.33.33',
|
43
|
-
:private_dns_name => 'example.com',
|
44
|
-
:private_ip_address => '10.10.10.10',
|
45
|
-
}
|
46
|
-
|
47
|
-
@softlayer_server_attribs.each_pair do |attrib, value|
|
48
|
-
@cci.stub(attrib).and_return(value)
|
49
|
-
end
|
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'
|
50
29
|
end
|
51
30
|
|
52
31
|
describe "go-wrong cases for .run" do
|
53
32
|
it "should raise an exception if we try to create/bootstrap a windows instance" do
|
54
|
-
@
|
55
|
-
expect { @
|
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
|
+
[':ram', ':cores', ':hostname', ':domain', ':datacenter', ':os_code', ':block_storage'].each do |opt|
|
38
|
+
class_eval <<EOS, __FILE__, __LINE__
|
39
|
+
it "should should raise an ArgumentError if missing #{opt} option" do
|
40
|
+
@server_create.config.delete(#{opt})
|
41
|
+
expect { @server_create.run }.to raise_exception(ArgumentError)
|
42
|
+
end
|
43
|
+
EOS
|
56
44
|
end
|
57
45
|
end
|
58
46
|
|
59
47
|
describe "go-right cases for .run" do
|
60
48
|
before do
|
61
|
-
@
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@cci.should_receive(:[]).with('primaryIpAddress').and_return('33.33.33.33')
|
66
|
-
|
67
|
-
@public_ip = "33.33.33.33"
|
68
|
-
SoftLayer::Service.should_receive(:new).twice.and_return(@softlayer_connection)
|
69
|
-
|
70
|
-
|
71
|
-
@knife_softlayer_create.stub(:puts)
|
72
|
-
@knife_softlayer_create.stub(:print)
|
73
|
-
{
|
74
|
-
:domain => 'example.com',
|
75
|
-
:hostname => 'test',
|
76
|
-
:flavor => 'medium',
|
77
|
-
:chef_node_name => 'test.example.com',
|
78
|
-
}.each do |key, value|
|
79
|
-
@knife_softlayer_create.config[key] = value
|
80
|
-
end
|
81
|
-
|
82
|
-
@bootstrap = Chef::Knife::Bootstrap.new
|
83
|
-
Chef::Knife::Bootstrap.stub(:new).and_return(@bootstrap)
|
84
|
-
@bootstrap.should_receive(:run)
|
49
|
+
@server_create.stub(:apply_tags).and_return(Proc.new{})
|
50
|
+
Chef::Knife::Bootstrap.any_instance.stub(:run)
|
51
|
+
Fog::Compute::Softlayer::Server.any_instance.stub(:ready?).and_return(true)
|
52
|
+
Fog::Compute::Softlayer::Server.any_instance.stub(:sshable?).and_return(true)
|
85
53
|
end
|
86
54
|
|
87
55
|
it "defaults to a distro of 'chef-full' for a linux instance" do
|
88
|
-
@
|
89
|
-
@
|
90
|
-
|
56
|
+
@server_create.config[:distro] = @server_create.options[:distro][:default]
|
57
|
+
bootstrap = @server_create.linux_bootstrap(double('instance', :id => 42, :ssh_ip_address => '3.3.3.3', :private_ip_address => '3.3.3.3'))
|
58
|
+
bootstrap.config[:distro].should == 'chef-full'
|
91
59
|
end
|
92
60
|
|
93
61
|
it "creates an VM instance and bootstraps it" do
|
94
|
-
@
|
95
|
-
@
|
62
|
+
@server_create.run
|
63
|
+
@server_create.connection.virtual_guests.count.should == 1
|
96
64
|
end
|
97
65
|
|
98
66
|
it "sets ssh_user value by using -x option" do
|
99
|
-
#
|
100
|
-
@
|
67
|
+
#default value of config[:ssh_user] is root
|
68
|
+
@server_create.config[:ssh_user] = "tim-eah!"
|
101
69
|
|
102
|
-
@
|
103
|
-
@
|
104
|
-
@
|
70
|
+
@server_create.run
|
71
|
+
@server_create.config[:ssh_user].should == "tim-eah!"
|
72
|
+
@server_create.connection.virtual_guests.count.should == 1
|
105
73
|
end
|
106
74
|
|
107
75
|
it "sets ssh_password value by using -P option" do
|
108
76
|
# default value of config[:ssh_password] is nil
|
109
|
-
@
|
77
|
+
@server_create.config[:ssh_password] = "passw0rd"
|
110
78
|
|
111
|
-
@
|
112
|
-
@
|
113
|
-
@
|
79
|
+
@server_create.run
|
80
|
+
@server_create.config[:ssh_password].should == "passw0rd"
|
81
|
+
@server_create.connection.virtual_guests.count.should == 1
|
114
82
|
end
|
115
83
|
|
116
84
|
it "sets ssh_port value by using -p option" do
|
117
85
|
# default value of config[:ssh_port] is 22
|
118
|
-
@
|
86
|
+
@server_create.config[:ssh_port] = "86"
|
119
87
|
|
120
|
-
@
|
121
|
-
@
|
122
|
-
@
|
88
|
+
@server_create.run
|
89
|
+
@server_create.config[:ssh_port].should == "86"
|
90
|
+
@server_create.connection.virtual_guests.count.should == 1
|
123
91
|
end
|
124
92
|
|
125
93
|
it "sets identity_file value by using -i option for ssh bootstrap protocol or linux image" do
|
126
94
|
# default value of config[:identity_file] is nil
|
127
|
-
@
|
95
|
+
@server_create.config[:identity_file] = "~/.ssh/mah_key_file.pem"
|
128
96
|
|
129
|
-
@
|
130
|
-
@
|
131
|
-
@
|
97
|
+
@server_create.run
|
98
|
+
@server_create.config[:identity_file].should == "~/.ssh/mah_key_file.pem"
|
99
|
+
@server_create.connection.virtual_guests.count.should == 1
|
132
100
|
end
|
133
101
|
|
134
102
|
end
|
@@ -7,65 +7,41 @@
|
|
7
7
|
|
8
8
|
require File.expand_path('../../spec_helper', __FILE__)
|
9
9
|
require 'chef/knife/bootstrap'
|
10
|
-
require '
|
11
|
-
|
10
|
+
require 'fog/softlayer'
|
11
|
+
Fog.mock!
|
12
12
|
|
13
13
|
|
14
14
|
describe Chef::Knife::SoftlayerServerDestroy do
|
15
|
-
before do
|
16
|
-
|
15
|
+
before(:each) do
|
16
|
+
Chef::Config[:knife][:softlayer_username] = 'username'
|
17
|
+
Chef::Config[:knife][:softlayer_api_key] = 'key'
|
18
|
+
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
20
|
+
@attributes = {
|
21
|
+
:id => '1000001',
|
22
|
+
:name => '1000001',
|
23
|
+
:flavor_id => 'medium',
|
24
|
+
:fqdn => 'test.example.com',
|
25
|
+
:public_ip_address => '33.33.33.33',
|
26
|
+
:private_ip_address => '10.10.10.10',
|
27
|
+
:tags => ['slid=1000001']
|
28
|
+
}
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@softlayer_connection = double("connection", :createObject => {
|
36
|
-
'accountId' => 000001,
|
37
|
-
'createDate' => '2014-03-24T18:03:27-04:00',
|
38
|
-
'dedicatedAccountHostOnlyFlag' => false,
|
39
|
-
'domain' => 'example.com',
|
40
|
-
'fullyQualifiedDomainName' => 'test',
|
41
|
-
'hostname' =>"test",
|
42
|
-
'id' => 0000001,
|
43
|
-
'lastPowerStateId' => nil,
|
44
|
-
'lastVerifiedDate' => nil,
|
45
|
-
'maxCpu' => 4,
|
46
|
-
'maxCpuUnits' => 'CORE',
|
47
|
-
'maxMemory' => 4096,
|
48
|
-
'metricPollDate' => nil,
|
49
|
-
'modifyDate' => nil,
|
50
|
-
'startCpus' => 4,
|
51
|
-
'statusId' => 1001,
|
52
|
-
'globalIdentifier' => '93f3bfb6-3f48-4e9c-82ab-25e8b5dd14ce'
|
53
|
-
})
|
54
|
-
@softlayer_connection.stub(:findByIpAddress).and_return({ 'id' => 100001 })
|
55
|
-
@softlayer_connection.stub(:object_with_id).and_return(@softlayer_connection)
|
56
|
-
@softlayer_connection.stub(:deleteObject).and_return(true)
|
57
|
-
@knife_softlayer_destroy.ui.stub(:warn)
|
58
|
-
@knife_softlayer_destroy.node = double("node", :name => 'foo')
|
59
|
-
SoftLayer::Service.should_receive(:new).twice.and_return(@softlayer_connection)
|
60
|
-
end
|
30
|
+
@knife_softlayer_destroy = Chef::Knife::SoftlayerServerDestroy.new
|
31
|
+
@knife_softlayer_destroy.connection.virtual_guests = @vm_attributes
|
32
|
+
@knife_softlayer_destroy.node = double("node", @attributes)
|
33
|
+
@knife_softlayer_destroy.stub(:destroy_item)
|
34
|
+
instance = double(@attributes)
|
35
|
+
@knife_softlayer_destroy.stub_chain(:connection, :servers, :get).and_return(instance)
|
61
36
|
|
62
|
-
it "should be talking to the softlayer api and the chef server" do
|
63
|
-
Chef::Search::Query.stub(:new).and_return(double("query", :search => {}))
|
64
|
-
@knife_softlayer_destroy.config[:ip_address] = '33.33.33.33'
|
65
|
-
@softlayer_connection.should_receive(:findByIpAddress).with('33.33.33.33')
|
66
|
-
@softlayer_connection.should_receive(:deleteObject)
|
67
|
-
@knife_softlayer_destroy.run
|
68
|
-
end
|
69
37
|
|
70
38
|
end
|
39
|
+
|
40
|
+
it "should be talking to the softlayer api and the chef server" do
|
41
|
+
Chef::Search::Query.stub(:new).and_return(double("query", :search => {}))
|
42
|
+
@knife_softlayer_destroy.config[:ip_address] = '33.33.33.33'
|
43
|
+
@knife_softlayer_destroy.connection.servers.get.should_receive(:destroy)
|
44
|
+
@knife_softlayer_destroy.run
|
45
|
+
end
|
46
|
+
|
71
47
|
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.
|
4
|
+
version: 0.2.0.pre.f0ba31b95
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Eldridge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fog-softlayer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.3.14
|
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:
|
26
|
+
version: 0.3.14
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: knife-windows
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,11 +157,18 @@ files:
|
|
157
157
|
- lib/chef/knife/flavor/base.rb
|
158
158
|
- lib/chef/knife/softlayer.rb
|
159
159
|
- lib/chef/knife/softlayer_base.rb
|
160
|
+
- lib/chef/knife/softlayer_datacenter_list.rb
|
161
|
+
- lib/chef/knife/softlayer_datacenter_show.rb
|
160
162
|
- lib/chef/knife/softlayer_delete.rb
|
161
163
|
- lib/chef/knife/softlayer_flavor_list.rb
|
164
|
+
- lib/chef/knife/softlayer_global_ip_list.rb
|
165
|
+
- lib/chef/knife/softlayer_image_list.rb
|
162
166
|
- lib/chef/knife/softlayer_list.rb
|
163
167
|
- lib/chef/knife/softlayer_server_create.rb
|
164
168
|
- lib/chef/knife/softlayer_server_destroy.rb
|
169
|
+
- lib/chef/knife/softlayer_vlan_create.rb
|
170
|
+
- lib/chef/knife/softlayer_vlan_list.rb
|
171
|
+
- lib/chef/knife/softlayer_vlan_show.rb
|
165
172
|
- lib/knife-softlayer/version.rb
|
166
173
|
- spec/spec_helper.rb
|
167
174
|
- spec/unit/softlayer_base_spec.rb
|
@@ -182,9 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
189
|
version: '0'
|
183
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
191
|
requirements:
|
185
|
-
- - ! '
|
192
|
+
- - ! '>'
|
186
193
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
194
|
+
version: 1.3.1
|
188
195
|
requirements: []
|
189
196
|
rubyforge_project:
|
190
197
|
rubygems_version: 2.2.2
|