opennebula-cli 5.12.13 → 5.13.80.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.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/bin/oneacct +5 -14
  3. data/bin/oneacl +4 -15
  4. data/bin/onecluster +6 -17
  5. data/bin/onedatastore +6 -17
  6. data/bin/oneflow +81 -23
  7. data/bin/oneflow-template +51 -27
  8. data/bin/onegroup +6 -17
  9. data/bin/onehook +6 -17
  10. data/bin/onehost +4 -15
  11. data/bin/oneimage +95 -18
  12. data/bin/onemarket +6 -17
  13. data/bin/onemarketapp +113 -20
  14. data/bin/onesecgroup +9 -17
  15. data/bin/oneshowback +14 -20
  16. data/bin/onetemplate +8 -18
  17. data/bin/oneuser +26 -17
  18. data/bin/onevcenter +6 -28
  19. data/bin/onevdc +6 -17
  20. data/bin/onevm +142 -21
  21. data/bin/onevmgroup +9 -17
  22. data/bin/onevnet +4 -15
  23. data/bin/onevntemplate +7 -17
  24. data/bin/onevrouter +6 -17
  25. data/bin/onezone +6 -17
  26. data/lib/cli_helper.rb +7 -10
  27. data/lib/command_parser.rb +1 -1
  28. data/lib/one_helper/oneacct_helper.rb +9 -22
  29. data/lib/one_helper/oneacl_helper.rb +1 -1
  30. data/lib/one_helper/onecluster_helper.rb +1 -1
  31. data/lib/one_helper/onedatastore_helper.rb +11 -1
  32. data/lib/one_helper/oneflow_helper.rb +20 -5
  33. data/lib/one_helper/oneflowtemplate_helper.rb +28 -2
  34. data/lib/one_helper/onegroup_helper.rb +1 -1
  35. data/lib/one_helper/onehook_helper.rb +1 -1
  36. data/lib/one_helper/onehost_helper.rb +1 -5
  37. data/lib/one_helper/oneimage_helper.rb +7 -7
  38. data/lib/one_helper/onemarket_helper.rb +1 -1
  39. data/lib/one_helper/onemarketapp_helper.rb +494 -96
  40. data/lib/one_helper/onequota_helper.rb +1 -1
  41. data/lib/one_helper/onesecgroup_helper.rb +1 -1
  42. data/lib/one_helper/onetemplate_helper.rb +12 -1
  43. data/lib/one_helper/oneuser_helper.rb +11 -3
  44. data/lib/one_helper/onevcenter_helper.rb +176 -146
  45. data/lib/one_helper/onevdc_helper.rb +1 -1
  46. data/lib/one_helper/onevm_helper.rb +9 -9
  47. data/lib/one_helper/onevmgroup_helper.rb +1 -1
  48. data/lib/one_helper/onevnet_helper.rb +1 -1
  49. data/lib/one_helper/onevntemplate_helper.rb +1 -1
  50. data/lib/one_helper/onevrouter_helper.rb +1 -20
  51. data/lib/one_helper/onezone_helper.rb +12 -1
  52. data/lib/one_helper.rb +398 -37
  53. data/share/schemas/xsd/acct.xsd +179 -0
  54. data/share/schemas/xsd/acl_pool.xsd +22 -0
  55. data/share/schemas/xsd/api_info.xsd +43 -0
  56. data/share/schemas/xsd/cluster.xsd +34 -0
  57. data/share/schemas/xsd/cluster_pool.xsd +12 -0
  58. data/share/schemas/xsd/datastore.xsd +67 -0
  59. data/share/schemas/xsd/datastore_pool.xsd +12 -0
  60. data/share/schemas/xsd/document.xsd +42 -0
  61. data/share/schemas/xsd/document_pool.xsd +12 -0
  62. data/share/schemas/xsd/group.xsd +179 -0
  63. data/share/schemas/xsd/group_pool.xsd +194 -0
  64. data/share/schemas/xsd/hook.xsd +59 -0
  65. data/share/schemas/xsd/hook_message_api.xsd +14 -0
  66. data/share/schemas/xsd/hook_message_retry.xsd +12 -0
  67. data/share/schemas/xsd/hook_message_state.xsd +25 -0
  68. data/share/schemas/xsd/hook_pool.xsd +12 -0
  69. data/share/schemas/xsd/host.xsd +164 -0
  70. data/share/schemas/xsd/host_pool.xsd +12 -0
  71. data/share/schemas/xsd/image.xsd +123 -0
  72. data/share/schemas/xsd/image_pool.xsd +12 -0
  73. data/share/schemas/xsd/index.xsd +49 -0
  74. data/share/schemas/xsd/marketplace.xsd +44 -0
  75. data/share/schemas/xsd/marketplace_pool.xsd +12 -0
  76. data/share/schemas/xsd/marketplaceapp.xsd +56 -0
  77. data/share/schemas/xsd/marketplaceapp_pool.xsd +12 -0
  78. data/share/schemas/xsd/opennebula_configuration.xsd +412 -0
  79. data/share/schemas/xsd/raftstatus.xsd +18 -0
  80. data/share/schemas/xsd/security_group.xsd +74 -0
  81. data/share/schemas/xsd/security_group_pool.xsd +12 -0
  82. data/share/schemas/xsd/showback.xsd +29 -0
  83. data/share/schemas/xsd/user.xsd +186 -0
  84. data/share/schemas/xsd/user_pool.xsd +201 -0
  85. data/share/schemas/xsd/vdc.xsd +76 -0
  86. data/share/schemas/xsd/vdc_pool.xsd +12 -0
  87. data/share/schemas/xsd/vm.xsd +251 -0
  88. data/share/schemas/xsd/vm_group.xsd +59 -0
  89. data/share/schemas/xsd/vm_group_pool.xsd +12 -0
  90. data/share/schemas/xsd/vm_pool.xsd +114 -0
  91. data/share/schemas/xsd/vmtemplate.xsd +52 -0
  92. data/share/schemas/xsd/vmtemplate_pool.xsd +12 -0
  93. data/share/schemas/xsd/vnet.xsd +137 -0
  94. data/share/schemas/xsd/vnet_pool.xsd +85 -0
  95. data/share/schemas/xsd/vntemplate.xsd +50 -0
  96. data/share/schemas/xsd/vntemplate_pool.xsd +12 -0
  97. data/share/schemas/xsd/vrouter.xsd +49 -0
  98. data/share/schemas/xsd/vrouter_pool.xsd +12 -0
  99. data/share/schemas/xsd/zone.xsd +40 -0
  100. data/share/schemas/xsd/zone_pool.xsd +36 -0
  101. metadata +92 -30
  102. data/lib/one_helper/oneprovision_helper.rb +0 -362
