opennebula-cli 5.7.80.pre → 5.7.85.pre
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/bin/oneacct +1 -1
- data/bin/oneacl +1 -1
- data/bin/onecluster +1 -1
- data/bin/onedatastore +1 -1
- data/bin/oneflow +1 -1
- data/bin/oneflow-template +1 -1
- data/bin/onegroup +1 -1
- data/bin/onehost +14 -1
- data/bin/oneimage +1 -1
- data/bin/onemarket +1 -1
- data/bin/onemarketapp +1 -1
- data/bin/onesecgroup +1 -1
- data/bin/oneshowback +1 -1
- data/bin/onetemplate +3 -1
- data/bin/oneuser +1 -1
- data/bin/onevcenter +1 -1
- data/bin/onevdc +1 -1
- data/bin/onevm +37 -12
- data/bin/onevmgroup +1 -1
- data/bin/onevnet +1 -1
- data/bin/onevntemplate +1 -2
- data/bin/onevrouter +1 -1
- data/bin/onezone +1 -1
- data/lib/cli_helper.rb +13 -3
- data/lib/command_parser.rb +1 -1
- data/lib/one_helper.rb +15 -11
- data/lib/one_helper/oneacct_helper.rb +1 -1
- data/lib/one_helper/oneacl_helper.rb +1 -1
- data/lib/one_helper/onecluster_helper.rb +1 -1
- data/lib/one_helper/onedatastore_helper.rb +1 -1
- data/lib/one_helper/onegroup_helper.rb +1 -1
- data/lib/one_helper/onehost_helper.rb +329 -204
- data/lib/one_helper/oneimage_helper.rb +1 -1
- data/lib/one_helper/onemarket_helper.rb +1 -1
- data/lib/one_helper/onemarketapp_helper.rb +1 -1
- data/lib/one_helper/onequota_helper.rb +1 -1
- data/lib/one_helper/onesecgroup_helper.rb +1 -1
- data/lib/one_helper/onetemplate_helper.rb +1 -1
- data/lib/one_helper/oneuser_helper.rb +1 -1
- data/lib/one_helper/onevcenter_helper.rb +1 -1
- data/lib/one_helper/onevdc_helper.rb +1 -1
- data/lib/one_helper/onevm_helper.rb +8 -1
- data/lib/one_helper/onevmgroup_helper.rb +1 -1
- data/lib/one_helper/onevnet_helper.rb +1 -1
- data/lib/one_helper/onevntemplate_helper.rb +1 -1
- data/lib/one_helper/onevrouter_helper.rb +1 -1
- data/lib/one_helper/onezone_helper.rb +1 -1
- metadata +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -18,8 +18,10 @@ require 'one_helper'
|
|
|
18
18
|
require 'one_helper/onevm_helper'
|
|
19
19
|
require 'rubygems'
|
|
20
20
|
|
|
21
|
+
# implements onehost command
|
|
21
22
|
class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
22
|
-
|
|
23
|
+
|
|
24
|
+
TEMPLATE_XPATH = '//HOST/TEMPLATE'
|
|
23
25
|
HYBRID = {
|
|
24
26
|
:ec2 => {
|
|
25
27
|
:help => <<-EOT.unindent,
|
|
@@ -41,7 +43,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
41
43
|
# See your ec2_driver.conf for more information
|
|
42
44
|
#
|
|
43
45
|
#-----------------------------------------------------------------------
|
|
44
|
-
|
|
46
|
+
EOT
|
|
45
47
|
},
|
|
46
48
|
:az => {
|
|
47
49
|
:help => <<-EOT.unindent,
|
|
@@ -67,110 +69,112 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
67
69
|
# AZ_ENDPOINT = <endpoint address>
|
|
68
70
|
#
|
|
69
71
|
#-----------------------------------------------------------------------
|
|
70
|
-
|
|
72
|
+
EOT
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
VERSION_XPATH = "#{TEMPLATE_XPATH}/VERSION"
|
|
76
|
+
VERSION_XPATH = "#{TEMPLATE_XPATH}/VERSION"
|
|
76
77
|
|
|
77
78
|
def self.rname
|
|
78
|
-
|
|
79
|
+
'HOST'
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
def self.conf_file
|
|
82
|
-
|
|
83
|
+
'onehost.yaml'
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def self.state_to_str(id)
|
|
86
87
|
id = id.to_i
|
|
87
88
|
state_str = Host::HOST_STATES[id]
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
Host::SHORT_HOST_STATES[state_str]
|
|
90
91
|
end
|
|
91
92
|
|
|
92
93
|
def format_pool(options)
|
|
93
94
|
config_file = self.class.table_conf
|
|
94
95
|
|
|
95
96
|
table = CLIHelper::ShowTable.new(config_file, self) do
|
|
96
|
-
column :ID,
|
|
97
|
-
d[
|
|
97
|
+
column :ID, 'ONE identifier for Host', :size => 4 do |d|
|
|
98
|
+
d['ID']
|
|
98
99
|
end
|
|
99
100
|
|
|
100
|
-
column :NAME,
|
|
101
|
-
d[
|
|
101
|
+
column :NAME, 'Name of the Host', :left, :size => 15 do |d|
|
|
102
|
+
d['NAME']
|
|
102
103
|
end
|
|
103
104
|
|
|
104
|
-
column :CLUSTER,
|
|
105
|
-
OpenNebulaHelper.cluster_str(d[
|
|
105
|
+
column :CLUSTER, 'Name of the Cluster', :left, :size => 9 do |d|
|
|
106
|
+
OpenNebulaHelper.cluster_str(d['CLUSTER'])
|
|
106
107
|
end
|
|
107
108
|
|
|
108
|
-
column :TVM,
|
|
109
|
-
|
|
109
|
+
column :TVM, 'Total Virtual Machines allocated to the Host',
|
|
110
|
+
:size => 3 do |d|
|
|
111
|
+
d['HOST_SHARE']['RUNNING_VMS'] || 0
|
|
110
112
|
end
|
|
111
113
|
|
|
112
|
-
column :ZVM,
|
|
113
|
-
d[
|
|
114
|
+
column :ZVM, 'Number of Virtual Machine zombies', :size => 3 do |d|
|
|
115
|
+
d['TEMPLATE']['TOTAL_ZOMBIES'] || 0
|
|
114
116
|
end
|
|
115
117
|
|
|
116
|
-
column :TCPU,
|
|
117
|
-
d[
|
|
118
|
+
column :TCPU, 'Total CPU percentage', :size => 4 do |d|
|
|
119
|
+
d['HOST_SHARE']['MAX_CPU'] || 0
|
|
118
120
|
end
|
|
119
121
|
|
|
120
|
-
column :FCPU,
|
|
121
|
-
d[
|
|
122
|
-
d[
|
|
122
|
+
column :FCPU, 'Free CPU percentage', :size => 4 do |d|
|
|
123
|
+
d['HOST_SHARE']['MAX_CPU'].to_i -
|
|
124
|
+
d['HOST_SHARE']['USED_CPU'].to_i rescue '-'
|
|
123
125
|
end
|
|
124
126
|
|
|
125
|
-
column :ACPU,
|
|
126
|
-
|
|
127
|
-
max_cpu=d[
|
|
128
|
-
max_cpu=100 if max_cpu
|
|
129
|
-
max_cpu-d[
|
|
127
|
+
column :ACPU, 'Available cpu percentage (not reserved by VMs)',
|
|
128
|
+
:size => 4 do |d|
|
|
129
|
+
max_cpu = d['HOST_SHARE']['MAX_CPU'].to_i
|
|
130
|
+
max_cpu = 100 if max_cpu.zero?
|
|
131
|
+
max_cpu - d['HOST_SHARE']['CPU_USAGE'].to_i
|
|
130
132
|
end
|
|
131
133
|
|
|
132
|
-
column :TMEM,
|
|
134
|
+
column :TMEM, 'Total Memory', :size => 7 do |d|
|
|
133
135
|
OpenNebulaHelper.unit_to_str(
|
|
134
|
-
d[
|
|
135
|
-
options
|
|
136
|
+
d['HOST_SHARE']['MAX_MEM'].to_i,
|
|
137
|
+
options
|
|
138
|
+
) rescue '-'
|
|
136
139
|
end
|
|
137
140
|
|
|
138
|
-
column :FMEM,
|
|
141
|
+
column :FMEM, 'Free Memory', :size => 7 do |d|
|
|
139
142
|
OpenNebulaHelper.unit_to_str(
|
|
140
|
-
d[
|
|
141
|
-
options
|
|
143
|
+
d['HOST_SHARE']['FREE_MEM'].to_i,
|
|
144
|
+
options
|
|
145
|
+
) rescue '-'
|
|
142
146
|
end
|
|
143
147
|
|
|
144
|
-
column :AMEM,
|
|
145
|
-
|
|
146
|
-
acpu=d[
|
|
147
|
-
|
|
148
|
-
OpenNebulaHelper.unit_to_str(acpu,options)
|
|
148
|
+
column :AMEM, 'Available Memory (not reserved by VMs)',
|
|
149
|
+
:size => 7 do |d|
|
|
150
|
+
acpu = d['HOST_SHARE']['MAX_MEM'].to_i -
|
|
151
|
+
d['HOST_SHARE']['MEM_USAGE'].to_i
|
|
152
|
+
OpenNebulaHelper.unit_to_str(acpu, options)
|
|
149
153
|
end
|
|
150
154
|
|
|
151
|
-
column :REAL_CPU,
|
|
152
|
-
max_cpu
|
|
155
|
+
column :REAL_CPU, 'Real CPU', :size => 18 do |d|
|
|
156
|
+
max_cpu = d['HOST_SHARE']['MAX_CPU'].to_i
|
|
153
157
|
|
|
154
158
|
if max_cpu != 0
|
|
155
|
-
used_cpu = d[
|
|
156
|
-
ratio = (used_cpu*100) / max_cpu
|
|
159
|
+
used_cpu = d['HOST_SHARE']['USED_CPU'].to_i
|
|
160
|
+
ratio = (used_cpu * 100) / max_cpu
|
|
157
161
|
"#{used_cpu} / #{max_cpu} (#{ratio}%)"
|
|
158
162
|
else
|
|
159
163
|
'-'
|
|
160
164
|
end
|
|
161
165
|
end
|
|
162
166
|
|
|
163
|
-
column :ALLOCATED_CPU,
|
|
164
|
-
max_cpu
|
|
165
|
-
cpu_usage = d[
|
|
167
|
+
column :ALLOCATED_CPU, 'Allocated CPU)', :size => 18 do |d|
|
|
168
|
+
max_cpu = d['HOST_SHARE']['MAX_CPU'].to_i
|
|
169
|
+
cpu_usage = d['HOST_SHARE']['CPU_USAGE'].to_i
|
|
166
170
|
|
|
167
|
-
if max_cpu
|
|
171
|
+
if max_cpu.zero? && cpu_usage.zero?
|
|
168
172
|
'-'
|
|
169
173
|
else
|
|
170
|
-
cpu_usage = d[
|
|
174
|
+
cpu_usage = d['HOST_SHARE']['CPU_USAGE'].to_i
|
|
171
175
|
|
|
172
176
|
if max_cpu != 0
|
|
173
|
-
ratio
|
|
177
|
+
ratio = (cpu_usage * 100) / max_cpu
|
|
174
178
|
"#{cpu_usage} / #{max_cpu} (#{ratio}%)"
|
|
175
179
|
else
|
|
176
180
|
"#{cpu_usage} / -"
|
|
@@ -178,39 +182,42 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
178
182
|
end
|
|
179
183
|
end
|
|
180
184
|
|
|
181
|
-
column :REAL_MEM,
|
|
182
|
-
max_mem
|
|
185
|
+
column :REAL_MEM, 'Real MEM', :size => 18 do |d|
|
|
186
|
+
max_mem = d['HOST_SHARE']['MAX_MEM'].to_i
|
|
183
187
|
|
|
184
188
|
if max_mem != 0
|
|
185
|
-
used_mem = d[
|
|
186
|
-
ratio = (used_mem*100) / max_mem
|
|
187
|
-
"#{OpenNebulaHelper.unit_to_str(used_mem,options)} /
|
|
189
|
+
used_mem = d['HOST_SHARE']['USED_MEM'].to_i
|
|
190
|
+
ratio = (used_mem * 100) / max_mem
|
|
191
|
+
"#{OpenNebulaHelper.unit_to_str(used_mem, options)} / "\
|
|
192
|
+
"#{OpenNebulaHelper.unit_to_str(max_mem, options)} "\
|
|
193
|
+
"(#{ratio}%)"
|
|
188
194
|
else
|
|
189
195
|
'-'
|
|
190
196
|
end
|
|
191
197
|
end
|
|
192
198
|
|
|
193
|
-
column :ALLOCATED_MEM,
|
|
194
|
-
max_mem
|
|
195
|
-
mem_usage = d[
|
|
199
|
+
column :ALLOCATED_MEM, 'Allocated MEM', :size => 18 do |d|
|
|
200
|
+
max_mem = d['HOST_SHARE']['MAX_MEM'].to_i
|
|
201
|
+
mem_usage = d['HOST_SHARE']['MEM_USAGE'].to_i
|
|
196
202
|
|
|
197
|
-
if max_mem
|
|
203
|
+
if max_mem.zero? && mem_usage.zero?
|
|
198
204
|
'-'
|
|
205
|
+
elsif max_mem != 0
|
|
206
|
+
ratio = (mem_usage * 100) / max_mem
|
|
207
|
+
"#{OpenNebulaHelper.unit_to_str(mem_usage, options)} / "\
|
|
208
|
+
"#{OpenNebulaHelper.unit_to_str(max_mem, options)} "\
|
|
209
|
+
"(#{ratio}%)"
|
|
199
210
|
else
|
|
200
|
-
|
|
201
|
-
ratio = (mem_usage*100) / max_mem
|
|
202
|
-
"#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
|
|
203
|
-
else
|
|
204
|
-
"#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / -"
|
|
205
|
-
end
|
|
211
|
+
"#{OpenNebulaHelper.unit_to_str(mem_usage, options)} / -"
|
|
206
212
|
end
|
|
207
213
|
end
|
|
208
214
|
|
|
209
|
-
column :STAT,
|
|
210
|
-
OneHostHelper.state_to_str(d[
|
|
215
|
+
column :STAT, 'Host status', :left, :size => 6 do |d|
|
|
216
|
+
OneHostHelper.state_to_str(d['STATE'])
|
|
211
217
|
end
|
|
212
218
|
|
|
213
|
-
default :ID, :NAME, :CLUSTER, :TVM,
|
|
219
|
+
default :ID, :NAME, :CLUSTER, :TVM,
|
|
220
|
+
:ALLOCATED_CPU, :ALLOCATED_MEM, :STAT
|
|
214
221
|
end
|
|
215
222
|
|
|
216
223
|
table
|
|
@@ -218,34 +225,37 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
218
225
|
|
|
219
226
|
def set_hybrid(type, path)
|
|
220
227
|
k = type.to_sym
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
|
|
229
|
+
return unless HYBRID.key?(k)
|
|
230
|
+
|
|
231
|
+
return OpenNebulaHelper.editor_input(HYBRID[k][:help]) if path.nil?
|
|
232
|
+
|
|
233
|
+
File.read(path)
|
|
224
234
|
end
|
|
225
235
|
|
|
226
236
|
NUM_THREADS = 15
|
|
227
237
|
def sync(host_ids, options)
|
|
228
|
-
if
|
|
238
|
+
if Process.uid.zero? || Process.gid.zero?
|
|
229
239
|
STDERR.puts("Cannot run 'onehost sync' as root")
|
|
230
|
-
exit
|
|
240
|
+
exit(-1)
|
|
231
241
|
end
|
|
232
242
|
|
|
233
243
|
begin
|
|
234
|
-
current_version = File.read(REMOTES_LOCATION+'/VERSION').strip
|
|
235
|
-
rescue
|
|
244
|
+
current_version = File.read(REMOTES_LOCATION + '/VERSION').strip
|
|
245
|
+
rescue StandardError
|
|
236
246
|
STDERR.puts("Could not read #{REMOTES_LOCATION}/VERSION")
|
|
237
247
|
exit(-1)
|
|
238
248
|
end
|
|
239
249
|
|
|
240
250
|
if current_version.empty?
|
|
241
|
-
STDERR.puts
|
|
251
|
+
STDERR.puts 'Remotes version can not be empty'
|
|
242
252
|
exit(-1)
|
|
243
253
|
end
|
|
244
254
|
|
|
245
255
|
begin
|
|
246
256
|
current_version = Gem::Version.new(current_version)
|
|
247
|
-
rescue
|
|
248
|
-
STDERR.puts
|
|
257
|
+
rescue StandardError
|
|
258
|
+
STDERR.puts 'VERSION file is malformed, use semantic versioning.'
|
|
249
259
|
end
|
|
250
260
|
|
|
251
261
|
cluster_id = options[:cluster]
|
|
@@ -259,13 +269,13 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
259
269
|
|
|
260
270
|
# Verify the existence of REMOTES_LOCATION
|
|
261
271
|
if !File.directory? REMOTES_LOCATION
|
|
262
|
-
error_msg = "'#{REMOTES_LOCATION}' does not exist. "
|
|
263
|
-
|
|
264
|
-
return -1,error_msg
|
|
272
|
+
error_msg = "'#{REMOTES_LOCATION}' does not exist. " \
|
|
273
|
+
'This command must be run in the frontend.'
|
|
274
|
+
return -1, error_msg
|
|
265
275
|
end
|
|
266
276
|
|
|
267
277
|
# Touch the update file
|
|
268
|
-
FileUtils.touch(File.join(REMOTES_LOCATION,'.update'))
|
|
278
|
+
FileUtils.touch(File.join(REMOTES_LOCATION, '.update'))
|
|
269
279
|
|
|
270
280
|
# Get the Host pool
|
|
271
281
|
filter_flag ||= OpenNebula::Pool::INFO_ALL
|
|
@@ -276,18 +286,16 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
276
286
|
return -1, rc.message if OpenNebula.is_error?(rc)
|
|
277
287
|
|
|
278
288
|
# Assign hosts to threads
|
|
279
|
-
|
|
280
|
-
queue = Array.new
|
|
289
|
+
queue = []
|
|
281
290
|
|
|
282
291
|
pool.each do |host|
|
|
283
292
|
if host_ids
|
|
284
|
-
next
|
|
293
|
+
next unless host_ids.include?(host['ID'].to_i)
|
|
285
294
|
elsif cluster_id
|
|
286
295
|
next if host['CLUSTER_ID'].to_i != cluster_id
|
|
287
296
|
end
|
|
288
297
|
|
|
289
298
|
vm_mad = host['VM_MAD'].downcase
|
|
290
|
-
remote_remotes = host['TEMPLATE/REMOTE_REMOTES']
|
|
291
299
|
state = host['STATE']
|
|
292
300
|
|
|
293
301
|
# Skip this host from remote syncing if it's a PUBLIC_CLOUD host
|
|
@@ -297,20 +305,22 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
297
305
|
next if Host::HOST_STATES[state.to_i] == 'OFFLINE'
|
|
298
306
|
|
|
299
307
|
# Skip this host if it is a vCenter cluster
|
|
300
|
-
next if vm_mad ==
|
|
308
|
+
next if vm_mad == 'vcenter'
|
|
301
309
|
|
|
302
|
-
host_version=host['TEMPLATE/VERSION']
|
|
310
|
+
host_version = host['TEMPLATE/VERSION']
|
|
303
311
|
|
|
304
312
|
begin
|
|
305
313
|
host_version = Gem::Version.new(host_version)
|
|
306
|
-
rescue
|
|
314
|
+
rescue StandardError
|
|
315
|
+
nil
|
|
307
316
|
end
|
|
308
317
|
|
|
309
318
|
if !options[:force]
|
|
310
319
|
begin
|
|
311
320
|
next if host_version && host_version >= current_version
|
|
312
|
-
rescue
|
|
313
|
-
STDERR.puts
|
|
321
|
+
rescue StandardError
|
|
322
|
+
STDERR.puts 'Error comparing versions '\
|
|
323
|
+
" for host #{host['NAME']}."
|
|
314
324
|
end
|
|
315
325
|
end
|
|
316
326
|
|
|
@@ -320,45 +330,45 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
320
330
|
end
|
|
321
331
|
|
|
322
332
|
# Run the jobs in threads
|
|
323
|
-
host_errors =
|
|
333
|
+
host_errors = []
|
|
324
334
|
queue_lock = Mutex.new
|
|
325
335
|
error_lock = Mutex.new
|
|
326
336
|
total = queue.length
|
|
327
337
|
|
|
328
|
-
if total
|
|
329
|
-
puts
|
|
338
|
+
if total.zero?
|
|
339
|
+
puts 'No hosts are going to be updated.'
|
|
330
340
|
exit(0)
|
|
331
341
|
end
|
|
332
342
|
|
|
333
|
-
ts = (1..NUM_THREADS).map do |
|
|
343
|
+
ts = (1..NUM_THREADS).map do |_t|
|
|
334
344
|
Thread.new do
|
|
335
|
-
|
|
345
|
+
loop do
|
|
336
346
|
host = nil
|
|
337
347
|
size = 0
|
|
338
348
|
|
|
339
349
|
queue_lock.synchronize do
|
|
340
|
-
host=queue.shift
|
|
341
|
-
size=queue.length
|
|
350
|
+
host = queue.shift
|
|
351
|
+
size = queue.length
|
|
342
352
|
end
|
|
343
353
|
|
|
344
|
-
break
|
|
354
|
+
break unless host
|
|
345
355
|
|
|
346
|
-
print_update_info(total-size, total, host['NAME'])
|
|
356
|
+
print_update_info(total - size, total, host['NAME'])
|
|
347
357
|
|
|
348
358
|
if options[:rsync]
|
|
349
|
-
sync_cmd = "rsync -Laz --delete #{REMOTES_LOCATION}"
|
|
350
|
-
|
|
359
|
+
sync_cmd = "rsync -Laz --delete #{REMOTES_LOCATION}" \
|
|
360
|
+
" #{host['NAME']}:#{remote_dir}"
|
|
351
361
|
else
|
|
352
|
-
sync_cmd = "scp -rp #{REMOTES_LOCATION}/. "
|
|
353
|
-
|
|
362
|
+
sync_cmd = "scp -rp #{REMOTES_LOCATION}/. " \
|
|
363
|
+
"#{host['NAME']}:#{remote_dir} 2> /dev/null"
|
|
354
364
|
end
|
|
355
365
|
|
|
356
366
|
`#{sync_cmd} 2>/dev/null`
|
|
357
367
|
|
|
358
|
-
if
|
|
359
|
-
error_lock.synchronize
|
|
368
|
+
if !$CHILD_STATUS.success?
|
|
369
|
+
error_lock.synchronize do
|
|
360
370
|
host_errors << host['NAME']
|
|
361
|
-
|
|
371
|
+
end
|
|
362
372
|
else
|
|
363
373
|
update_version(host, current_version)
|
|
364
374
|
end
|
|
@@ -367,16 +377,108 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
367
377
|
end
|
|
368
378
|
|
|
369
379
|
# Wait for threads to finish
|
|
370
|
-
ts.each{|t| t.join}
|
|
380
|
+
ts.each {|t| t.join }
|
|
371
381
|
|
|
372
382
|
puts
|
|
373
383
|
|
|
374
384
|
if host_errors.empty?
|
|
375
|
-
puts
|
|
385
|
+
puts 'All hosts updated successfully.'
|
|
376
386
|
0
|
|
377
387
|
else
|
|
378
|
-
STDERR.puts
|
|
379
|
-
host_errors.each{|h| STDERR.puts "* #{h}"}
|
|
388
|
+
STDERR.puts 'Failed to update the following hosts:'
|
|
389
|
+
host_errors.each {|h| STDERR.puts "* #{h}" }
|
|
390
|
+
-1
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
def forceupdate(host_ids, options)
|
|
395
|
+
if Process.uid.zero? || Process.gid.zero?
|
|
396
|
+
STDERR.puts("Cannot run 'onehost forceupdate' as root")
|
|
397
|
+
exit(-1)
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
cluster_id = options[:cluster]
|
|
401
|
+
|
|
402
|
+
# Get the Host pool
|
|
403
|
+
filter_flag ||= OpenNebula::Pool::INFO_ALL
|
|
404
|
+
|
|
405
|
+
pool = factory_pool(filter_flag)
|
|
406
|
+
|
|
407
|
+
rc = pool.info
|
|
408
|
+
return -1, rc.message if OpenNebula.is_error?(rc)
|
|
409
|
+
|
|
410
|
+
# Assign hosts to threads
|
|
411
|
+
queue = []
|
|
412
|
+
|
|
413
|
+
pool.each do |host|
|
|
414
|
+
if host_ids
|
|
415
|
+
next unless host_ids.include?(host['ID'].to_i)
|
|
416
|
+
elsif cluster_id
|
|
417
|
+
next if host['CLUSTER_ID'].to_i != cluster_id
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
vm_mad = host['VM_MAD'].downcase
|
|
421
|
+
state = host['STATE']
|
|
422
|
+
|
|
423
|
+
# Skip this host from remote syncing if it's a PUBLIC_CLOUD host
|
|
424
|
+
next if host['TEMPLATE/PUBLIC_CLOUD'] == 'YES'
|
|
425
|
+
|
|
426
|
+
# Skip this host from remote syncing if it's OFFLINE
|
|
427
|
+
next if Host::HOST_STATES[state.to_i] == 'OFFLINE'
|
|
428
|
+
|
|
429
|
+
# Skip this host if it is a vCenter cluster
|
|
430
|
+
next if vm_mad == 'vcenter'
|
|
431
|
+
|
|
432
|
+
queue << host
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
# Run the jobs in threads
|
|
436
|
+
host_errors = []
|
|
437
|
+
queue_lock = Mutex.new
|
|
438
|
+
error_lock = Mutex.new
|
|
439
|
+
total = queue.length
|
|
440
|
+
|
|
441
|
+
if total.zero?
|
|
442
|
+
puts 'No hosts are going to be forced.'
|
|
443
|
+
exit(0)
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
ts = (1..NUM_THREADS).map do |_t|
|
|
447
|
+
Thread.new do
|
|
448
|
+
loop do
|
|
449
|
+
host = nil
|
|
450
|
+
size = 0
|
|
451
|
+
|
|
452
|
+
queue_lock.synchronize do
|
|
453
|
+
host = queue.shift
|
|
454
|
+
size = queue.length
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
break unless host
|
|
458
|
+
|
|
459
|
+
cmd = 'cat /tmp/one-collectd-client.pid | xargs kill -HUP'
|
|
460
|
+
system("ssh #{host['NAME']} \"#{cmd}\" 2>/dev/null")
|
|
461
|
+
|
|
462
|
+
if !$CHILD_STATUS.success?
|
|
463
|
+
error_lock.synchronize do
|
|
464
|
+
host_errors << host['NAME']
|
|
465
|
+
end
|
|
466
|
+
else
|
|
467
|
+
puts "#{host['NAME']} monitoring forced"
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
# Wait for threads to finish
|
|
474
|
+
ts.each {|t| t.join }
|
|
475
|
+
|
|
476
|
+
if host_errors.empty?
|
|
477
|
+
puts 'All hosts updated successfully.'
|
|
478
|
+
0
|
|
479
|
+
else
|
|
480
|
+
STDERR.puts 'Failed to update the following hosts:'
|
|
481
|
+
host_errors.each {|h| STDERR.puts "* #{h}" }
|
|
380
482
|
-1
|
|
381
483
|
end
|
|
382
484
|
end
|
|
@@ -384,22 +486,22 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
384
486
|
private
|
|
385
487
|
|
|
386
488
|
def print_update_info(current, total, host)
|
|
387
|
-
bar_length=40
|
|
489
|
+
bar_length = 40
|
|
388
490
|
|
|
389
|
-
percentage=current.to_f/total.to_f
|
|
390
|
-
done=(percentage*bar_length).floor
|
|
491
|
+
percentage = current.to_f / total.to_f
|
|
492
|
+
done = (percentage * bar_length).floor
|
|
391
493
|
|
|
392
|
-
bar=
|
|
393
|
-
bar+=
|
|
394
|
-
bar+=
|
|
395
|
-
bar+=
|
|
494
|
+
bar = '['
|
|
495
|
+
bar += '=' * done
|
|
496
|
+
bar += '-' * (bar_length - done)
|
|
497
|
+
bar += ']'
|
|
396
498
|
|
|
397
|
-
info="#{current}/#{total}"
|
|
499
|
+
info = "#{current}/#{total}"
|
|
398
500
|
|
|
399
|
-
str="#{bar} #{info} "
|
|
400
|
-
name=host[0..(79-str.length)]
|
|
401
|
-
str
|
|
402
|
-
str
|
|
501
|
+
str = "#{bar} #{info} "
|
|
502
|
+
name = host[0..(79 - str.length)]
|
|
503
|
+
str += name
|
|
504
|
+
str += ' ' * (80 - str.length)
|
|
403
505
|
|
|
404
506
|
print "#{str}\r"
|
|
405
507
|
STDOUT.flush
|
|
@@ -412,54 +514,65 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
412
514
|
|
|
413
515
|
host.add_element(TEMPLATE_XPATH, 'VERSION' => version)
|
|
414
516
|
|
|
415
|
-
template=host.template_str
|
|
517
|
+
template = host.template_str
|
|
416
518
|
host.update(template)
|
|
417
519
|
end
|
|
418
520
|
|
|
419
|
-
def factory(id=nil)
|
|
521
|
+
def factory(id = nil)
|
|
420
522
|
if id
|
|
421
523
|
OpenNebula::Host.new_with_id(id, @client)
|
|
422
524
|
else
|
|
423
|
-
xml=OpenNebula::Host.build_xml
|
|
525
|
+
xml = OpenNebula::Host.build_xml
|
|
424
526
|
OpenNebula::Host.new(xml, @client)
|
|
425
527
|
end
|
|
426
528
|
end
|
|
427
529
|
|
|
428
|
-
def factory_pool(
|
|
429
|
-
#TBD OpenNebula::HostPool.new(@client, user_flag)
|
|
530
|
+
def factory_pool(_user_flag = -2)
|
|
531
|
+
# TBD OpenNebula::HostPool.new(@client, user_flag)
|
|
430
532
|
OpenNebula::HostPool.new(@client)
|
|
431
533
|
end
|
|
432
534
|
|
|
433
|
-
def format_resource(host,
|
|
434
|
-
str =
|
|
435
|
-
str_h1 =
|
|
535
|
+
def format_resource(host, _options = {})
|
|
536
|
+
str = '%-22s: %-20s'
|
|
537
|
+
str_h1 = '%-80s'
|
|
436
538
|
|
|
437
539
|
CLIHelper.print_header(
|
|
438
|
-
str_h1 % "HOST #{host.id
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
puts str
|
|
442
|
-
puts str
|
|
443
|
-
puts str
|
|
444
|
-
|
|
445
|
-
puts str
|
|
446
|
-
puts str
|
|
540
|
+
str_h1 % "HOST #{host.id} INFORMATION", true
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
puts format(str, 'ID', host.id.to_s)
|
|
544
|
+
puts format(str, 'NAME', host.name)
|
|
545
|
+
puts format(str, 'CLUSTER',
|
|
546
|
+
OpenNebulaHelper.cluster_str(host['CLUSTER']))
|
|
547
|
+
puts format(str, 'STATE', host.state_str)
|
|
548
|
+
puts format(str, 'IM_MAD', host['IM_MAD'])
|
|
549
|
+
puts format(str, 'VM_MAD', host['VM_MAD'])
|
|
550
|
+
puts format(str, 'LAST MONITORING TIME',
|
|
551
|
+
OpenNebulaHelper.time_to_str(host['LAST_MON_TIME']))
|
|
447
552
|
puts
|
|
448
553
|
|
|
449
|
-
CLIHelper.print_header(str_h1 %
|
|
450
|
-
puts str
|
|
451
|
-
|
|
452
|
-
CLIHelper.print_header(str_h1 %
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
554
|
+
CLIHelper.print_header(str_h1 % 'HOST SHARES', false)
|
|
555
|
+
puts format(str, 'RUNNING VMS', host['HOST_SHARE/RUNNING_VMS'])
|
|
556
|
+
|
|
557
|
+
CLIHelper.print_header(str_h1 % 'MEMORY', false)
|
|
558
|
+
puts format(str, ' TOTAL',
|
|
559
|
+
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/TOTAL_MEM']
|
|
560
|
+
.to_i, {}))
|
|
561
|
+
puts format(str, ' TOTAL +/- RESERVED',
|
|
562
|
+
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM']
|
|
563
|
+
.to_i, {}))
|
|
564
|
+
puts format(str, ' USED (REAL)',
|
|
565
|
+
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM']
|
|
566
|
+
.to_i, {}))
|
|
567
|
+
puts format(str, ' USED (ALLOCATED)',
|
|
568
|
+
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE']
|
|
569
|
+
.to_i, {}))
|
|
570
|
+
|
|
571
|
+
CLIHelper.print_header(str_h1 % 'CPU', false)
|
|
572
|
+
puts format(str, ' TOTAL', host['HOST_SHARE/TOTAL_CPU'])
|
|
573
|
+
puts format(str, ' TOTAL +/- RESERVED', host['HOST_SHARE/MAX_CPU'])
|
|
574
|
+
puts format(str, ' USED (REAL)', host['HOST_SHARE/USED_CPU'])
|
|
575
|
+
puts format(str, ' USED (ALLOCATED)', host['HOST_SHARE/CPU_USAGE'])
|
|
463
576
|
puts
|
|
464
577
|
|
|
465
578
|
datastores = host.to_hash['HOST']['HOST_SHARE']['DATASTORES']['DS']
|
|
@@ -471,26 +584,34 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
471
584
|
end
|
|
472
585
|
|
|
473
586
|
datastores.each do |datastore|
|
|
474
|
-
CLIHelper.print_header(str_h1 %
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
puts str
|
|
587
|
+
CLIHelper.print_header(str_h1 %
|
|
588
|
+
'LOCAL SYSTEM DATASTORE '\
|
|
589
|
+
"##{datastore['ID']} CAPACITY", false)
|
|
590
|
+
puts format(str, 'TOTAL:',
|
|
591
|
+
OpenNebulaHelper.unit_to_str(datastore['TOTAL_MB']
|
|
592
|
+
.to_i, {}, 'M'))
|
|
593
|
+
puts format(str, 'USED: ',
|
|
594
|
+
OpenNebulaHelper.unit_to_str(datastore['USED_MB']
|
|
595
|
+
.to_i, {}, 'M'))
|
|
596
|
+
puts format(str, 'FREE:',
|
|
597
|
+
OpenNebulaHelper.unit_to_str(datastore['FREE_MB']
|
|
598
|
+
.to_i, {}, 'M'))
|
|
478
599
|
puts
|
|
479
600
|
end
|
|
480
601
|
|
|
481
|
-
CLIHelper.print_header(str_h1 %
|
|
602
|
+
CLIHelper.print_header(str_h1 % 'MONITORING INFORMATION', false)
|
|
482
603
|
|
|
483
604
|
wilds = host.wilds
|
|
484
605
|
|
|
485
606
|
begin
|
|
486
607
|
pcis = [host.to_hash['HOST']['HOST_SHARE']['PCI_DEVICES']['PCI']]
|
|
487
608
|
pcis = pcis.flatten.compact
|
|
488
|
-
rescue
|
|
609
|
+
rescue StandardError
|
|
489
610
|
pcis = nil
|
|
490
611
|
end
|
|
491
612
|
|
|
492
|
-
host.delete_element(
|
|
493
|
-
host.delete_element(
|
|
613
|
+
host.delete_element('TEMPLATE/VM')
|
|
614
|
+
host.delete_element('TEMPLATE_WILDS')
|
|
494
615
|
|
|
495
616
|
puts host.template_str
|
|
496
617
|
|
|
@@ -499,81 +620,85 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
|
|
499
620
|
end
|
|
500
621
|
|
|
501
622
|
puts
|
|
502
|
-
CLIHelper.print_header(
|
|
623
|
+
CLIHelper.print_header('WILD VIRTUAL MACHINES', false)
|
|
503
624
|
puts
|
|
504
625
|
|
|
505
|
-
format =
|
|
506
|
-
CLIHelper.print_header(format
|
|
626
|
+
format = '%-30.30s %36s %4s %10s'
|
|
627
|
+
CLIHelper.print_header(format(format, 'NAME',
|
|
628
|
+
'IMPORT_ID', 'CPU', 'MEMORY'),
|
|
507
629
|
true)
|
|
508
630
|
|
|
509
631
|
wilds.each do |wild|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
632
|
+
if wild['IMPORT_TEMPLATE']
|
|
633
|
+
wild_tmplt = Base64.decode64(wild['IMPORT_TEMPLATE'])
|
|
634
|
+
.split("\n")
|
|
635
|
+
name = wild['VM_NAME']
|
|
636
|
+
import = wild_tmplt.select do |line|
|
|
637
|
+
line[/^IMPORT_VM_ID/]
|
|
638
|
+
end[0].split('=')[1].tr('"', ' ').strip
|
|
639
|
+
memory = wild_tmplt.select do |line|
|
|
640
|
+
line[/^MEMORY/]
|
|
641
|
+
end[0].split('=')[1].tr('"', ' ').strip
|
|
642
|
+
cpu = wild_tmplt.select do |line|
|
|
643
|
+
line[/^CPU/]
|
|
644
|
+
end[0].split('=')[1].tr('"', ' ').strip
|
|
645
|
+
else
|
|
646
|
+
name = wild['DEPLOY_ID']
|
|
647
|
+
import = memory = cpu = '-'
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
puts format(format, name, import, cpu, memory)
|
|
528
651
|
end
|
|
529
652
|
|
|
530
653
|
puts
|
|
531
|
-
CLIHelper.print_header(
|
|
654
|
+
CLIHelper.print_header('VIRTUAL MACHINES', false)
|
|
532
655
|
puts
|
|
533
656
|
|
|
534
|
-
onevm_helper=OneVMHelper.new
|
|
535
|
-
onevm_helper.client
|
|
536
|
-
onevm_helper.list_pool({:filter=>["HOST=#{host.name}"],
|
|
657
|
+
onevm_helper = OneVMHelper.new
|
|
658
|
+
onevm_helper.client = @client
|
|
659
|
+
onevm_helper.list_pool({ :filter => ["HOST=#{host.name}"],
|
|
660
|
+
:no_pager => true },
|
|
661
|
+
false)
|
|
537
662
|
end
|
|
538
663
|
|
|
539
664
|
def print_pcis(pcis)
|
|
540
665
|
puts
|
|
541
|
-
CLIHelper.print_header(
|
|
666
|
+
CLIHelper.print_header('PCI DEVICES', false)
|
|
542
667
|
puts
|
|
543
668
|
|
|
544
|
-
table=CLIHelper::ShowTable.new(nil, self) do
|
|
545
|
-
column :VM,
|
|
546
|
-
if d[
|
|
547
|
-
|
|
669
|
+
table = CLIHelper::ShowTable.new(nil, self) do
|
|
670
|
+
column :VM, 'Used by VM', :size => 5, :left => false do |d|
|
|
671
|
+
if d['VMID'] == '-1'
|
|
672
|
+
''
|
|
548
673
|
else
|
|
549
|
-
d[
|
|
674
|
+
d['VMID']
|
|
550
675
|
end
|
|
551
676
|
end
|
|
552
677
|
|
|
553
|
-
column :ADDR,
|
|
554
|
-
d[
|
|
678
|
+
column :ADDR, 'PCI Address', :size => 7, :left => true do |d|
|
|
679
|
+
d['SHORT_ADDRESS']
|
|
555
680
|
end
|
|
556
681
|
|
|
557
|
-
column :TYPE,
|
|
558
|
-
d[
|
|
682
|
+
column :TYPE, 'Type', :size => 14, :left => true do |d|
|
|
683
|
+
d['TYPE']
|
|
559
684
|
end
|
|
560
685
|
|
|
561
|
-
column :CLASS,
|
|
562
|
-
d[
|
|
686
|
+
column :CLASS, 'Class', :size => 12, :left => true do |d|
|
|
687
|
+
d['CLASS_NAME']
|
|
563
688
|
end
|
|
564
689
|
|
|
565
|
-
column :NAME,
|
|
566
|
-
d[
|
|
690
|
+
column :NAME, 'Name', :size => 50, :left => true do |d|
|
|
691
|
+
d['DEVICE_NAME']
|
|
567
692
|
end
|
|
568
693
|
|
|
569
|
-
column :VENDOR,
|
|
570
|
-
d[
|
|
694
|
+
column :VENDOR, 'Vendor', :size => 8, :left => true do |d|
|
|
695
|
+
d['VENDOR_NAME']
|
|
571
696
|
end
|
|
572
697
|
|
|
573
698
|
default :VM, :ADDR, :TYPE, :NAME
|
|
574
|
-
|
|
575
699
|
end
|
|
576
700
|
|
|
577
701
|
table.show(pcis)
|
|
578
702
|
end
|
|
703
|
+
|
|
579
704
|
end
|