knife-opennebula 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/chef/knife/opennebula_base.rb +41 -16
- data/lib/chef/knife/opennebula_server_create.rb +121 -89
- data/lib/chef/knife/opennebula_server_delete.rb +59 -39
- data/lib/chef/knife/opennebula_server_list.rb +29 -50
- data/lib/chef/knife/opennebula_template_list.rb +27 -37
- data/lib/chef/opennebula/version.rb +1 -1
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e44d8c756d827a13b17680c62a2633e0009330f
|
4
|
+
data.tar.gz: 8b525639ad2fdd294dceaad85a600ce89250f1ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e6b013604fdfad27c3164fdd7cbea2e1715042859bf012627c7c9fa70a310300e56607b392a049886397b830fa76de17bf288331175f485c55758715ca4bf2
|
7
|
+
data.tar.gz: 45dd682acb0e47f897cd54c91847ee0f456e09cea5c1fee0af5531892c27a85c3a58a28d7658307a553489f79f33b85ac20d14a67622dd3fae65c7d78fecab9c
|
data/README.md
CHANGED
@@ -16,13 +16,13 @@ More info:
|
|
16
16
|
|
17
17
|
## Authors
|
18
18
|
|
19
|
-
* Leader: Thomas Alrin (
|
20
|
-
* Kishore Kumar (nkishore@megam.
|
19
|
+
* Leader: Thomas Alrin (thomasalrin@megam.io)
|
20
|
+
* Kishore Kumar (nkishore@megam.io)
|
21
21
|
|
22
22
|
## Compatibility
|
23
23
|
|
24
|
-
This add-on is compatible with OpenNebula 4.4, 4.6.
|
25
|
-
|
24
|
+
This add-on is compatible with OpenNebula 4.4, 4.6, 4.12
|
25
|
+
|
26
26
|
|
27
27
|
## Requirements
|
28
28
|
|
@@ -37,7 +37,6 @@ Hosted Chef 11.0.x (or) On Premises Chef (http://www.getchef.com/chef/choose-you
|
|
37
37
|
To install the plugin you need to do the following in your workstation:
|
38
38
|
|
39
39
|
* `gem install chef`
|
40
|
-
* `gem install opennebula`
|
41
40
|
* `gem install knife-opennebula`
|
42
41
|
|
43
42
|
|
@@ -1,19 +1,40 @@
|
|
1
|
-
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012-2014 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
|
+
#
|
2
18
|
|
3
19
|
class Chef
|
4
20
|
class Knife
|
5
21
|
module OpennebulaBase
|
6
22
|
|
7
|
-
|
23
|
+
# :nodoc:
|
24
|
+
# Would prefer to do this in a rational way, but can't be done b/c of
|
25
|
+
# Mixlib::CLI's design :(
|
26
|
+
def self.included(includer)
|
8
27
|
includer.class_eval do
|
9
28
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
29
|
+
deps do
|
30
|
+
require 'chef/json_compat'
|
31
|
+
require 'chef/knife'
|
32
|
+
require 'readline'
|
33
|
+
require 'fog'
|
34
|
+
Chef::Knife.load_deps
|
35
|
+
end
|
15
36
|
|
16
|
-
|
37
|
+
option :opennebula_username,
|
17
38
|
:short => "-A OPENNEBULA_USERNAME",
|
18
39
|
:long => "--username OPENNEBULA_USERNAME",
|
19
40
|
:description => "Opennebula user's name",
|
@@ -30,13 +51,21 @@ class Chef
|
|
30
51
|
:long => "--endpoint OPENNEBULA_ENDPOIN",
|
31
52
|
:description => "Opennebula Endpoint",
|
32
53
|
:proc => Proc.new { |endpoint| Chef::Config[:knife][:opennebula_endpoint] = endpoint }
|
54
|
+
|
33
55
|
end
|
34
56
|
end
|
35
57
|
|
58
|
+
def connection
|
59
|
+
@connection ||= begin
|
60
|
+
connection = Fog::Compute.new(
|
61
|
+
:provider => 'OpenNebula',
|
62
|
+
:opennebula_username => locate_config_value(:opennebula_username),
|
63
|
+
:opennebula_password => locate_config_value(:opennebula_password),
|
64
|
+
:opennebula_endpoint => locate_config_value(:opennebula_endpoint)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
36
68
|
|
37
|
-
require 'opennebula'
|
38
|
-
|
39
|
-
include OpenNebula
|
40
69
|
|
41
70
|
def validate!
|
42
71
|
if (!opennebula_username)
|
@@ -51,11 +80,6 @@ class Chef
|
|
51
80
|
end
|
52
81
|
end
|
53
82
|
|
54
|
-
def client
|
55
|
-
cli = Client.new("#{opennebula_username}:#{opennebula_password}", "#{opennebula_endpoint}")
|
56
|
-
cli
|
57
|
-
end
|
58
|
-
|
59
83
|
def msg_pair(label, value, color=:cyan)
|
60
84
|
if value && !value.to_s.empty?
|
61
85
|
ui.info "#{ui.color(label, color)}: #{value}"
|
@@ -79,6 +103,7 @@ class Chef
|
|
79
103
|
config[key] || Chef::Config[:knife][key]
|
80
104
|
end
|
81
105
|
|
106
|
+
|
82
107
|
end
|
83
108
|
end
|
84
109
|
end
|
@@ -1,21 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012-2014 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
|
+
|
1
19
|
require 'chef/knife'
|
2
20
|
require 'chef/json_compat'
|
3
21
|
require 'chef/knife/opennebula_base'
|
4
22
|
|
5
|
-
#require_relative 'opennebula_base'
|
6
23
|
class Chef
|
7
24
|
class Knife
|
8
|
-
|
25
|
+
class OpennebulaServerCreate < Knife
|
9
26
|
|
10
27
|
deps do
|
11
28
|
require 'highline'
|
12
29
|
require 'chef/knife/bootstrap'
|
13
|
-
|
14
|
-
require 'net/ssh/multi'
|
15
|
-
Chef::Knife.load_deps
|
30
|
+
Chef::Knife::Bootstrap.load_deps
|
16
31
|
end
|
17
32
|
include Knife::OpennebulaBase
|
18
|
-
|
33
|
+
|
19
34
|
banner "knife opennebula server create OPTIONS"
|
20
35
|
|
21
36
|
option :opennebula_template,
|
@@ -31,6 +46,12 @@ class Chef
|
|
31
46
|
:boolean => true,
|
32
47
|
:default => true
|
33
48
|
|
49
|
+
#It assumes that chef-client already installed in the server (ie) Image has installed with chef-client
|
50
|
+
#Chef-client install command
|
51
|
+
option :bootstrap_install_command,
|
52
|
+
:long => "--bootstrap_install_command",
|
53
|
+
:description => "Bootstrap the server with the given chef-client install command",
|
54
|
+
:default => "pwd"
|
34
55
|
|
35
56
|
option :ssh_user,
|
36
57
|
:short => "-x USERNAME",
|
@@ -79,6 +100,13 @@ class Chef
|
|
79
100
|
:boolean => true,
|
80
101
|
:default => true
|
81
102
|
|
103
|
+
option :json_attributes,
|
104
|
+
:short => "-j JSON",
|
105
|
+
:long => "--json-attributes JSON",
|
106
|
+
:description => "A JSON string to be added to the first run of chef-client",
|
107
|
+
:proc => lambda { |o| JSON.parse(o) }
|
108
|
+
|
109
|
+
|
82
110
|
option :identity_file,
|
83
111
|
:short => "-i IDENTITY_FILE",
|
84
112
|
:long => "--identity-file IDENTITY_FILE",
|
@@ -89,109 +117,113 @@ class Chef
|
|
89
117
|
end
|
90
118
|
|
91
119
|
def run
|
92
|
-
#Validate opennebula credentials
|
93
120
|
validate!
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
unless "#{vm_id.class}" == "Fixnum"
|
110
|
-
ui.error("Some problem in instantiating template")
|
111
|
-
exit 1
|
112
|
-
end
|
113
|
-
puts ui.color("Template Instantiated, and a VM created with id #{vm_id}", :green)
|
114
|
-
puts ui.color("Fetching ip address of the VM ", :magenta)
|
115
|
-
#Get the VM details
|
116
|
-
vir_mac = virtual_machine("#{vm_id}")
|
117
|
-
unless "#{vir_mac.class}" == "OpenNebula::VirtualMachine"
|
118
|
-
ui.error("Some problem in Getting Virtual Machine")
|
119
|
-
exit 1
|
120
|
-
end
|
121
|
-
@vm_hash = vir_mac.to_hash
|
122
|
-
#VM can have more ip addresses. Priority to get vm ip is AWS_IP_ADDRESS, MEGAM_IP_ADDRESS and PRIVATE_IP_ADDRESS.
|
123
|
-
if @vm_hash['VM']['TEMPLATE'].has_key?('AWS_IP_ADDRESS')
|
124
|
-
@ip_add = @vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS']
|
125
|
-
else
|
126
|
-
@ip_add = @vm_hash['VM']['USER_TEMPLATE']['MEGAM_IP_ADDRESS']
|
127
|
-
end
|
121
|
+
validate_flavor!
|
122
|
+
|
123
|
+
newvm = connection.servers.new
|
124
|
+
|
125
|
+
newvm.flavor = connection.flavors.get(flavor.id)
|
126
|
+
|
127
|
+
# set the name of the vm
|
128
|
+
newvm.name = locate_config_value(:chef_node_name)
|
129
|
+
|
130
|
+
newvm.flavor.vcpu = 1
|
131
|
+
|
132
|
+
vm = newvm.save
|
133
|
+
|
134
|
+
ser = server(vm.id)
|
128
135
|
puts ui.color("\nServer:", :green)
|
129
|
-
msg_pair("Name",
|
130
|
-
msg_pair("
|
136
|
+
msg_pair("VM Name", ser.name)
|
137
|
+
msg_pair("VM ID", ser.id)
|
138
|
+
msg_pair("IP", ser.ip)
|
139
|
+
msg_pair("Template", flavor.name)
|
140
|
+
|
141
|
+
print "\n#{ui.color("Waiting for server", :magenta)}"
|
142
|
+
|
143
|
+
# wait for it to be ready to do stuff
|
144
|
+
ser.wait_for { print "."; ready? }
|
145
|
+
|
146
|
+
puts("\n")
|
147
|
+
# hack to ensure the nodes have had time to spin up
|
148
|
+
print(".")
|
149
|
+
sleep 30
|
150
|
+
print(".")
|
151
|
+
|
152
|
+
print(".") until tcp_test_ssh(ser.ip) {
|
153
|
+
sleep @initial_sleep_delay ||= 10
|
154
|
+
puts("done")
|
155
|
+
}
|
156
|
+
|
131
157
|
#Bootstrap VM
|
132
|
-
bootstrap()
|
158
|
+
bootstrap(ser.ip)
|
133
159
|
|
134
160
|
puts ui.color("Server:", :green)
|
135
|
-
msg_pair("Name",
|
136
|
-
msg_pair("IP",
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
vm_pool = VirtualMachinePool.new(client, -1)
|
141
|
-
rc = vm_pool.info
|
142
|
-
if OpenNebula.is_error?(rc)
|
143
|
-
puts rc.message
|
144
|
-
exit -1
|
145
|
-
end
|
146
|
-
vm_pool.each do |vm|
|
147
|
-
if "#{vm.id}" == "#{id}"
|
148
|
-
v_hash = vm.to_hash
|
149
|
-
#Sleep untill get the VM's Ip address from either vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS'] or vm_hash['VM']['USER_TEMPLATE']['MEGAM_IP_ADDRESS'].
|
150
|
-
#vm_hash['VM']['USER_TEMPLATE']['MEGAM_IP_ADDRESS'] can be set by onegate. In our case, we get that ip from vpn.
|
151
|
-
if v_hash['VM']['TEMPLATE'].has_key?('AWS_IP_ADDRESS') || v_hash['VM']['USER_TEMPLATE'].has_key?('MEGAM_IP_ADDRESS')
|
152
|
-
@re_obj = vm
|
153
|
-
else
|
154
|
-
sleep 1
|
155
|
-
print "."
|
156
|
-
virtual_machine("#{vm.id}")
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
@re_obj
|
161
|
+
msg_pair("Name", ser.name)
|
162
|
+
msg_pair("IP", ser.ip)
|
163
|
+
msg_pair("Environment", config[:environment] || '_default')
|
164
|
+
msg_pair("Run List", config[:run_list].join(', '))
|
165
|
+
msg_pair("JSON Attributes",config[:json_attributes]) unless !config[:json_attributes] || config[:json_attributes].empty?
|
161
166
|
end
|
162
167
|
|
163
|
-
def template(name)
|
164
|
-
#Searching user's vm template
|
165
|
-
puts ui.color("Locating Template......", :green)
|
166
|
-
temp_pool = TemplatePool.new(client, -1)
|
167
|
-
rc = temp_pool.info
|
168
|
-
if OpenNebula.is_error?(rc)
|
169
|
-
puts rc.message
|
170
|
-
exit -1
|
171
|
-
end
|
172
|
-
temp_pool.each do |temp|
|
173
|
-
if "#{temp.name}" == "#{name}"
|
174
|
-
puts ui.color("Template Found.", :green)
|
175
|
-
return temp
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
168
|
|
180
|
-
def bootstrap
|
169
|
+
def bootstrap(ip)
|
181
170
|
bootstrap = Chef::Knife::Bootstrap.new
|
182
|
-
bootstrap.name_args =
|
171
|
+
bootstrap.name_args = ip
|
183
172
|
bootstrap.config[:run_list] = locate_config_value(:run_list)
|
184
173
|
bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
|
185
174
|
bootstrap.config[:ssh_port] = locate_config_value(:ssh_port)
|
186
175
|
bootstrap.config[:identity_file] = locate_config_value(:identity_file)
|
187
176
|
bootstrap.config[:distro] = locate_config_value(:distro)
|
188
177
|
bootstrap.config[:host_key_verify] = config[:host_key_verify]
|
178
|
+
bootstrap.config[:first_boot_attributes] = locate_config_value(:json_attributes) || {}
|
189
179
|
bootstrap.config[:template_file] = locate_config_value(:template_file)
|
190
|
-
bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name)
|
180
|
+
bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name)
|
181
|
+
bootstrap.config[:bootstrap_install_command] = locate_config_value(:bootstrap_install_command)
|
191
182
|
bootstrap.config[:use_sudo] = true unless bootstrap.config[:ssh_user] == 'root'
|
192
183
|
bootstrap.run
|
193
184
|
end
|
194
185
|
|
186
|
+
def tcp_test_ssh(hostname)
|
187
|
+
tcp_socket = TCPSocket.new(hostname, 22)
|
188
|
+
readable = IO.select([tcp_socket], nil, nil, 5)
|
189
|
+
if readable
|
190
|
+
Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
|
191
|
+
yield
|
192
|
+
true
|
193
|
+
else
|
194
|
+
false
|
195
|
+
end
|
196
|
+
rescue Errno::ETIMEDOUT
|
197
|
+
false
|
198
|
+
rescue Errno::EPERM
|
199
|
+
false
|
200
|
+
rescue Errno::ECONNREFUSED
|
201
|
+
sleep 2
|
202
|
+
false
|
203
|
+
rescue Errno::EHOSTUNREACH
|
204
|
+
sleep 2
|
205
|
+
false
|
206
|
+
ensure
|
207
|
+
tcp_socket && tcp_socket.close
|
208
|
+
end
|
209
|
+
|
210
|
+
def flavor
|
211
|
+
@flavor ||= connection.flavors.get_by_name(locate_config_value(:opennebula_template))
|
212
|
+
@flavor[0]
|
213
|
+
end
|
214
|
+
|
215
|
+
def server(id)
|
216
|
+
@server ||= connection.servers.get(id)
|
217
|
+
end
|
218
|
+
|
219
|
+
def validate_flavor!
|
220
|
+
if flavor.nil?
|
221
|
+
ui.error("You have not provided a valid Template NAme. Please note the options for this value are -t or --template-name.")
|
222
|
+
exit 1
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
|
195
227
|
end
|
196
228
|
end
|
197
229
|
end
|
@@ -1,18 +1,36 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012-2014 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/node'
|
20
|
+
require 'chef/api_client'
|
3
21
|
require 'chef/knife/opennebula_base'
|
4
22
|
|
5
|
-
#require_relative 'opennebula_base'
|
6
23
|
class Chef
|
7
24
|
class Knife
|
8
|
-
|
25
|
+
class OpennebulaServerDelete < Knife
|
9
26
|
|
10
27
|
deps do
|
11
28
|
require 'highline'
|
12
29
|
Chef::Knife.load_deps
|
13
30
|
end
|
14
|
-
include Knife::OpennebulaBase
|
15
31
|
|
32
|
+
include Knife::OpennebulaBase
|
33
|
+
|
16
34
|
banner "knife opennebula server delete VM_NAME (OPTIONS)"
|
17
35
|
|
18
36
|
option :purge,
|
@@ -28,10 +46,6 @@ class Chef
|
|
28
46
|
:description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
|
29
47
|
|
30
48
|
|
31
|
-
def h
|
32
|
-
@highline ||= HighLine.new
|
33
|
-
end
|
34
|
-
|
35
49
|
def destroy_item(klass, name, type_name)
|
36
50
|
begin
|
37
51
|
object = klass.load(name)
|
@@ -42,45 +56,51 @@ class Chef
|
|
42
56
|
end
|
43
57
|
end
|
44
58
|
|
59
|
+
def h
|
60
|
+
@highline ||= HighLine.new
|
61
|
+
end
|
62
|
+
|
63
|
+
|
45
64
|
def run
|
65
|
+
|
46
66
|
validate!
|
47
|
-
if @name_args.empty?
|
48
|
-
ui.error("no vm name is specific")
|
49
|
-
exit -1
|
50
|
-
else
|
51
|
-
@vm_name = @name_args[0]
|
52
|
-
end
|
53
|
-
vm_pool = VirtualMachinePool.new(client, -1)
|
54
|
-
rc = vm_pool.info
|
55
|
-
if OpenNebula.is_error?(rc)
|
56
|
-
puts rc.message
|
57
|
-
exit -1
|
58
|
-
end
|
59
67
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
@name_args.each do |instance_id|
|
69
|
+
begin
|
70
|
+
|
71
|
+
#Fetch instance_id by name of the server =====> MEGAM SYSTEMS CODE START
|
72
|
+
connection.servers.all.each do |ser|
|
73
|
+
if ser.name.to_s == "#{instance_id}"
|
74
|
+
instance_id = ser.id
|
75
|
+
end
|
76
|
+
end
|
77
|
+
#=====> MEGAM SYSTEMS CODE END
|
78
|
+
|
79
|
+
server = connection.servers.get(instance_id)
|
80
|
+
|
81
|
+
msg_pair("VM ID", server.id)
|
82
|
+
msg_pair("VM Name", server.name)
|
83
|
+
msg_pair("IP Address", server.ip)
|
84
|
+
|
85
|
+
puts "\n"
|
67
86
|
confirm("Do you really want to delete this server")
|
68
|
-
|
69
|
-
|
87
|
+
|
88
|
+
server.destroy
|
89
|
+
|
90
|
+
ui.warn("Deleted server #{server.id}")
|
91
|
+
|
70
92
|
if config[:purge]
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
destroy_item(Chef::ApiClient, thing_to_delete, "client")
|
75
|
-
else
|
76
|
-
ui.error("Please Provide Chef NODE_NAME in -N")
|
77
|
-
end
|
93
|
+
thing_to_delete = config[:chef_node_name] || instance_id
|
94
|
+
destroy_item(Chef::Node, thing_to_delete, "node")
|
95
|
+
destroy_item(Chef::ApiClient, thing_to_delete, "client")
|
78
96
|
else
|
79
|
-
ui.warn("Corresponding node and client for the #{
|
97
|
+
ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server")
|
80
98
|
end
|
99
|
+
|
100
|
+
rescue NoMethodError
|
101
|
+
ui.error("Could not locate server '#{instance_id}'.")
|
81
102
|
end
|
82
103
|
end
|
83
|
-
|
84
104
|
end
|
85
105
|
|
86
106
|
end
|
@@ -1,74 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012-2014 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
|
+
|
1
19
|
require 'chef/knife'
|
2
20
|
require 'chef/json_compat'
|
3
21
|
require 'chef/knife/opennebula_base'
|
4
22
|
|
5
|
-
#require_relative 'opennebula_base'
|
6
23
|
class Chef
|
7
24
|
class Knife
|
8
25
|
class OpennebulaServerList < Knife
|
9
26
|
|
10
|
-
deps do
|
11
|
-
require 'highline'
|
12
|
-
Chef::Knife.load_deps
|
13
|
-
end
|
14
27
|
include Knife::OpennebulaBase
|
15
28
|
|
16
|
-
banner "knife opennebula server list
|
17
|
-
|
18
|
-
def h
|
19
|
-
@highline ||= HighLine.new
|
20
|
-
end
|
29
|
+
banner "knife opennebula server list (options)"
|
21
30
|
|
22
31
|
def run
|
23
|
-
validate!
|
24
32
|
|
25
|
-
|
26
|
-
rc = vm_pool.info
|
27
|
-
if OpenNebula.is_error?(rc)
|
28
|
-
puts rc.message
|
29
|
-
exit -1
|
30
|
-
end
|
31
|
-
|
32
|
-
# TO-DO: This is tailored for AWS, need to be fixed, just so it works for private/public
|
33
|
+
validate!
|
33
34
|
|
34
|
-
|
35
|
+
server_list = [
|
35
36
|
ui.color('ID', :bold),
|
36
37
|
ui.color('Name', :bold),
|
38
|
+
ui.color('IP', :bold),
|
37
39
|
ui.color('Memory', :bold),
|
38
|
-
ui.color('Cpu', :bold),
|
39
|
-
#ui.color('AWS_ZONE', :bold),
|
40
|
-
#ui.color('INSTANCE_TYPE', :bold),
|
41
|
-
#ui.color('IP', :bold),
|
42
|
-
#ui.color('AWS_Key', :bold),
|
43
40
|
ui.color('State', :bold)]
|
44
|
-
vm_pool.each do |vm|
|
45
|
-
vm_hash = vm.to_hash
|
46
|
-
vm_list << vm_hash['VM']['ID']
|
47
|
-
vm_list << vm_hash['VM']['NAME']
|
48
|
-
vm_list << vm_hash['VM']['TEMPLATE']['MEMORY']
|
49
|
-
vm_list << vm_hash['VM']['TEMPLATE']['CPU']
|
50
|
-
#vm_list << vm_hash['VM']['TEMPLATE']['AWS_AVAILABILITY_ZONE'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_AVAILABILITY_ZONE')
|
51
|
-
#vm_list << vm_hash['VM']['TEMPLATE']['AWS_INSTANCE_TYPE'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_INSTANCE_TYPE')
|
52
|
-
#vm_list << vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_IP_ADDRESS')
|
53
|
-
#vm_list << vm_hash['VM']['TEMPLATE']['AWS_KEY_NAME'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_KEY_NAME')
|
54
|
-
vm_list << begin
|
55
|
-
state = vm_hash['VM']['STATE']
|
56
|
-
case state
|
57
|
-
when '1'
|
58
|
-
ui.color(state, :red)
|
59
|
-
when '2'
|
60
|
-
ui.color(state, :yellow)
|
61
|
-
else
|
62
|
-
ui.color(state, :green)
|
63
|
-
end
|
64
|
-
end
|
65
41
|
|
42
|
+
connection.servers.all.each do |server|
|
43
|
+
server_list << "#{server.id.to_s}"
|
44
|
+
server_list << server.name
|
45
|
+
server_list << server.ip
|
46
|
+
server_list << "#{server.memory.to_s}"
|
47
|
+
server_list << server.state
|
66
48
|
end
|
67
|
-
puts ui.
|
68
|
-
puts ui.list(vm_list, :uneven_columns_across, 5)
|
69
|
-
|
49
|
+
puts ui.list(server_list, :uneven_columns_across, 5)
|
70
50
|
end
|
71
|
-
|
72
51
|
end
|
73
52
|
end
|
74
53
|
end
|
@@ -1,61 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012-2014 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
|
+
|
1
19
|
require 'chef/knife'
|
2
20
|
require 'chef/json_compat'
|
3
21
|
require 'chef/knife/opennebula_base'
|
4
22
|
|
5
|
-
#require_relative 'opennebula_base'
|
6
23
|
class Chef
|
7
24
|
class Knife
|
8
25
|
class OpennebulaTemplateList < Knife
|
9
26
|
|
10
|
-
deps do
|
11
|
-
require 'highline'
|
12
|
-
Chef::Knife.load_deps
|
13
|
-
end
|
14
27
|
include Knife::OpennebulaBase
|
15
28
|
|
16
|
-
banner "knife opennebula template list
|
17
|
-
|
18
|
-
def h
|
19
|
-
@highline ||= HighLine.new
|
20
|
-
end
|
29
|
+
banner "knife opennebula template list (options)"
|
21
30
|
|
22
31
|
def run
|
23
|
-
validate!
|
24
32
|
|
25
|
-
|
26
|
-
rc = temp_pool.info
|
27
|
-
if OpenNebula.is_error?(rc)
|
28
|
-
puts rc.message
|
29
|
-
exit -1
|
30
|
-
end
|
33
|
+
validate!
|
31
34
|
|
32
|
-
|
33
|
-
temp_list = [
|
35
|
+
flavor_list = [
|
34
36
|
ui.color('ID', :bold),
|
35
37
|
ui.color('Name', :bold),
|
36
|
-
#ui.color('AMI', :bold),
|
37
|
-
#ui.color('INSTANCE_TYPE', :bold),
|
38
|
-
#ui.color('KEY_PAIR', :bold),
|
39
|
-
#ui.color('SECURITY_GROUP', :bold),
|
40
38
|
ui.color('CPU', :bold),
|
41
39
|
ui.color('MEMORY', :bold)]
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['INSTANCETYPE'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
|
49
|
-
#temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['KEYPAIR'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
|
50
|
-
#temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['SECURITYGROUPS'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
|
51
|
-
temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['CPU']
|
52
|
-
temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['MEMORY']
|
41
|
+
connection.flavors.all.each do |flavor|
|
42
|
+
flavor_list << flavor.id
|
43
|
+
flavor_list << flavor.name
|
44
|
+
flavor_list << flavor.cpu.to_s
|
45
|
+
flavor_list << "#{flavor.memory.to_s} MB"
|
53
46
|
end
|
54
|
-
|
55
|
-
puts ui.color("VM Templates Listed Successfully", :green)
|
56
|
-
puts ui.list(temp_list, :uneven_columns_across, 4)
|
47
|
+
puts ui.list(flavor_list, :uneven_columns_across, 4)
|
57
48
|
end
|
58
|
-
|
59
49
|
end
|
60
50
|
end
|
61
51
|
end
|
metadata
CHANGED
@@ -1,31 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-opennebula
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kishorekumar Neelamegam, Thomas Alrin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fog
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.26.0
|
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: 1.26.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: chef
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opennebula
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -54,8 +68,8 @@ dependencies:
|
|
54
68
|
version: '0'
|
55
69
|
description: Knife plugin to manage OpenNebula VMs
|
56
70
|
email:
|
57
|
-
- nkishore@megam.
|
58
|
-
-
|
71
|
+
- nkishore@megam.io
|
72
|
+
- thomasalrin@megam.io
|
59
73
|
executables: []
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files:
|
@@ -89,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
103
|
version: '0'
|
90
104
|
requirements: []
|
91
105
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.6
|
93
107
|
signing_key:
|
94
108
|
specification_version: 4
|
95
109
|
summary: Knife plugin to manage OpenNebula VMs
|