data/lib/one_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2021, 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 #
@@ -30,17 +30,19 @@ include OpenNebula
30
30
  module OpenNebulaHelper
31
31
  ONE_VERSION=<<-EOT
32
32
  OpenNebula #{OpenNebula::VERSION}
33
- Copyright 2002-2023, OpenNebula Project, OpenNebula Systems
33
+ Copyright 2002-2021, OpenNebula Project, OpenNebula Systems
34
34
  EOT
35
35
 
36
36
  if ONE_LOCATION
37
- TABLE_CONF_PATH=ONE_LOCATION+"/etc/cli"
38
- VAR_LOCATION=ONE_LOCATION+"/var" if !defined?(VAR_LOCATION)
39
- CLI_ADDONS_LOCATION=ONE_LOCATION+"/lib/ruby/cli/addons"
37
+ TABLE_CONF_PATH = ONE_LOCATION + "/etc/cli"
38
+ VAR_LOCATION = ONE_LOCATION + "/var" if !defined?(VAR_LOCATION)
39
+ CLI_ADDONS_LOCATION = ONE_LOCATION + "/lib/ruby/cli/addons"
40
+ XSD_PATH = ONE_LOCATION + '/share/schemas/xsd'
40
41
  else
41
- TABLE_CONF_PATH="/etc/one/cli"
42
- VAR_LOCATION="/var/lib/one" if !defined?(VAR_LOCATION)
43
- CLI_ADDONS_LOCATION="/usr/lib/one/ruby/cli/addons"
42
+ TABLE_CONF_PATH = "/etc/one/cli"
43
+ VAR_LOCATION = "/var/lib/one" if !defined?(VAR_LOCATION)
44
+ CLI_ADDONS_LOCATION = "/usr/lib/one/ruby/cli/addons"
45
+ XSD_PATH = '/usr/share/one/schemas/xsd'
44
46
  end
