opennebula-cli 6.0.2 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38415d05a5a46b897679a59f395d635b33093e59
4
- data.tar.gz: 84e514c15e324cab67b86348274251d747eec436
3
+ metadata.gz: b9047abc8d9178fcb286d57d5b78011953ac28b9
4
+ data.tar.gz: ed6331618ee88c1858ca45686a3e618347177301
5
5
  SHA512:
6
- metadata.gz: 2923363afe9835b9297e69b77dbd8fc58887ad438f62733f8fb60195e12cc06524d7c324a97688e8666be4eaa5ae1cd23b9e8fd523dded84bc301daaa47b7a63
7
- data.tar.gz: 5f278b45143d8e0c8f80538a034ad2af4741c25245d44a292cdd99cc45b73535d66e997e840e5199b0f488d901bcbd5c8ece5eece79227b6019d77166c27d668
6
+ metadata.gz: cc9036cd78ef6b9f679d3b572b84e953687f4c1e67efa7c3b82da2010536d84274a309318edc576abc81e58c9662a87c23605d719d9dd059bc13a7c0cc2896cf
7
+ data.tar.gz: b74774142ddff00b508f990c63c575743493a7e8d7728d117dd46f27705e22143ff9f5180a8cbcd13b3127cfec6ba409a824857e7cdfc4206faae98654d21b03
data/bin/oneflow CHANGED
@@ -82,6 +82,14 @@ CommandParser::CmdParser.new(ARGV) do
82
82
  :description => 'Force flow necover delete'
83
83
  }
84
84
 
85
+ APPEND = {
86
+ :name => 'append',
87
+ :large => '--append',
88
+ :description => 'Append template to the current one'
89
+ }
90
+
91
+ FORMAT = [OpenNebulaHelper::JSON, OpenNebulaHelper::YAML]
92
+
85
93
  # create helper object
86
94
  helper = OneFlowHelper.new
87
95
 
@@ -122,7 +130,7 @@ CommandParser::CmdParser.new(ARGV) do
122
130
  List the available services
123
131
  EOT
124
132
 
125
- command :list, list_desc, :options => OpenNebulaHelper::FORMAT do
133
+ command :list, list_desc, :options => FORMAT do
126
134
  helper.list_service_pool(helper.client(options), options)
127
135
  end
128
136
 
@@ -146,10 +154,7 @@ CommandParser::CmdParser.new(ARGV) do
146
154
  Show detailed information of a given service
147
155
  EOT
148
156
 
149
- command :show,
150
- show_desc,
151
- :service_id,
152
- :options => OpenNebulaHelper::FORMAT do
157
+ command :show, show_desc, :service_id, :options => FORMAT do
153
158
  helper.format_resource(helper.client(options), args[0], options)
154
159
  end
155
160
 
@@ -365,7 +370,11 @@ CommandParser::CmdParser.new(ARGV) do
365
370
  be launched to modify the current content.
366
371
  EOT
367
372
 
368
- command :update, update_desc, :service_id, [:file, nil] do
373
+ command :update,
374
+ update_desc,
375
+ :service_id,
376
+ [:file, nil],
377
+ :options => APPEND do
369
378
  service_id = args[0]
370
379
  client = helper.client(options)
371
380
 
@@ -383,8 +392,10 @@ CommandParser::CmdParser.new(ARGV) do
383
392
  tmp = Tempfile.new(service_id.to_s)
384
393
  path = tmp.path
385
394
 
386
- tmp.write(JSON.pretty_generate(template))
387
- tmp.flush
395
+ unless options[:append]
396
+ tmp.write(JSON.pretty_generate(template))
397
+ tmp.flush
398
+ end
388
399
 
389
400
  if ENV['EDITOR']
390
401
  editor_path = ENV['EDITOR']
@@ -403,7 +414,17 @@ CommandParser::CmdParser.new(ARGV) do
403
414
  end
404
415
  end
405
416
 
