knife-oraclecloud 1.0.0

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.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +12 -0
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +248 -0
  9. data/Rakefile +6 -0
  10. data/knife-oraclecloud.gemspec +28 -0
  11. data/lib/chef/knife/cloud/oraclecloud_service.rb +206 -0
  12. data/lib/chef/knife/cloud/oraclecloud_service_helpers.rb +48 -0
  13. data/lib/chef/knife/cloud/oraclecloud_service_options.rb +58 -0
  14. data/lib/chef/knife/oraclecloud_image_list.rb +63 -0
  15. data/lib/chef/knife/oraclecloud_orchestration_delete.rb +51 -0
  16. data/lib/chef/knife/oraclecloud_orchestration_list.rb +65 -0
  17. data/lib/chef/knife/oraclecloud_orchestration_show.rb +64 -0
  18. data/lib/chef/knife/oraclecloud_server_create.rb +105 -0
  19. data/lib/chef/knife/oraclecloud_server_delete.rb +48 -0
  20. data/lib/chef/knife/oraclecloud_server_list.rb +67 -0
  21. data/lib/chef/knife/oraclecloud_server_show.rb +52 -0
  22. data/lib/chef/knife/oraclecloud_shape_list.rb +51 -0
  23. data/lib/knife-oraclecloud/version.rb +21 -0
  24. data/spec/spec_helper.rb +17 -0
  25. data/spec/unit/cloud/oraclecloud_service_helpers_spec.rb +94 -0
  26. data/spec/unit/cloud/oraclecloud_service_spec.rb +386 -0
  27. data/spec/unit/oraclecloud_image_list_spec.rb +39 -0
  28. data/spec/unit/oraclecloud_orchestration_delete_spec.rb +59 -0
  29. data/spec/unit/oraclecloud_orchestration_list_spec.rb +56 -0
  30. data/spec/unit/oraclecloud_orchestration_show_spec.rb +96 -0
  31. data/spec/unit/oraclecloud_server_create_spec.rb +118 -0
  32. data/spec/unit/oraclecloud_server_delete_spec.rb +40 -0
  33. data/spec/unit/oraclecloud_server_list_spec.rb +59 -0
  34. data/spec/unit/oraclecloud_server_show_spec.rb +57 -0
  35. data/spec/unit/oraclecloud_shape_list_spec.rb +39 -0
  36. metadata +161 -0
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_image_list'
21
+ require 'support/shared_examples_for_command'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudImageList do
24
+ let(:command) { described_class.new }
25
+ let(:service) { double('service') }
26
+
27
+ before do
28
+ allow(command).to receive(:service).and_return(service)
29
+ end
30
+
31
+ it_behaves_like Chef::Knife::Cloud::Command, described_class.new
32
+
33
+ describe '#query_resource' do
34
+ it 'calls list_images' do
35
+ expect(service).to receive(:list_images)
36
+ command.query_resource
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,59 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_orchestration_delete'
21
+ require 'support/shared_examples_for_command'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudOrchestrationDelete do
24
+ let(:command) { described_class.new(%w(orch1 orch2)) }
25
+ let(:service) { double('service') }
26
+
27
+ before do
28
+ allow(command).to receive(:service).and_return(service)
29
+ end
30
+
31
+ it_behaves_like Chef::Knife::Cloud::Command, described_class.new(%w(orch1 orch2))
32
+
33
+ describe '#validate_params!' do
34
+ context 'when no orchestrations are provided' do
35
+ let(:command) { described_class.new }
36
+
37
+ it 'prints an error and exits' do
38
+ expect(command.ui).to receive(:error)
39
+ expect { command.validate_params! }.to raise_error(SystemExit)
40
+ end
41
+ end
42
+
43
+ context 'when orchestrations are provided' do
44
+ it 'does not print an error or raise an exception' do
45
+ expect(command.ui).not_to receive(:error)
46
+ expect { command.validate_params! }.not_to raise_error
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#execute_command' do
52
+ it 'calls delete_orchestration for each orchestration' do
53
+ expect(service).to receive(:delete_orchestration).with('orch1')
54
+ expect(service).to receive(:delete_orchestration).with('orch2')
55
+
56
+ command.execute_command
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_orchestration_list'
21
+ require 'support/shared_examples_for_command'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudOrchestrationList do
24
+ let(:command) { described_class.new }
25
+ let(:service) { double('service') }
26
+
27
+ before do
28
+ allow(command).to receive(:service).and_return(service)
29
+ end
30
+
31
+ it_behaves_like Chef::Knife::Cloud::Command, described_class.new
32
+
33
+ describe '#query_resource' do
34
+ it 'calls list_orchestrations' do
35
+ expect(service).to receive(:list_orchestrations)
36
+ command.query_resource
37
+ end
38
+ end
39
+
40
+ describe '#format_status_value' do
41
+ it 'returns green when the status is ready' do
42
+ expect(command.ui).to receive(:color).with('ready', :green)
43
+ command.format_status_value('ready')
44
+ end
45
+
46
+ it 'returns red when the status is stopped' do
47
+ expect(command.ui).to receive(:color).with('stopped', :red)
48
+ command.format_status_value('stopped')
49
+ end
50
+
51
+ it 'returns yellow when the status is something random' do
52
+ expect(command.ui).to receive(:color).with('random', :yellow)
53
+ command.format_status_value('random')
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,96 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_orchestration_show'
21
+ require 'support/shared_examples_for_command'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudOrchestrationShow do
24
+ let(:command) { described_class.new(%w(orch1)) }
25
+ let(:service) { double('service') }
26
+
27
+ before do
28
+ allow(command).to receive(:service).and_return(service)
29
+ end
30
+
31
+ it_behaves_like Chef::Knife::Cloud::Command, described_class.new
32
+
33
+ describe '#validate_params!' do
34
+ context 'when no orchestration is provided' do
35
+ let(:command) { described_class.new }
36
+ it 'print an error and exits' do
37
+ expect(command.ui).to receive(:error)
38
+ expect { command.validate_params! }.to raise_error(SystemExit)
39
+ end
40
+ end
41
+
42
+ context 'when more than one orchestration is provided' do
43
+ let(:command) { described_class.new(%w(orch1 orch2)) }
44
+ it 'print an error and exits' do
45
+ expect(command.ui).to receive(:error)
46
+ expect { command.validate_params! }.to raise_error(SystemExit)
47
+ end
48
+ end
49
+
50
+ context 'when one orchestration is provided' do
51
+ it 'does not print an error and does not exit' do
52
+ expect(command.ui).not_to receive(:error)
53
+ expect { command.validate_params! }.not_to raise_error
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#execute_command' do
59
+ let(:orchestration) { double('orchestration') }
60
+ let(:ui) { double('ui') }
61
+ let(:instance1) { double('instance1') }
62
+ let(:instance2) { double('instance2') }
63
+ let(:instances) { [ instance1, instance2 ] }
64
+
65
+ before do
66
+ allow(command).to receive(:ui).and_return(ui)
67
+ allow(ui).to receive(:msg)
68
+ allow(ui).to receive(:color)
69
+ allow(service).to receive(:orchestration_summary)
70
+ allow(service).to receive(:server_summary)
71
+ allow(service).to receive(:get_orchestration).and_return(orchestration)
72
+ allow(orchestration).to receive(:instances).and_return(instances)
73
+ allow(instance1).to receive(:id)
74
+ allow(instance2).to receive(:id)
75
+ end
76
+
77
+ it 'retrieves the orchestration' do
78
+ expect(service).to receive(:get_orchestration).with('orch1').and_return(orchestration)
79
+
80
+ command.execute_command
81
+ end
82
+
83
+ it 'outputs the orchestration summary' do
84
+ expect(service).to receive(:orchestration_summary).with(orchestration)
85
+
86
+ command.execute_command
87
+ end
88
+
89
+ it 'outputs a server summary for each instance' do
90
+ expect(service).to receive(:server_summary).with(instance1)
91
+ expect(service).to receive(:server_summary).with(instance2)
92
+
93
+ command.execute_command
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,118 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_server_create'
21
+ require 'support/shared_examples_for_servercreatecommand'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudServerCreate do
24
+ argv = []
25
+ argv += %w(--image /path/to/test_image)
26
+ argv += %w(--shape test_shape)
27
+ argv += %w(--hostname test_hostname)
28
+ argv += %w(--public-ip pool)
29
+ argv += %w(--sshkeys user/test_key)
30
+ argv += %w(--bootstrap-protocol ssh)
31
+ argv += %w(--ssh-password test_password)
32
+
33
+ let(:command) { described_class.new(argv) }
34
+ let(:service) { double('service') }
35
+ let(:server) { double('server') }
36
+
37
+ before do
38
+ allow(command).to receive(:service).and_return(service)
39
+ allow(command).to receive(:server).and_return(server)
40
+ end
41
+
42
+ it_behaves_like Chef::Knife::Cloud::ServerCreateCommand, described_class.new
43
+
44
+ describe '#validate_params!' do
45
+ it 'checks for missing config values' do
46
+ expect(command).to receive(:check_for_missing_config_values!).with(:image, :shape, :hostname)
47
+
48
+ command.validate_params!
49
+ end
50
+ end
51
+
52
+ describe '#public_ip' do
53
+ it 'returns nil if no public IP is requested' do
54
+ allow(command).to receive(:locate_config_value).with(:public_ip).and_return(nil)
55
+
56
+ expect(command.public_ip).to eq(nil)
57
+ end
58
+
59
+ it 'returns :pool if a pool is specified' do
60
+ allow(command).to receive(:locate_config_value).with(:public_ip).and_return('pool')
61
+
62
+ expect(command.public_ip).to eq(:pool)
63
+ end
64
+
65
+ it 'returns an IP reservation name if something other than pool is specified' do
66
+ allow(command).to receive(:locate_config_value).with(:public_ip).and_return('reserve1')
67
+
68
+ expect(command.public_ip).to eq('ipreservation:reserve1')
69
+ end
70
+ end
71
+
72
+ describe '#sshkeys' do
73
+ it 'returns an empty array if no ssh keys are specified' do
74
+ allow(command).to receive(:locate_config_value).with(:sshkeys).and_return(nil)
75
+
76
+ expect(command.sshkeys).to eq([])
77
+ end
78
+
79
+ it 'returns an array of properly formatted keys' do
80
+ allow(command).to receive(:locate_config_value).with(:sshkeys).and_return('key1,key2')
81
+ allow(service).to receive(:prepend_identity_domain).with('key1').and_return('domain/key1')
82
+ allow(service).to receive(:prepend_identity_domain).with('key2').and_return('domain/key2')
83
+
84
+ expect(command.sshkeys).to eq([ 'domain/key1', 'domain/key2' ])
85
+ end
86
+ end
87
+
88
+ describe '#label' do
89
+ it 'returns the label if it has been provided' do
90
+ allow(command).to receive(:locate_config_value).with(:label).and_return('test_label')
91
+
92
+ expect(command.label).to eq('test_label')
93
+ end
94
+
95
+ it 'returns the hostname if no label has been provided' do
96
+ allow(command).to receive(:locate_config_value).with(:label).and_return(nil)
97
+ allow(command).to receive(:locate_config_value).with(:hostname).and_return('test_hostname')
98
+
99
+ expect(command.label).to eq('test_hostname')
100
+ end
101
+ end
102
+
103
+ describe '#ip_address' do
104
+ it 'defaults to a public IP if a public IP was requested' do
105
+ allow(command).to receive(:locate_config_value).with(:public_ip).and_return('pool')
106
+ allow(server).to receive(:public_ip_addresses).and_return([ '1.2.3.4' ])
107
+
108
+ expect(command.ip_address).to eq('1.2.3.4')
109
+ end
110
+
111
+ it 'returns the server private IP if a public IP was not requested' do
112
+ allow(command).to receive(:locate_config_value).with(:public_ip).and_return(nil)
113
+ allow(server).to receive(:ip_address).and_return('4.3.2.1')
114
+
115
+ expect(command.ip_address).to eq('4.3.2.1')
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_server_delete'
21
+ require 'support/shared_examples_for_command'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudServerDelete do
24
+ let(:command) { described_class.new(%w(server1)) }
25
+ let(:service) { double('service') }
26
+ let(:server) { double('server') }
27
+
28
+ it_behaves_like Chef::Knife::Cloud::Command, described_class.new(%w(server1))
29
+
30
+ it 'executes the correct methods in the overrided execute_command' do
31
+ allow(command).to receive(:service).and_return(service)
32
+ allow(server).to receive(:label).and_return('test_label')
33
+
34
+ expect(service).to receive(:get_server).with('server1').and_return(server)
35
+ expect(service).to receive(:delete_server).with('server1')
36
+ expect(command).to receive(:delete_from_chef).with('test_label')
37
+
38
+ command.execute_command
39
+ end
40
+ end
@@ -0,0 +1,59 @@
1
+ #
2
+ # Author:: Chef Partner Engineering (<partnereng@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/knife/oraclecloud_server_list'
21
+ require 'support/shared_examples_for_command'
22
+
23
+ describe Chef::Knife::Cloud::OraclecloudServerList do
24
+ let(:command) { described_class.new }
25
+ let(:service) { double('service') }
26
+
27
+ before do
28
+ allow(command).to receive(:service).and_return(service)
29
+ end
30
+
31
+ it_behaves_like Chef::Knife::Cloud::Command, described_class.new
32
+
33
+ describe '#format_status_value' do
34
+ it 'returns green when the status is running' do
35
+ expect(command.ui).to receive(:color).with('running', :green)
36
+ command.format_status_value('running')
37
+ end
38
+
39
+ it 'returns red when the status is stopped' do
40
+ expect(command.ui).to receive(:color).with('stopped', :red)
41
+ command.format_status_value('stopped')
42
+ end
43
+
44
+ it 'returns yellow when the status is something random' do
45
+ expect(command.ui).to receive(:color).with('random', :yellow)
46
+ command.format_status_value('random')
47
+ end
48
+ end
49
+
50
+ describe '#format_orchestration_value' do
51
+ it 'returns the orchestration ID passed in' do
52
+ expect(command.format_orchestration_value('test_orch')).to eq('test_orch')
53
+ end
54
+
55
+ it 'returns none if no orchestration is passed in' do
56
+ expect(command.format_orchestration_value(nil)).to eq('none')
57
+ end
58
+ end
59
+ end