45
47
 
46
48
  EDITOR_PATH='/usr/bin/vi'
@@ -55,6 +57,23 @@ EOT
55
57
  :description => "Show the resource in xml format"
56
58
  }
57
59
 
60
+ JSON = {
61
+ :name => 'json',
62
+ :short => '-j',
63
+ :large => '--json',
64
+ :description => 'Show the resource in JSON format',
65
+ :proc => lambda do |_, _|
66
+ require 'json'
67
+ end
68
+ }
69
+
70
+ YAML = {
71
+ :name => 'yaml',
72
+ :short => '-y',
73
+ :large => '--yaml',
74
+ :description => 'Show the resource in YAML format'
75
+ }
76
+
58
77
  NUMERIC={
59
78
  :name => "numeric",
60
79
  :short => "-n",
@@ -428,7 +447,9 @@ EOT
428
447
  UPDATECONF_OPTIONS_VM = TEMPLATE_OPTIONS[6..15] + [TEMPLATE_OPTIONS[2],
429
448
  TEMPLATE_OPTIONS[17], TEMPLATE_OPTIONS[18]]
430
449
 
431
- OPTIONS = XML, EXTENDED, NUMERIC, KILOBYTES
450
+ FORMAT = [XML, JSON, YAML]
451
+
452
+ OPTIONS = FORMAT, EXTENDED, NUMERIC, KILOBYTES
432
453
 
433
454
  class OneHelper
434
455
  attr_accessor :client
@@ -590,12 +611,10 @@ EOT
590
611
  end
591
612
 
592
613
  def print_page(pool, options)
593
- page = nil
614
+ elements = 0
615
+ page = ""
594
616
 
595
617
  if options[:xml]
596
- elements = 0
597
- page = ""
598
-
599
618
  pool.each {|e|
600
619
  elements += 1
601
620
  page << e.to_xml(true) << "\n"
@@ -604,8 +623,15 @@ EOT
604
623
  pname = pool.pool_name
605
624
  ename = pool.element_name
606
625
 
607
- page = pool.to_hash
608
- elems = page["#{pname}"]["#{ename}"]
626
+ if options[:decrypt]
627
+ page = pool.map do |element|
628
+ element.info(true)
629
+ element.to_hash[ename]
630
+ end
631
+ else
632
+ page = pool.to_hash
633
+ elems = page[pname][ename]
634
+ end
609
635
 
610
636
  if elems.class == Array
611
637
  elements = elems.length
@@ -626,7 +652,7 @@ EOT
626
652
  size = $stdout.winsize[0] - 1
627
653
 
628
654
  # ----------- First page, check if pager is needed -------------
629
- rc = pool.get_page(size, 0, false)
655
+ rc = pool.get_page(size, 0, false, options[:state])
630
656
  ps = ""
631
657
 
632
658
  return -1, rc.message if OpenNebula.is_error?(rc)
@@ -654,7 +680,7 @@ EOT
654
680
  options[:no_header] = true
655
681
 
656
682
  loop do
657
- rc = pool.get_page(size, current, false)
683
+ rc = pool.get_page(size, current, false, options[:state])
658
684
 
659
685
  return -1, rc.message if OpenNebula.is_error?(rc)
660
686
 
@@ -677,19 +703,19 @@ EOT
677
703
 
678
704
  stop_pager(ppid)
679
705
  else
680
- array = pool.get_hash
681
- return -1, array.message if OpenNebula.is_error?(array)
706
+ rc = pool.info
682
707
 
683
- rname = self.class.rname
684
- elements = array["#{rname}_POOL"][rname]
708
+ return -1, rc.message if OpenNebula.is_error?(rc)
709
+
710
+ _, hash = print_page(pool, options)
685
711
 
686
712
  if options[:ids] && elements
687
- elements.reject! do |element|
713
+ hash.reject! do |element|
688
714
  !options[:ids].include?(element['ID'].to_i)
689
715
  end
690
716
  end
691
717
 
692
- table.show(array, options)
718
+ table.show(hash, options)
693
719
  end
694
720
 
695
721
  return 0
@@ -705,7 +731,7 @@ EOT
705
731
  size = $stdout.winsize[0] - 1
706
732
 
707
733
  # ----------- First page, check if pager is needed -------------
708
- rc = pool.get_page(size, 0, extended)
734
+ rc = pool.get_page(size, 0, extended, options[:state])
709
735
  ps = ""
710
736
 
711
737
  return -1, rc.message if OpenNebula.is_error?(rc)
@@ -740,7 +766,7 @@ EOT
740
766
  current = size
741
767
 
742
768
  loop do
743
- rc = pool.get_page(size, current, extended)
769
+ rc = pool.get_page(size, current, extended, options[:state])
744
770
 
745
771
  return -1, rc.message if OpenNebula.is_error?(rc)
746
772
 
@@ -779,6 +805,82 @@ EOT
779
805
  return 0
780
806
  end
781
807
 
808
+ #-----------------------------------------------------------------------
809
+ # List pool in JSON format, pagination is used in interactive output
810
+ #-----------------------------------------------------------------------
811
+ def list_pool_format(pool, options, filter_flag)
812
+ extended = options.include?(:extended) && options[:extended]
813
+
814
+ if $stdout.isatty and (!options.key?:no_pager)
815
+ size = $stdout.winsize[0] - 1
816
+
817
+ # ----------- First page, check if pager is needed -------------
818
+ rc = pool.get_page(size, 0, extended, options[:state])
819
+ ps = ""
820
+
821
+ return -1, rc.message if OpenNebula.is_error?(rc)
822
+
823
+ elements = get_format_size(pool, options)
824
+ ppid = -1
825
+
826
+ if elements >= size
827
+ ppid = start_pager
828
+ end
829
+
830
+ yield(pool) if block_given?
831
+
832
+ if elements < size
833
+ return 0
834
+ end
835
+
836
+ if elements < size
837
+ return 0
838
+ elsif !pool.is_paginated?
839
+ stop_pager(ppid)
840
+ return 0
841
+ end
842
+
843
+ # ------- Rest of the pages in the pool, piped to pager --------
844
+ current = size
845
+
846
+ loop do
847
+ rc = pool.get_page(size, current, extended, options[:state])
848
+
849
+ return -1, rc.message if OpenNebula.is_error?(rc)
850
+
851
+ current += size
852
+
853
+ begin
854
+ Process.waitpid(ppid, Process::WNOHANG)
855
+ rescue Errno::ECHILD
856
+ break
857
+ end
858
+
859
+ elements = get_format_size(pool, options)
860
+
861
+ break if elements < size
862
+
863
+ yield(pool) if block_given?
864
+
865
+ $stdout.flush
866
+ end
867
+
868
+ stop_pager(ppid)
869
+ else
870
+ if pool.pool_name == "VM_POOL" && extended
871
+ rc = pool.info_all_extended
872
+ else
873
+ rc = pool.info
874
+ end
875
+
876
+ return -1, rc.message if OpenNebula.is_error?(rc)
877
+
878
+ yield(pool) if block_given?
879
+ end
880
+
881
+ return 0
882
+ end
883
+
782
884
  #-----------------------------------------------------------------------
783
885
  # List pool table in top-like form
784
886
  #-----------------------------------------------------------------------
@@ -807,11 +909,27 @@ EOT
807
909
  filter_flag ||= OpenNebula::Pool::INFO_ALL
808
910
 
809
911
  pool = factory_pool(filter_flag)
912
+ pname = pool.pool_name
913
+ ename = pool.element_name
810
914
 
811
915
  if top
812
916
  return list_pool_top(table, pool, options)
813
917
  elsif options[:xml]
814
918
  return list_pool_xml(pool, options, filter_flag)
919
+ elsif options[:json]
920
+ list_pool_format(pool, options, filter_flag) do |pool|
921
+ hash = check_resource_xsd(pool, pname)
922
+ hash[pname] = check_resource_xsd(hash[pname], ename)
923
+
924
+ puts ::JSON.pretty_generate(hash)
925
+ end
926
+ elsif options[:yaml]
927
+ list_pool_format(pool, options, filter_flag) do |pool|
928
+ hash = check_resource_xsd(pool, pname)
929
+ hash[pname] = check_resource_xsd(hash[pname], ename)
930
+
931
+ puts hash.to_yaml(:indent => 4)
932
+ end
815
933
  else
816
934
  return list_pool_table(table, pool, options, filter_flag)
817
935
  end
@@ -855,6 +973,17 @@ EOT
855
973
 
856
974
  if options[:xml]
857
975
  return 0, resource.to_xml(true)
976
+ elsif options[:json]
977
+ # If body is set, the resource contains a JSON inside
978
+ if options[:body]
979
+ return 0, check_resource_xsd(resource)
980
+ else
981
+ return 0, ::JSON.pretty_generate(
982
+ check_resource_xsd(resource)
983
+ )
984
+ end
985
+ elsif options[:yaml]
986
+ return 0, check_resource_xsd(resource).to_yaml(:indent => 4)
858
987
  else
859
988
  format_resource(resource, options)
860
989
  return 0
@@ -1064,6 +1193,199 @@ EOT
1064
1193
 
1065
1194
  return 0, pool
1066
1195
  end
1196
+
1197
+ def get_format_size(pool, options)
1198
+ if options[:json]
1199
+ ::JSON.pretty_generate(pool.to_hash).split("\n").size
1200
+ elsif options[:yaml]
1201
+ pool.to_hash.to_yaml.split("\n").size
1202
+ else
1203
+ STDERR.puts 'ERROR: Format not found'
1204
+ exit(-1)
1205
+ end
1206
+ end
1207
+
1208
+ ########################################################################
1209
+ # XSD check and fix
1210
+ ########################################################################
1211
+
1212
+ # Check XSD values for a single resource
1213
+ #
1214
+ # @param resource [OpenNebula::Object] Resource to check
1215
+ # @param ename [String] Resource name
1216
+ #
1217
+ # @return [Object] Hash with correct values
1218
+ def check_resource_xsd(resource, ename = nil)
1219
+ hash = resource.to_hash
1220
+ ename = hash.keys.first unless ename
1221
+ xsd = read_xsd(ename)
1222
+
1223
+ return hash unless xsd
1224
+
1225
+ hash[ename] = check_xsd(hash[ename], nil, ename, xsd)
1226
+
1227
+ hash
1228
+ end
1229
+
1230
+ # Read XSD file and parse to XML
1231
+ #
1232
+ # @param ename [String] Element name to read XSD
1233
+ #
1234
+ # @return [Hash] XSD in hash format, nil if not found
1235
+ def read_xsd(ename)
1236
+ require 'active_support/core_ext/hash/conversions'
1237
+
1238
+ # Try GEM directory
1239
+ file = File.expand_path(
1240
+ "../share/schemas/xsd/#{ename.downcase}.xsd",
1241
+ File.dirname(__FILE__)
1242
+ )
1243
+
1244
+ file = "#{XSD_PATH}/#{ename.downcase}.xsd" unless File.exist?(file)
1245
+
1246
+ unless File.exist?(file)
1247
+ STDERR.puts "WARNING: XSD for #{ename} not found, skipping check"
1248
+ return nil
1249
+ end
1250
+
1251
+ hash = Hash.from_xml(Nokogiri::XML(File.read(file)).to_s)
1252
+ hash = hash['schema']['element']
1253
+
1254
+ if hash.keys.include?('complexType')
1255
+ hash['complexType']['sequence']['element']
1256
+ else
1257
+ hash['element']
1258
+ end
1259
+ end
1260
+
1261
+ # Check values XSD
1262
+ #
1263
+ # @param hash [Object] Resource information in hash format
1264
+ # @param elements [Array] Keys to check
1265
+ # @param ename [String] Element name to take XSD
1266
+ # @param xsd [Hash] XSD file content
1267
+ # @param parents [Array] Parent keys of current hash
1268
+ def check_xsd(hash, elements, ename, xsd, parents = [])
1269
+ return unless hash
1270
+
1271
+ if (hash.is_a? Hash) && !hash.empty?
1272
+ hash.map do |ki, vi|
1273
+ vi = [vi].flatten if is_array?(xsd, [ki])
1274
+
1275
+ if (vi.is_a? Hash) && !vi.empty?
1276
+ parents << ki
1277
+
1278
+ vi.map do |kj, vj|
1279
+ parents << kj
1280
+
1281
+ path = (parents + [ki, kj]).uniq
1282
+ vj = [vj].flatten if is_array?(xsd, path)
1283
+
1284
+ hash[ki][kj] = check_xsd(vj,
1285
+ [ki, kj],
1286
+ ename,
1287
+ xsd,
1288
+ parents)
1289
+ end
1290
+
1291
+ parents.clear
1292
+ elsif vi.is_a? Array
1293
+ hash[ki] = check_xsd(vi, [ki], ename, xsd, parents)
1294
+ else
1295
+ hash[ki] = check_xsd(vi, [ki], ename, xsd, parents)
1296
+ end
1297
+ end
1298
+
1299
+ hash
1300
+ elsif hash.is_a? Array
1301
+ ret = []
1302
+
1303
+ hash.each do |v|
1304
+ ret << check_xsd(v, elements, ename, xsd, parents)
1305
+ end
1306
+
1307
+ ret
1308
+ else
1309
+ check_type(hash) do
1310
+ type = get_xsd_path(xsd, elements)
1311
+ type['type'] unless type.nil?
1312
+ end
1313
+ end
1314
+ end
1315
+
1316
+ # Get xsd path value
1317
+ #
1318
+ # @param xsd [Hash] XSD information
1319
+ # @param elements [Array] Path to get
1320
+ #
1321
+ # @return [Hash] Path information
1322
+ def get_xsd_path(xsd, elements)
1323
+ return unless elements
1324
+
1325
+ element = elements.shift
1326
+
1327
+ # Return nil, because is an empty complexType
1328
+ return unless element
1329
+
1330
+ element = [xsd].flatten.find do |v|
1331
+ v['name'] == element || v['ref'] == element
1332
+ end
1333
+
1334
+ # Return nil, because element was not find in XSD
1335
+ return unless element
1336
+
1337
+ if element.keys.include?('complexType') && !elements.empty?
1338
+ if element['complexType']['all']
1339
+ element = element['complexType']['all']['element']
1340
+ else
1341
+ element = element['complexType']['sequence']['element']
1342
+ end
1343
+
1344
+ get_xsd_path(element, elements)
1345
+ else
1346
+ element
1347
+ end
1348
+ end
1349
+
1350
+ # CHeck if current element is an array
1351
+ #
1352
+ # @param xsd [Hash] XSD information
1353
+ # @param elements [Array] Path to check
1354
+ #
1355
+ # @return [Boolean] True if it's an array, false otherwise
1356
+ def is_array?(xsd, elements)
1357
+ max = get_xsd_path(xsd, elements)
1358
+ max = max['maxOccurs'] if max
1359
+
1360
+ max == 'unbounded' || max.to_i > 1
1361
+ end
1362
+
1363
+ # Check XSD type for especific value
1364
+ #
1365
+ # @param value [Object] Value to check
1366
+ #
1367
+ # @return [Object] nil if the type is not correct, value otherwise
1368
+ def check_type(value)
1369
+ type = yield if block_given?
1370
+
1371
+ # If there is no type, return current value
1372
+ return value unless type
1373
+
1374
+ types = %w[string decimal integer boolean date time]
1375
+ type = type.split(':')[1]
1376
+
1377
+ if types.include?(type)
1378
+ # If the current type is different, return string
1379
+ # because this value doesn't respect the type
1380
+ if (value.is_a? Hash) || (value.is_a? Array)
1381
+ ''
1382
+ else
1383
+ value
1384
+ end
1385
+ else
1386
+ value
1387
+ end
1388
+ end
1067
1389
  end
1068
1390
 
1069
1391
  def OpenNebulaHelper.rname_to_id(name, poolname)
@@ -1072,18 +1394,20 @@ EOT
1072
1394
  client=OneHelper.client
1073
1395
 
1074
1396
  pool = case poolname
1075
- when "HOST" then OpenNebula::HostPool.new(client)
1076
- when "HOOK" then OpenNebula::HookPool.new(client)
1077
- when "GROUP" then OpenNebula::GroupPool.new(client)
1078
- when "USER" then OpenNebula::UserPool.new(client)
1079
- when "DATASTORE" then OpenNebula::DatastorePool.new(client)
1080
- when "CLUSTER" then OpenNebula::ClusterPool.new(client)
1081
- when "VNET" then OpenNebula::VirtualNetworkPool.new(client)
1082
- when "IMAGE" then OpenNebula::ImagePool.new(client)
1083
- when "VMTEMPLATE" then OpenNebula::TemplatePool.new(client)
1084
- when "VM" then OpenNebula::VirtualMachinePool.new(client)
1085
- when "ZONE" then OpenNebula::ZonePool.new(client)
1086
- when "MARKETPLACE" then OpenNebula::MarketPlacePool.new(client)
1397
+ when "HOST" then OpenNebula::HostPool.new(client)
1398
+ when "HOOK" then OpenNebula::HookPool.new(client)
1399
+ when "GROUP" then OpenNebula::GroupPool.new(client)
1400
+ when "USER" then OpenNebula::UserPool.new(client)
1401
+ when "DATASTORE" then OpenNebula::DatastorePool.new(client)
1402
+ when "CLUSTER" then OpenNebula::ClusterPool.new(client)
1403
+ when "VNET" then OpenNebula::VirtualNetworkPool.new(client)
1404
+ when "IMAGE" then OpenNebula::ImagePool.new(client)
1405
+ when "VMTEMPLATE" then OpenNebula::TemplatePool.new(client)
1406
+ when "VNTEMPLATES" then OpenNebula::VNTemplatePool.new(client)
1407
+ when "VM" then OpenNebula::VirtualMachinePool.new(client)
1408
+ when "ZONE" then OpenNebula::ZonePool.new(client)
1409
+ when "MARKETPLACE" then OpenNebula::MarketPlacePool.new(client)
1410
+ when "FLOWTEMPLATES" then OpenNebula::ServiceTemplatePool.new(client)
1087
1411
  end
1088
1412
 
1089
1413
  rc = pool.info
@@ -1269,6 +1593,43 @@ EOT
1269
1593
  end
1270
1594
  end
1271
1595
 
1596
+ def OpenNebulaHelper.update_obj(obj, file, plain = false)
1597
+ rc = obj.info(true)
1598
+
1599
+ return rc if OpenNebula.is_error?(rc)
1600
+
1601
+ if file
1602
+ path = file
1603
+ else
1604
+ tmp = Tempfile.new(obj['ID'])
1605
+ path = tmp.path
1606
+
1607
+ tmp.write(yield(obj)) if block_given?
1608
+ tmp.flush
1609
+
1610
+ if ENV['EDITOR']
1611
+ editor_path = ENV['EDITOR']
1612
+ else
1613
+ editor_path = EDITOR_PATH
1614
+ end
1615
+
1616
+ system("#{editor_path} #{path}")
1617
+
1618
+ unless $CHILD_STATUS.exitstatus.zero?
1619
+ STDERR.puts 'Editor not defined'
1620
+ exit(-1)
1621
+ end
1622
+
1623
+ tmp.close
1624
+ end
1625
+
1626
+ if plain
1627
+ obj.update(File.read(path), plain)
1628
+ else
1629
+ obj.update(File.read(path))
1630
+ end
1631
+ end
1632
+
1272
1633
  def OpenNebulaHelper.editor_input(contents=nil)
1273
1634
  require 'tempfile'
1274
1635