406
- response = client.put("#{RESOURCE_PATH}/#{service_id}", File.read(path))
417
+ if options[:append]
418
+ req = {}
419
+ req['append'] = true
420
+ req['template'] = File.read(path)
421
+
422
+ response = client.put("#{RESOURCE_PATH}/#{service_id}",
423
+ req.to_json)
424
+ else
425
+ response = client.put("#{RESOURCE_PATH}/#{service_id}",
426
+ File.read(path))
427
+ end
407
428
 
408
429
  if CloudClient.is_error?(response)
409
430
  [response.code.to_i, response.to_s]
@@ -428,4 +449,76 @@ CommandParser::CmdParser.new(ARGV) do
428
449
  0
429
450
  end
430
451
  end
452
+
453
+ ###
454
+
455
+ add_role_desc = <<-EOT.unindent
456
+ Add new role to running service
457
+ EOT
458
+
459
+ command :'add-role', add_role_desc, :service_id, [:file, nil] do
460
+ service_id = args[0]
461
+ client = helper.client(options)
462
+
463
+ if args[1]
464
+ path = args[1]
465
+ else
466
+ tmp = Tempfile.new(service_id.to_s)
467
+ path = tmp.path
468
+
469
+ if ENV['EDITOR']
470
+ editor_path = ENV['EDITOR']
471
+ else
472
+ editor_path = OpenNebulaHelper::EDITOR_PATH
473
+ end
474
+
475
+ system("#{editor_path} #{path}")
476
+
477
+ unless $CHILD_STATUS.exitstatus.zero?
478
+ STDERR.puts 'Editor not defined'
479
+ exit(-1)
480
+ end
481
+
482
+ tmp.close
483
+ end
484
+
485
+ params = {}
486
+ params[:role] = File.read(path)
487
+ params[:add] = true
488
+ json = Service.build_json_action('add_role', params)
489
+
490
+ response = client.post("#{RESOURCE_PATH}/#{service_id}/role_action",
491
+ json)
492
+
493
+ if CloudClient.is_error?(response)
494
+ [response.code.to_i, response.to_s]
495
+ else
496
+ 0
497
+ end
498
+ end
499
+
500
+ ###
501
+
502
+ remove_role_desc = <<-EOT.unindent
503
+ Remove role from running service
504
+ EOT
505
+
506
+ command :'remove-role', remove_role_desc, :service_id, :role_name do
507
+ service_id = args[0]
508
+ client = helper.client(options)
509
+
510
+ params = {}
511
+ params[:role] = args[1]
512
+ params[:add] = false
513
+ json = Service.build_json_action('remove_role', params)
514
+
515
+ response = client.post("#{RESOURCE_PATH}/#{service_id}/role_action",
516
+ json)
517
+
518
+ if CloudClient.is_error?(response)
519
+ [response.code.to_i, response.to_s]
520
+ else
521
+ 0
522
+ end
523
+ end
431
524
  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 => OpenNebulaHelper::FORMAT do
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] do
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
- VCenterDriver::VcImporter.import_clusters(con_ops, options)
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] do
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.info
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.perform_action(args[0], options, 'SSH') do |vm|
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
- [*e_start_p..e_end_p].zip([*i_start_p..i_end_p]) do |p1, p2|
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
@@ -216,11 +216,15 @@ class AcctHelper < OpenNebulaHelper::OneHelper
216
216
  d["HOURS"]
217
217
  end
218
218
 
219
+ column :RUNNING_HOURS, "Running hours", :size=>7 do |d|
220
+ d["RHOURS"] || '-'
221
+ end
222
+
219
223
  column :COST, "Cost", :size=>15 do |d|
220
224
  d["TOTAL_COST"]
221
225
  end
222
226
 
223
- default :USER_NAME, :GROUP_NAME, :VM_ID, :VM_NAME, :MONTH, :YEAR, :HOURS, :COST
227
+ default :USER_NAME, :GROUP_NAME, :VM_ID, :VM_NAME, :MONTH, :YEAR, :HOURS, :RUNNING_HOURS, :COST
224
228
  end
225
229
 
226
230
  def self.print_start_end_time_header(start_time, end_time)
@@ -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
- default :ID, :NAME, :SIZE, :AVAIL, :APPS, :MAD, :ZONE
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(_options, list)
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