knife-oraclecloud 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +202 -0
- data/README.md +248 -0
- data/Rakefile +6 -0
- data/knife-oraclecloud.gemspec +28 -0
- data/lib/chef/knife/cloud/oraclecloud_service.rb +206 -0
- data/lib/chef/knife/cloud/oraclecloud_service_helpers.rb +48 -0
- data/lib/chef/knife/cloud/oraclecloud_service_options.rb +58 -0
- data/lib/chef/knife/oraclecloud_image_list.rb +63 -0
- data/lib/chef/knife/oraclecloud_orchestration_delete.rb +51 -0
- data/lib/chef/knife/oraclecloud_orchestration_list.rb +65 -0
- data/lib/chef/knife/oraclecloud_orchestration_show.rb +64 -0
- data/lib/chef/knife/oraclecloud_server_create.rb +105 -0
- data/lib/chef/knife/oraclecloud_server_delete.rb +48 -0
- data/lib/chef/knife/oraclecloud_server_list.rb +67 -0
- data/lib/chef/knife/oraclecloud_server_show.rb +52 -0
- data/lib/chef/knife/oraclecloud_shape_list.rb +51 -0
- data/lib/knife-oraclecloud/version.rb +21 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/cloud/oraclecloud_service_helpers_spec.rb +94 -0
- data/spec/unit/cloud/oraclecloud_service_spec.rb +386 -0
- data/spec/unit/oraclecloud_image_list_spec.rb +39 -0
- data/spec/unit/oraclecloud_orchestration_delete_spec.rb +59 -0
- data/spec/unit/oraclecloud_orchestration_list_spec.rb +56 -0
- data/spec/unit/oraclecloud_orchestration_show_spec.rb +96 -0
- data/spec/unit/oraclecloud_server_create_spec.rb +118 -0
- data/spec/unit/oraclecloud_server_delete_spec.rb +40 -0
- data/spec/unit/oraclecloud_server_list_spec.rb +59 -0
- data/spec/unit/oraclecloud_server_show_spec.rb +57 -0
- data/spec/unit/oraclecloud_shape_list_spec.rb +39 -0
- metadata +161 -0
@@ -0,0 +1,65 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/list_resource_command'
|
21
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class Cloud
|
28
|
+
class OraclecloudOrchestrationList < ResourceListCommand
|
29
|
+
include OraclecloudServiceHelpers
|
30
|
+
include OraclecloudServiceOptions
|
31
|
+
|
32
|
+
banner 'knife oraclecloud orchestration list'
|
33
|
+
|
34
|
+
def before_exec_command
|
35
|
+
@columns_with_info = [
|
36
|
+
{ label: 'Orchestration ID', key: 'name_with_container' },
|
37
|
+
{ label: 'Description', key: 'description' },
|
38
|
+
{ label: 'Status', key: 'status', value_callback: method(:format_status_value) },
|
39
|
+
{ label: 'Instance Count', key: 'instance_count' }
|
40
|
+
]
|
41
|
+
|
42
|
+
@sort_by_field = 'name_with_container'
|
43
|
+
end
|
44
|
+
|
45
|
+
def query_resource
|
46
|
+
service.list_orchestrations
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_status_value(status)
|
50
|
+
status = status.downcase
|
51
|
+
status_color = case status
|
52
|
+
when 'ready'
|
53
|
+
:green
|
54
|
+
when 'stopped'
|
55
|
+
:red
|
56
|
+
else
|
57
|
+
:yellow
|
58
|
+
end
|
59
|
+
|
60
|
+
ui.color(status, status_color)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,64 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/command'
|
21
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class Cloud
|
28
|
+
class OraclecloudOrchestrationShow < Command
|
29
|
+
include OraclecloudServiceHelpers
|
30
|
+
include OraclecloudServiceOptions
|
31
|
+
|
32
|
+
banner 'knife oraclecloud orchestration show ORCHESTRATION_ID (options)'
|
33
|
+
|
34
|
+
def validate_params!
|
35
|
+
if @name_args.empty?
|
36
|
+
ui.error('You must supply an Orchestration ID for an orchestration to display.')
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
if @name_args.size > 1
|
41
|
+
ui.error('You may only supply one Orchestration ID.')
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute_command
|
49
|
+
orchestration = service.get_orchestration(@name_args.first)
|
50
|
+
|
51
|
+
ui.msg(ui.color('Orchestration Summary', :bold))
|
52
|
+
service.orchestration_summary(orchestration)
|
53
|
+
ui.msg('')
|
54
|
+
|
55
|
+
orchestration.instances.each do |instance|
|
56
|
+
ui.msg(ui.color("Instance #{instance.id}", :bold))
|
57
|
+
service.server_summary(instance)
|
58
|
+
ui.msg('')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/server/create_command'
|
21
|
+
require 'chef/knife/cloud/server/create_options'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
24
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Knife
|
28
|
+
class Cloud
|
29
|
+
class OraclecloudServerCreate < ServerCreateCommand
|
30
|
+
include OraclecloudServiceOptions
|
31
|
+
include OraclecloudServiceHelpers
|
32
|
+
include ServerCreateOptions
|
33
|
+
|
34
|
+
banner 'knife oraclecloud server create (options)'
|
35
|
+
|
36
|
+
option :hostname,
|
37
|
+
long: '--hostname HOSTNAME',
|
38
|
+
description: 'hostname of the server to be created',
|
39
|
+
proc: proc { |i| Chef::Config[:knife][:hostname] = i }
|
40
|
+
|
41
|
+
option :shape,
|
42
|
+
long: '--shape SHAPE',
|
43
|
+
description: 'shape name (i.e. size of instance) to be created',
|
44
|
+
proc: proc { |i| Chef::Config[:knife][:shape] = i }
|
45
|
+
|
46
|
+
option :public_ip,
|
47
|
+
long: '--public-ip POOL_OR_RESERVATION_NAME',
|
48
|
+
description: 'optional; "pool" to use the default public IP pool, or specify an IP reservation name to use for the public IP'
|
49
|
+
|
50
|
+
option :label,
|
51
|
+
long: '--label LABEL',
|
52
|
+
description: 'optional; text to use as label for the new instance and orchestration'
|
53
|
+
|
54
|
+
option :sshkeys,
|
55
|
+
long: '--sshkeys SSHKEY1,SSHKEY2',
|
56
|
+
description: 'optional; comma-separated list of ssh keys to enable for this instance. Key name must be user@domain.io/keyname.'
|
57
|
+
|
58
|
+
def validate_params!
|
59
|
+
super
|
60
|
+
check_for_missing_config_values!(:image, :shape, :hostname)
|
61
|
+
end
|
62
|
+
|
63
|
+
def public_ip
|
64
|
+
return nil unless locate_config_value(:public_ip)
|
65
|
+
|
66
|
+
(locate_config_value(:public_ip) == 'pool') ? :pool : "ipreservation:#{locate_config_value(:public_ip)}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def sshkeys
|
70
|
+
return [] unless locate_config_value(:sshkeys)
|
71
|
+
|
72
|
+
locate_config_value(:sshkeys).split(',').map { |key| service.prepend_identity_domain(key) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def label
|
76
|
+
locate_config_value(:label) ? locate_config_value(:label) : locate_config_value(:hostname)
|
77
|
+
end
|
78
|
+
|
79
|
+
def before_exec_command
|
80
|
+
super
|
81
|
+
|
82
|
+
@create_options = {
|
83
|
+
name: locate_config_value(:hostname),
|
84
|
+
shape: locate_config_value(:shape),
|
85
|
+
image: locate_config_value(:image),
|
86
|
+
label: label,
|
87
|
+
public_ip: public_ip,
|
88
|
+
sshkeys: sshkeys
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def ip_address
|
93
|
+
locate_config_value(:public_ip) ? server.public_ip_addresses.first : server.ip_address
|
94
|
+
end
|
95
|
+
|
96
|
+
def before_bootstrap
|
97
|
+
super
|
98
|
+
|
99
|
+
config[:chef_node_name] = locate_config_value(:chef_node_name) ? locate_config_value(:chef_node_name) : server.name
|
100
|
+
config[:bootstrap_ip_address] = ip_address
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,48 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/server/delete_options'
|
21
|
+
require 'chef/knife/cloud/server/delete_command'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
24
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Knife
|
28
|
+
class Cloud
|
29
|
+
class OraclecloudServerDelete < ServerDeleteCommand
|
30
|
+
include ServerDeleteOptions
|
31
|
+
include OraclecloudServiceHelpers
|
32
|
+
include OraclecloudServiceOptions
|
33
|
+
|
34
|
+
banner 'knife oraclecloud server delete INSTANCE_ID [INSTANCE_ID] (options)'
|
35
|
+
|
36
|
+
# overriding this method from knife-cloud so we can pull the instance label
|
37
|
+
# to pass to delete_from_chef rather than the resource ID
|
38
|
+
def execute_command
|
39
|
+
@name_args.each do |instance_id|
|
40
|
+
instance = service.get_server(instance_id)
|
41
|
+
service.delete_server(instance_id)
|
42
|
+
delete_from_chef(instance.label)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/server/list_command'
|
21
|
+
require 'chef/knife/cloud/server/list_options'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
24
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Knife
|
28
|
+
class Cloud
|
29
|
+
class OraclecloudServerList < ServerListCommand
|
30
|
+
include OraclecloudServiceHelpers
|
31
|
+
include OraclecloudServiceOptions
|
32
|
+
|
33
|
+
banner 'knife oraclecloud server list'
|
34
|
+
|
35
|
+
def before_exec_command
|
36
|
+
@columns_with_info = [
|
37
|
+
{ label: 'Hostname', key: 'hostname' },
|
38
|
+
{ label: 'Status', key: 'status', value_callback: method(:format_status_value) },
|
39
|
+
{ label: 'Shape', key: 'shape' },
|
40
|
+
{ label: 'Image', key: 'image' },
|
41
|
+
{ label: 'Instance ID', key: 'id' },
|
42
|
+
{ label: 'Orchestration ID', key: 'orchestration', value_callback: method(:format_orchestration_value) }
|
43
|
+
]
|
44
|
+
|
45
|
+
@sort_by_field = 'name'
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_status_value(status)
|
49
|
+
status = status.downcase
|
50
|
+
status_color = case status
|
51
|
+
when 'running'
|
52
|
+
:green
|
53
|
+
when 'stopped'
|
54
|
+
:red
|
55
|
+
else
|
56
|
+
:yellow
|
57
|
+
end
|
58
|
+
ui.color(status, status_color)
|
59
|
+
end
|
60
|
+
|
61
|
+
def format_orchestration_value(orchestration)
|
62
|
+
orchestration.nil? ? 'none' : orchestration
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/server/show_options'
|
21
|
+
require 'chef/knife/cloud/server/show_command'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
24
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Knife
|
28
|
+
class Cloud
|
29
|
+
class OraclecloudServerShow < ServerShowCommand
|
30
|
+
include ServerShowOptions
|
31
|
+
include OraclecloudServiceHelpers
|
32
|
+
include OraclecloudServiceOptions
|
33
|
+
|
34
|
+
banner 'knife oraclecloud server show INSTANCE_ID (options)'
|
35
|
+
|
36
|
+
def validate_params!
|
37
|
+
if @name_args.empty?
|
38
|
+
ui.error('You must supply an Instance ID for a server to display.')
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
if @name_args.size > 1
|
43
|
+
ui.error('You may only supply one Instance ID.')
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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 'chef/knife'
|
20
|
+
require 'chef/knife/cloud/list_resource_command'
|
21
|
+
require 'chef/knife/cloud/oraclecloud_service'
|
22
|
+
require 'chef/knife/cloud/oraclecloud_service_helpers'
|
23
|
+
require 'chef/knife/cloud/oraclecloud_service_options'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class Cloud
|
28
|
+
class OraclecloudShapeList < ResourceListCommand
|
29
|
+
include OraclecloudServiceHelpers
|
30
|
+
include OraclecloudServiceOptions
|
31
|
+
|
32
|
+
banner 'knife oraclecloud shape list'
|
33
|
+
|
34
|
+
def before_exec_command
|
35
|
+
@columns_with_info = [
|
36
|
+
{ label: 'Shape Name', key: 'name' },
|
37
|
+
{ label: 'CPUs', key: 'cpus' },
|
38
|
+
{ label: 'RAM', key: 'ram' },
|
39
|
+
{ label: 'I/O', key: 'io' }
|
40
|
+
]
|
41
|
+
|
42
|
+
@sort_by_field = 'name'
|
43
|
+
end
|
44
|
+
|
45
|
+
def query_resource
|
46
|
+
service.list_shapes
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|