opennebula-cli 6.0.0.2 → 6.1.80.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/oneflow +76 -5
- data/bin/oneflow-template +4 -5
- data/bin/oneimage +2 -2
- data/bin/onemarket +20 -0
- data/bin/onevcenter +15 -6
- data/bin/onevm +9 -66
- data/bin/onezone +20 -0
- data/lib/one_helper/onemarket_helper.rb +12 -1
- data/lib/one_helper/onevcenter_helper.rb +2 -2
- data/lib/one_helper/onevm_helper.rb +98 -36
- data/lib/one_helper/onezone_helper.rb +13 -1
- data/lib/one_helper.rb +114 -125
- data/share/schemas/xsd/api_info.xsd +2 -2
- data/share/schemas/xsd/hook_message_api.xsd +1 -1
- data/share/schemas/xsd/hook_message_state.xsd +1 -1
- data/share/schemas/xsd/host.xsd +21 -1
- data/share/schemas/xsd/marketplace.xsd +1 -0
- data/share/schemas/xsd/monitoring_data.xsd +23 -11
- data/share/schemas/xsd/vm.xsd +64 -10
- data/share/schemas/xsd/vm_pool.xsd +3 -26
- data/share/schemas/xsd/vnet.xsd +4 -1
- data/share/schemas/xsd/zone.xsd +1 -0
- data/share/schemas/xsd/zone_pool.xsd +2 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2306988d8afeaa179ef65f89fbb07a27746a370b
|
4
|
+
data.tar.gz: 443a4f8d1aa6fcbfb886c14c2fe3228e3d67bff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1df610ba16fd464d6429e9ebf26fcecb1872319ff6795cca452917c6258df631b688f59fb8cd416143da7cf40e16c4bdbd73db052f4c2faa9b4da4b011fb920
|
7
|
+
data.tar.gz: 8bfc858b932ec71fdc86e6bef789957d55401190bc780f90c1630b6808651cbdd2a02dc970bf79f2bf17d406422268804ff1954be9ae46a0087bb88d28fc518d
|
data/bin/oneflow
CHANGED
@@ -82,6 +82,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
82
82
|
:description => 'Force flow necover delete'
|
83
83
|
}
|
84
84
|
|
85
|
+
FORMAT = [OpenNebulaHelper::JSON, OpenNebulaHelper::YAML]
|
86
|
+
|
85
87
|
# create helper object
|
86
88
|
helper = OneFlowHelper.new
|
87
89
|
|
@@ -122,7 +124,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
122
124
|
List the available services
|
123
125
|
EOT
|
124
126
|
|
125
|
-
command :list, list_desc, :options =>
|
127
|
+
command :list, list_desc, :options => FORMAT do
|
126
128
|
helper.list_service_pool(helper.client(options), options)
|
127
129
|
end
|
128
130
|
|
@@ -146,10 +148,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
146
148
|
Show detailed information of a given service
|
147
149
|
EOT
|
148
150
|
|
149
|
-
command :show,
|
150
|
-
show_desc,
|
151
|
-
:service_id,
|
152
|
-
:options => OpenNebulaHelper::FORMAT do
|
151
|
+
command :show, show_desc, :service_id, :options => FORMAT do
|
153
152
|
helper.format_resource(helper.client(options), args[0], options)
|
154
153
|
end
|
155
154
|
|
@@ -428,4 +427,76 @@ CommandParser::CmdParser.new(ARGV) do
|
|
428
427
|
0
|
429
428
|
end
|
430
429
|
end
|
430
|
+
|
431
|
+
###
|
432
|
+
|
433
|
+
add_role_desc = <<-EOT.unindent
|
434
|
+
Add new role to running service
|
435
|
+
EOT
|
436
|
+
|
437
|
+
command :'add-role', add_role_desc, :service_id, [:file, nil] do
|
438
|
+
service_id = args[0]
|
439
|
+
client = helper.client(options)
|
440
|
+
|
441
|
+
if args[1]
|
442
|
+
path = args[1]
|
443
|
+
else
|
444
|
+
tmp = Tempfile.new(service_id.to_s)
|
445
|
+
path = tmp.path
|
446
|
+
|
447
|
+
if ENV['EDITOR']
|
448
|
+
editor_path = ENV['EDITOR']
|
449
|
+
else
|
450
|
+
editor_path = OpenNebulaHelper::EDITOR_PATH
|
451
|
+
end
|
452
|
+
|
453
|
+
system("#{editor_path} #{path}")
|
454
|
+
|
455
|
+
unless $CHILD_STATUS.exitstatus.zero?
|
456
|
+
STDERR.puts 'Editor not defined'
|
457
|
+
exit(-1)
|
458
|
+
end
|
459
|
+
|
460
|
+
tmp.close
|
461
|
+
end
|
462
|
+
|
463
|
+
params = {}
|
464
|
+
params[:role] = File.read(path)
|
465
|
+
params[:add] = true
|
466
|
+
json = Service.build_json_action('add_role', params)
|
467
|
+
|
468
|
+
response = client.post("#{RESOURCE_PATH}/#{service_id}/role_action",
|
469
|
+
json)
|
470
|
+
|
471
|
+
if CloudClient.is_error?(response)
|
472
|
+
[response.code.to_i, response.to_s]
|
473
|
+
else
|
474
|
+
0
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
###
|
479
|
+
|
480
|
+
remove_role_desc = <<-EOT.unindent
|
481
|
+
Remove role from running service
|
482
|
+
EOT
|
483
|
+
|
484
|
+
command :'remove-role', remove_role_desc, :service_id, :role_name do
|
485
|
+
service_id = args[0]
|
486
|
+
client = helper.client(options)
|
487
|
+
|
488
|
+
params = {}
|
489
|
+
params[:role] = args[1]
|
490
|
+
params[:add] = false
|
491
|
+
json = Service.build_json_action('remove_role', params)
|
492
|
+
|
493
|
+
response = client.post("#{RESOURCE_PATH}/#{service_id}/role_action",
|
494
|
+
json)
|
495
|
+
|
496
|
+
if CloudClient.is_error?(response)
|
497
|
+
[response.code.to_i, response.to_s]
|
498
|
+
else
|
499
|
+
0
|
500
|
+
end
|
501
|
+
end
|
431
502
|
end
|
data/bin/oneflow-template
CHANGED
@@ -104,6 +104,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
104
104
|
'deleting service template'
|
105
105
|
}
|
106
106
|
|
107
|
+
FORMAT = [OpenNebulaHelper::JSON, OpenNebulaHelper::YAML]
|
108
|
+
|
107
109
|
usage '`oneflow-template` <command> [<args>] [<options>]'
|
108
110
|
version OpenNebulaHelper::ONE_VERSION
|
109
111
|
|
@@ -141,7 +143,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
141
143
|
List the available Service Templates
|
142
144
|
EOT
|
143
145
|
|
144
|
-
command :list, list_desc, :options =>
|
146
|
+
command :list, list_desc, :options => FORMAT do
|
145
147
|
helper.list_service_template_pool(helper.client(options), options)
|
146
148
|
end
|
147
149
|
|
@@ -169,10 +171,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
169
171
|
Show detailed information of a given Service Template
|
170
172
|
EOT
|
171
173
|
|
172
|
-
command :show,
|
173
|
-
show_desc,
|
174
|
-
:templateid,
|
175
|
-
:options => OpenNebulaHelper::FORMAT do
|
174
|
+
command :show, show_desc, :templateid, :options => FORMAT do
|
176
175
|
helper.format_resource(helper.client(options), args[0], options)
|
177
176
|
end
|
178
177
|
|
data/bin/oneimage
CHANGED
@@ -160,8 +160,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
160
160
|
|
161
161
|
oneimage create -d 1 --name ubuntu --path /tmp/ubuntu.qcow2 \\
|
162
162
|
--prefix sd --type OS --driver qcow2 \\
|
163
|
-
--description "A OS plain installation \\
|
164
|
-
--persistent
|
163
|
+
--description "A OS plain installation" \\
|
164
|
+
--persistent
|
165
165
|
|
166
166
|
- a datablock image of 400MB:
|
167
167
|
|
data/bin/onemarket
CHANGED
@@ -199,4 +199,24 @@ CommandParser::CmdParser.new(ARGV) do
|
|
199
199
|
o.rename(args[1])
|
200
200
|
end
|
201
201
|
end
|
202
|
+
|
203
|
+
enable_desc = <<-EOT.unindent
|
204
|
+
Enables the marketplace
|
205
|
+
EOT
|
206
|
+
|
207
|
+
command :enable, enable_desc, [:range, :marketplaceid_list] do
|
208
|
+
helper.perform_actions(args[0], options, 'enabled') do |obj|
|
209
|
+
obj.enable
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
disable_desc = <<-EOT.unindent
|
214
|
+
Disables the marketplace. Remove all its apps.
|
215
|
+
EOT
|
216
|
+
|
217
|
+
command :disable, disable_desc, [:range, :marketplaceid_list] do
|
218
|
+
helper.perform_actions(args[0], options, 'disabled') do |obj|
|
219
|
+
obj.disable
|
220
|
+
end
|
221
|
+
end
|
202
222
|
end
|
data/bin/onevcenter
CHANGED
@@ -165,7 +165,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
165
165
|
|
166
166
|
command :list,
|
167
167
|
list_desc,
|
168
|
-
:options => [OBJECT, HOST, DATASTORE, VCENTER, USER, PASS
|
168
|
+
:options => [OBJECT, HOST, DATASTORE, VCENTER, USER, PASS,
|
169
|
+
CLIHelper::CSV_OPT] do
|
169
170
|
begin
|
170
171
|
args = helper.parse_opts(options)
|
171
172
|
args[:filter] = true
|
@@ -178,7 +179,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
178
179
|
|
179
180
|
helper.list_object(options, list)
|
180
181
|
rescue StandardError => e
|
181
|
-
puts e.message
|
182
|
+
STDERR.puts e.message
|
183
|
+
exit 1
|
182
184
|
end
|
183
185
|
|
184
186
|
exit 0
|
@@ -209,7 +211,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
209
211
|
|
210
212
|
helper.list_object(options, list)
|
211
213
|
rescue StandardError => e
|
212
|
-
puts e.message
|
214
|
+
STDERR.puts e.message
|
215
|
+
exit 1
|
213
216
|
end
|
214
217
|
|
215
218
|
exit 0
|
@@ -256,7 +259,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
256
259
|
|
257
260
|
importer.stdout
|
258
261
|
rescue StandardError => e
|
259
|
-
puts e.message
|
262
|
+
STDERR.puts e.message
|
263
|
+
exit 1
|
260
264
|
end
|
261
265
|
|
262
266
|
exit 0
|
@@ -283,7 +287,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
283
287
|
|
284
288
|
importer.stdout
|
285
289
|
rescue StandardError => e
|
286
|
-
puts e.message
|
290
|
+
STDERR.puts e.message
|
291
|
+
exit 1
|
287
292
|
end
|
288
293
|
|
289
294
|
exit 0
|
@@ -305,7 +310,11 @@ CommandParser::CmdParser.new(ARGV) do
|
|
305
310
|
:options => [VCENTER, USER, PASS, USE_DEFAULTS, PORT] do
|
306
311
|
con_ops = helper.connection_options('Hosts', options)
|
307
312
|
|
308
|
-
|
313
|
+
begin
|
314
|
+
VCenterDriver::VcImporter.import_clusters(con_ops, options)
|
315
|
+
rescue StandardError
|
316
|
+
exit 1
|
317
|
+
end
|
309
318
|
|
310
319
|
exit 0
|
311
320
|
end
|
data/bin/onevm
CHANGED
@@ -1305,7 +1305,8 @@ CommandParser::CmdParser.new(ARGV) do
|
|
1305
1305
|
CONTEXT (any value, **variable substitution will be made**)
|
1306
1306
|
EOT
|
1307
1307
|
|
1308
|
-
command :updateconf, updateconf_desc, :vmid, [:file, nil]
|
1308
|
+
command :updateconf, updateconf_desc, :vmid, [:file, nil],
|
1309
|
+
:options => OpenNebulaHelper::APPEND do
|
1309
1310
|
template = ''
|
1310
1311
|
|
1311
1312
|
begin
|
@@ -1332,7 +1333,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
1332
1333
|
template = OpenNebulaHelper.editor_input(template)
|
1333
1334
|
end
|
1334
1335
|
|
1335
|
-
vm.updateconf(template)
|
1336
|
+
vm.updateconf(template, options[:append])
|
1336
1337
|
end
|
1337
1338
|
end
|
1338
1339
|
|
@@ -1411,22 +1412,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
1411
1412
|
|
1412
1413
|
command :'delete-chart', delete_chart_desc, :vmid, :sched_id do
|
1413
1414
|
helper.perform_action(args[0], {}, 'Charter deleted') do |vm|
|
1414
|
-
rc = vm.
|
1415
|
-
|
1416
|
-
if OpenNebula.is_error?(rc)
|
1417
|
-
STDERR.puts "Error #{rc.message}"
|
1418
|
-
exit(-1)
|
1419
|
-
end
|
1420
|
-
|
1421
|
-
xpath = "USER_TEMPLATE/SCHED_ACTION[ID=#{args[1]}]"
|
1422
|
-
|
1423
|
-
unless vm.retrieve_elements(xpath)
|
1424
|
-
STDERR.puts "Sched action #{args[1]} not found"
|
1425
|
-
exit(-1)
|
1426
|
-
end
|
1427
|
-
|
1428
|
-
vm.delete_element(xpath)
|
1429
|
-
rc = vm.update(vm.user_template_str)
|
1415
|
+
rc = vm.sched_action_delete(args[1])
|
1430
1416
|
|
1431
1417
|
if OpenNebula.is_error?(rc)
|
1432
1418
|
STDERR.puts "Error deleting: #{rc.message}"
|
@@ -1571,52 +1557,7 @@ CommandParser::CmdParser.new(ARGV) do
|
|
1571
1557
|
:vmid,
|
1572
1558
|
[:login, nil],
|
1573
1559
|
:options => [NIC_ID, CMD, SSH_OPTS] do
|
1574
|
-
helper.
|
1575
|
-
rc = vm.info
|
1576
|
-
|
1577
|
-
if OpenNebula.is_error?(rc)
|
1578
|
-
STDERR.puts rc.message
|
1579
|
-
exit(-1)
|
1580
|
-
end
|
1581
|
-
|
1582
|
-
# Get user to login
|
1583
|
-
args[1].nil? ? login = 'root' : login = args[1]
|
1584
|
-
|
1585
|
-
# Get CMD to run
|
1586
|
-
options[:cmd].nil? ? cmd = '' : cmd = options[:cmd]
|
1587
|
-
|
1588
|
-
# Get NIC to connect
|
1589
|
-
if options[:nic_id]
|
1590
|
-
nic = vm.retrieve_xmlelements(
|
1591
|
-
"//TEMPLATE/NIC[NIC_ID=\"#{options[:nic_id]}\"]"
|
1592
|
-
)[0]
|
1593
|
-
else
|
1594
|
-
nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[SSH="YES"]')[0]
|
1595
|
-
end
|
1596
|
-
|
1597
|
-
nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[1]')[0] if nic.nil?
|
1598
|
-
|
1599
|
-
if nic.nil?
|
1600
|
-
STDERR.puts 'No NIC found'
|
1601
|
-
exit(-1)
|
1602
|
-
end
|
1603
|
-
|
1604
|
-
# If there is node port
|
1605
|
-
if nic['EXTERNAL_PORT_RANGE']
|
1606
|
-
ip = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
|
1607
|
-
ip = [ip].flatten[-1]['HOSTNAME']
|
1608
|
-
port = Integer(nic['EXTERNAL_PORT_RANGE'].split(':')[0]) + 21
|
1609
|
-
else
|
1610
|
-
ip = nic['IP']
|
1611
|
-
port = 22
|
1612
|
-
end
|
1613
|
-
|
1614
|
-
options[:ssh_opts].nil? ? opts = '' : opts = options[:ssh_opts]
|
1615
|
-
|
1616
|
-
system("ssh #{opts} #{login}@#{ip} -p #{port} #{cmd}")
|
1617
|
-
end
|
1618
|
-
|
1619
|
-
$?.exitstatus
|
1560
|
+
helper.ssh(args, options)
|
1620
1561
|
end
|
1621
1562
|
|
1622
1563
|
port_desc = <<-EOT.unindent
|
@@ -1670,14 +1611,16 @@ CommandParser::CmdParser.new(ARGV) do
|
|
1670
1611
|
i_end_p = Integer(i_range[1].split('/')[0])
|
1671
1612
|
|
1672
1613
|
if args[1].nil?
|
1673
|
-
|
1614
|
+
start_r = Array(e_start_p..e_end_p)
|
1615
|
+
end_r = Array(i_start_p..i_end_p)
|
1616
|
+
|
1617
|
+
start_r.zip(end_r) do |p1, p2|
|
1674
1618
|
puts "#{ip}@#{p1} -> #{p2}"
|
1675
1619
|
end
|
1676
1620
|
else
|
1677
1621
|
puts "#{ip}@#{e_start_p + Integer(args[1]) - 1} -> #{args[1]}"
|
1678
1622
|
end
|
1679
1623
|
end
|
1680
|
-
|
1681
1624
|
end
|
1682
1625
|
|
1683
1626
|
# Deprecated commands
|
data/bin/onezone
CHANGED
@@ -269,4 +269,24 @@ CommandParser::CmdParser.new(ARGV) do
|
|
269
269
|
|
270
270
|
0
|
271
271
|
end
|
272
|
+
|
273
|
+
enable_desc = <<-EOT.unindent
|
274
|
+
Enable zone
|
275
|
+
EOT
|
276
|
+
|
277
|
+
command :enable, enable_desc, [:range, :zoneid_list] do
|
278
|
+
helper.perform_actions(args[0], options, 'enable zone') do |o|
|
279
|
+
o.enable
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
disable_desc = <<-EOT.unindent
|
284
|
+
Disable zone, disabled zones can execute only readonly commands
|
285
|
+
EOT
|
286
|
+
|
287
|
+
command :disable, disable_desc, [:range, :zoneid_list] do
|
288
|
+
helper.perform_actions(args[0], options, 'disable zone') do |o|
|
289
|
+
o.disable
|
290
|
+
end
|
291
|
+
end
|
272
292
|
end
|
@@ -36,6 +36,12 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
|
36
36
|
"onemarket.yaml"
|
37
37
|
end
|
38
38
|
|
39
|
+
def self.state_to_str(id)
|
40
|
+
state_str = MarketPlace::MARKETPLACE_STATES[id.to_i]
|
41
|
+
|
42
|
+
MarketPlace::SHORT_MARKETPLACE_STATES[state_str]
|
43
|
+
end
|
44
|
+
|
39
45
|
def format_pool(options)
|
40
46
|
config_file = self.class.table_conf
|
41
47
|
|
@@ -86,7 +92,11 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
|
86
92
|
d["ZONE_ID"]
|
87
93
|
end
|
88
94
|
|
89
|
-
|
95
|
+
column :STAT, 'Markeplace status', :left, :size => 4 do |d|
|
96
|
+
OneMarketPlaceHelper.state_to_str(d['STATE'])
|
97
|
+
end
|
98
|
+
|
99
|
+
default :ID, :NAME, :SIZE, :AVAIL, :APPS, :MAD, :ZONE, :STAT
|
90
100
|
end
|
91
101
|
|
92
102
|
table
|
@@ -116,6 +126,7 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
|
116
126
|
puts str % ["NAME", market.name]
|
117
127
|
puts str % ["USER", market['UNAME']]
|
118
128
|
puts str % ["GROUP", market['GNAME']]
|
129
|
+
puts str % ["STATE", market.state_str]
|
119
130
|
|
120
131
|
puts str % ["MARKET_MAD", market['MARKET_MAD']]
|
121
132
|
puts
|
@@ -188,14 +188,14 @@ class OneVcenterHelper < OpenNebulaHelper::OneHelper
|
|
188
188
|
|
189
189
|
# This method will print a list for a vcenter_resource.
|
190
190
|
#
|
191
|
-
def list_object(
|
191
|
+
def list_object(options, list)
|
192
192
|
vcenter_host = list.keys[0]
|
193
193
|
list = cli_format(list.values.first)
|
194
194
|
table = format_list
|
195
195
|
|
196
196
|
show_header(vcenter_host)
|
197
197
|
|
198
|
-
table.show(list)
|
198
|
+
table.show(list, options)
|
199
199
|
end
|
200
200
|
|
201
201
|
# handles :cli section of TABLE
|
@@ -124,7 +124,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
124
124
|
:name => 'weekly',
|
125
125
|
:large => '--weekly days',
|
126
126
|
:description => 'Repeats the schedule action the days of the week ' \
|
127
|
-
'specified, it can be a number between 0
|
127
|
+
'specified, it can be a number between 0 (Sunday) to 6 (Saturday) ' \
|
128
|
+
'separated with commas. ' \
|
128
129
|
'For example: onevm resume 0 --schedule "09/23 14:15" --weekly 0,2,4',
|
129
130
|
:format => String
|
130
131
|
}
|
@@ -133,8 +134,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
133
134
|
:name => 'monthly',
|
134
135
|
:large => '--monthly days',
|
135
136
|
:description => 'Repeats the schedule action the days of the month ' \
|
136
|
-
'specified, it can be a number between
|
137
|
-
'For example: onevm resume 0 --schedule "09/23 14:15" --monthly
|
137
|
+
'specified, it can be a number between 1,31 separated with commas. ' \
|
138
|
+
'For example: onevm resume 0 --schedule "09/23 14:15" --monthly 1,14',
|
138
139
|
:format => String
|
139
140
|
}
|
140
141
|
|
@@ -142,7 +143,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
142
143
|
:name => 'yearly',
|
143
144
|
:large => '--yearly days',
|
144
145
|
:description => 'Repeats the schedule action the days of the year ' \
|
145
|
-
'specified, it can be a number between 0,365 separated with commas.' \
|
146
|
+
'specified, it can be a number between 0,365 separated with commas. ' \
|
146
147
|
'For example: onevm resume 0 --schedule "09/23 14:15" --yearly 30,60',
|
147
148
|
:format => String
|
148
149
|
}
|
@@ -151,7 +152,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
151
152
|
:name => 'hourly',
|
152
153
|
:large => '--hourly hour',
|
153
154
|
:description => 'Repeats the schedule action each hours specified,' \
|
154
|
-
'it can be a number between 0,168 separated with commas.' \
|
155
|
+
'it can be a number between 0,168 separated with commas. ' \
|
155
156
|
'For example: onevm resume 0 --schedule "09/23 14:15" --hourly 1,5',
|
156
157
|
:format => Numeric
|
157
158
|
}
|
@@ -439,21 +440,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
439
440
|
str_periodic << ', END_TYPE = 0'
|
440
441
|
end
|
441
442
|
|
442
|
-
rc = vm.info
|
443
|
-
|
444
|
-
if OpenNebula.is_error?(rc)
|
445
|
-
puts rc.message
|
446
|
-
exit(-1)
|
447
|
-
end
|
448
|
-
|
449
|
-
ids = vm.retrieve_elements('USER_TEMPLATE/SCHED_ACTION/ID')
|
450
|
-
|
451
|
-
id = 0
|
452
|
-
if !ids.nil? && !ids.empty?
|
453
|
-
ids.map! {|e| e.to_i }
|
454
|
-
id = ids.max + 1
|
455
|
-
end
|
456
|
-
|
457
443
|
sched = options[:schedule]
|
458
444
|
|
459
445
|
# If the action is set to be executed from VM start to an specific
|
@@ -463,16 +449,14 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
463
449
|
sched = sched.to_i
|
464
450
|
end
|
465
451
|
|
466
|
-
tmp_str =
|
467
|
-
|
468
|
-
tmp_str << "\nSCHED_ACTION = "
|
469
|
-
tmp_str << "[ID = #{id}, ACTION = #{action}, "
|
452
|
+
tmp_str = "SCHED_ACTION = ["
|
453
|
+
tmp_str << "ACTION = #{action}, "
|
470
454
|
tmp_str << "WARNING = #{warning}," if warning
|
471
455
|
tmp_str << "ARGS = \"#{options[:args]}\"," if options[:args]
|
472
456
|
tmp_str << "TIME = #{sched}"
|
473
457
|
tmp_str << str_periodic << ']'
|
474
458
|
|
475
|
-
vm.
|
459
|
+
vm.sched_action_add(tmp_str)
|
476
460
|
end
|
477
461
|
end
|
478
462
|
|
@@ -490,7 +474,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
490
474
|
exit(-1)
|
491
475
|
end
|
492
476
|
|
493
|
-
xpath = "
|
477
|
+
xpath = "TEMPLATE/SCHED_ACTION[ID=#{action_id}]"
|
494
478
|
|
495
479
|
unless vm.retrieve_elements(xpath)
|
496
480
|
STDERR.puts "Sched action #{action_id} not found"
|
@@ -508,12 +492,11 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
508
492
|
vm.delete_element(xpath)
|
509
493
|
|
510
494
|
# Add the modified sched action
|
511
|
-
tmp_str =
|
512
|
-
tmp_str << "\nSCHED_ACTION = ["
|
495
|
+
tmp_str = "\nSCHED_ACTION = ["
|
513
496
|
tmp_str << str.split("\n").join(',')
|
514
497
|
tmp_str << ']'
|
515
498
|
|
516
|
-
rc = vm.
|
499
|
+
rc = vm.sched_action_update(action_id, tmp_str)
|
517
500
|
|
518
501
|
if OpenNebula.is_error?(rc)
|
519
502
|
STDERR.puts "Error updating: #{rc.message}"
|
@@ -669,6 +652,78 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
669
652
|
YAML.load_file(self.class.table_conf)[:charters]
|
670
653
|
end
|
671
654
|
|
655
|
+
# SSH into a VM
|
656
|
+
#
|
657
|
+
# @param args [Array] CLI arguments
|
658
|
+
# @param options [Hash] CLI parameters
|
659
|
+
def ssh(args, options)
|
660
|
+
perform_action(args[0], options, 'SSH') do |vm|
|
661
|
+
rc = vm.info
|
662
|
+
|
663
|
+
if OpenNebula.is_error?(rc)
|
664
|
+
STDERR.puts rc.message
|
665
|
+
exit(-1)
|
666
|
+
end
|
667
|
+
|
668
|
+
if vm.lcm_state_str != 'RUNNING'
|
669
|
+
STDERR.puts 'VM is not RUNNING, cannot SSH to it'
|
670
|
+
exit(-1)
|
671
|
+
end
|
672
|
+
|
673
|
+
# Get user to login
|
674
|
+
username = vm.retrieve_xmlelements('//TEMPLATE/CONTEXT/USERNAME')[0]
|
675
|
+
|
676
|
+
if !username.nil?
|
677
|
+
login = username.text
|
678
|
+
elsif !args[1].nil?
|
679
|
+
login = args[1]
|
680
|
+
else
|
681
|
+
login = 'root'
|
682
|
+
end
|
683
|
+
|
684
|
+
# Get CMD to run
|
685
|
+
options[:cmd].nil? ? cmd = '' : cmd = options[:cmd]
|
686
|
+
|
687
|
+
# Get NIC to connect
|
688
|
+
if options[:nic_id]
|
689
|
+
nic = vm.retrieve_xmlelements(
|
690
|
+
"//TEMPLATE/NIC[NIC_ID=\"#{options[:nic_id]}\"]"
|
691
|
+
)[0]
|
692
|
+
else
|
693
|
+
nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[SSH="YES"]')[0]
|
694
|
+
end
|
695
|
+
|
696
|
+
nic = vm.retrieve_xmlelements('//TEMPLATE/NIC[1]')[0] if nic.nil?
|
697
|
+
|
698
|
+
if nic.nil?
|
699
|
+
STDERR.puts 'No NIC found'
|
700
|
+
exit(-1)
|
701
|
+
end
|
702
|
+
|
703
|
+
# If there is node port
|
704
|
+
if nic['EXTERNAL_PORT_RANGE']
|
705
|
+
ip = vm.to_hash['VM']['HISTORY_RECORDS']['HISTORY']
|
706
|
+
ip = [ip].flatten[-1]['HOSTNAME']
|
707
|
+
port = Integer(nic['EXTERNAL_PORT_RANGE'].split(':')[0]) + 21
|
708
|
+
else
|
709
|
+
ip = nic['IP']
|
710
|
+
port = 22
|
711
|
+
end
|
712
|
+
|
713
|
+
options[:ssh_opts].nil? ? opts = '' : opts = options[:ssh_opts]
|
714
|
+
|
715
|
+
if opts.empty?
|
716
|
+
exec(*%W[ssh #{login}@#{ip} -p #{port} #{cmd}])
|
717
|
+
else
|
718
|
+
exec('ssh', *opts.split, *%W[#{login}@#{ip} -p #{port} #{cmd}])
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
# rubocop:disable Style/SpecialGlobalVars
|
723
|
+
$?.exitstatus
|
724
|
+
# rubocop:enable Style/SpecialGlobalVars
|
725
|
+
end
|
726
|
+
|
672
727
|
private
|
673
728
|
|
674
729
|
def factory(id = nil)
|
@@ -1227,7 +1282,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
1227
1282
|
format_history(vm)
|
1228
1283
|
end
|
1229
1284
|
|
1230
|
-
if vm.has_elements?('/VM/
|
1285
|
+
if vm.has_elements?('/VM/TEMPLATE/SCHED_ACTION')
|
1231
1286
|
puts
|
1232
1287
|
CLIHelper.print_header(str_h1 % 'SCHEDULED ACTIONS', false)
|
1233
1288
|
|
@@ -1245,7 +1300,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
1245
1300
|
end
|
1246
1301
|
|
1247
1302
|
column :SCHEDULED, '', :adjust => true do |d|
|
1248
|
-
|
1303
|
+
t2 = d['TIME'].to_i
|
1304
|
+
t2 += vm['STIME'].to_i unless d['TIME'] =~ /^[0-9].*/
|
1305
|
+
|
1306
|
+
OpenNebulaHelper.time_to_str(t2, false) \
|
1249
1307
|
unless d.nil?
|
1250
1308
|
end
|
1251
1309
|
|
@@ -1296,7 +1354,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
1296
1354
|
|
1297
1355
|
column :CHARTER, '', :left, :adjust, :size => 15 do |d|
|
1298
1356
|
t1 = Time.now
|
1299
|
-
t2 =
|
1357
|
+
t2 = d['TIME'].to_i
|
1358
|
+
t2 += vm['STIME'].to_i unless d['TIME'] =~ /^[0-9].*/
|
1359
|
+
|
1360
|
+
t2 = Time.at(t2)
|
1300
1361
|
|
1301
1362
|
days = ((t2 - t1) / (24 * 3600)).round(2)
|
1302
1363
|
hours = ((t2 - t1) / 3600).round(2)
|
@@ -1304,7 +1365,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
1304
1365
|
|
1305
1366
|
if days > 1
|
1306
1367
|
show = "In #{days} days"
|
1307
|
-
elsif days
|
1368
|
+
elsif days <= 1 && hours > 1
|
1308
1369
|
show = "In #{hours} hours"
|
1309
1370
|
elsif minutes > 0
|
1310
1371
|
show = "In #{minutes} minutes"
|
@@ -1312,18 +1373,19 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
|
1312
1373
|
show = 'Already done'
|
1313
1374
|
end
|
1314
1375
|
|
1315
|
-
|
1376
|
+
wrn = d['WARNING']
|
1377
|
+
if !wrn.nil? && (t1 - vm['STIME'].to_i).to_i > wrn.to_i
|
1316
1378
|
"#{show} *"
|
1317
1379
|
else
|
1318
1380
|
show
|
1319
1381
|
end
|
1320
1382
|
end
|
1321
|
-
end.show([vm_hash['VM']['
|
1383
|
+
end.show([vm_hash['VM']['TEMPLATE']['SCHED_ACTION']].flatten,
|
1322
1384
|
{})
|
1323
1385
|
end
|
1324
1386
|
|
1325
1387
|
if !options[:all]
|
1326
|
-
vm.delete_element('/VM/
|
1388
|
+
vm.delete_element('/VM/TEMPLATE/SCHED_ACTION')
|
1327
1389
|
end
|
1328
1390
|
|
1329
1391
|
if vm.has_elements?('/VM/USER_TEMPLATE')
|