opennebula 5.12.9 → 6.0.0.1

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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ActionManager.rb +1 -1
  3. data/lib/CommandManager.rb +1 -1
  4. data/lib/DriverExecHelper.rb +44 -28
  5. data/lib/OpenNebulaDriver.rb +8 -4
  6. data/lib/VirtualMachineDriver.rb +9 -2
  7. data/lib/cloud/CloudClient.rb +3 -3
  8. data/lib/datacenter.rb +1257 -0
  9. data/lib/datastore.rb +1025 -0
  10. data/lib/distributed_firewall.rb +280 -0
  11. data/lib/file_helper.rb +370 -0
  12. data/lib/host.rb +1517 -0
  13. data/lib/logical_port.rb +50 -0
  14. data/lib/logical_switch.rb +77 -0
  15. data/lib/memoize.rb +74 -0
  16. data/lib/models.rb +32 -0
  17. data/lib/models/role.rb +1126 -0
  18. data/lib/models/service.rb +709 -0
  19. data/lib/network.rb +699 -0
  20. data/lib/nsx_client.rb +144 -0
  21. data/lib/nsx_component.rb +28 -0
  22. data/lib/nsx_constants.rb +149 -0
  23. data/lib/nsx_driver.rb +78 -0
  24. data/lib/nsx_error.rb +77 -0
  25. data/lib/nsx_rule.rb +193 -0
  26. data/lib/nsxt_client.rb +176 -0
  27. data/lib/nsxt_dfw.rb +196 -0
  28. data/lib/nsxt_logical_port.rb +94 -0
  29. data/lib/nsxt_rule.rb +188 -0
  30. data/lib/nsxt_tz.rb +38 -0
  31. data/lib/nsxv_client.rb +176 -0
  32. data/lib/nsxv_dfw.rb +202 -0
  33. data/lib/nsxv_logical_port.rb +107 -0
  34. data/lib/nsxv_rule.rb +172 -0
  35. data/lib/nsxv_tz.rb +41 -0
  36. data/lib/opaque_network.rb +134 -0
  37. data/lib/opennebula.rb +5 -2
  38. data/lib/opennebula/acl.rb +1 -1
  39. data/lib/opennebula/acl_pool.rb +1 -1
  40. data/lib/opennebula/client.rb +10 -2
  41. data/lib/opennebula/cluster.rb +1 -1
  42. data/lib/opennebula/cluster_pool.rb +1 -1
  43. data/lib/opennebula/datastore.rb +1 -1
  44. data/lib/opennebula/datastore_pool.rb +1 -1
  45. data/lib/opennebula/document.rb +8 -29
  46. data/lib/opennebula/document_json.rb +42 -12
  47. data/lib/opennebula/document_pool.rb +1 -1
  48. data/lib/opennebula/document_pool_json.rb +1 -1
  49. data/lib/opennebula/error.rb +4 -1
  50. data/lib/opennebula/flow.rb +23 -0
  51. data/lib/opennebula/flow/grammar.rb +1195 -0
  52. data/lib/opennebula/flow/service_pool.rb +190 -0
  53. data/lib/opennebula/flow/service_template.rb +608 -0
  54. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  55. data/lib/opennebula/flow/service_template_pool.rb +32 -0
  56. data/lib/opennebula/flow/validator.rb +499 -0
  57. data/lib/opennebula/group.rb +1 -1
  58. data/lib/opennebula/group_pool.rb +1 -1
  59. data/lib/opennebula/hook.rb +5 -12
  60. data/lib/opennebula/hook_log.rb +1 -1
  61. data/lib/opennebula/hook_pool.rb +1 -1
  62. data/lib/opennebula/host.rb +1 -1
  63. data/lib/opennebula/host_pool.rb +1 -1
  64. data/lib/opennebula/image.rb +19 -14
  65. data/lib/opennebula/image_pool.rb +1 -1
  66. data/lib/opennebula/ldap_auth.rb +1 -1
  67. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  68. data/lib/opennebula/lockable_ext.rb +163 -0
  69. data/lib/opennebula/marketplace.rb +1 -1
  70. data/lib/opennebula/marketplace_pool.rb +1 -1
  71. data/lib/opennebula/marketplaceapp.rb +9 -119
  72. data/lib/opennebula/marketplaceapp_ext.rb +586 -0
  73. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  74. data/lib/opennebula/oneflow_client.rb +4 -3
  75. data/lib/opennebula/pool.rb +6 -3
  76. data/lib/opennebula/pool_element.rb +1 -1
  77. data/lib/opennebula/security_group.rb +1 -1
  78. data/lib/opennebula/security_group_pool.rb +1 -1
  79. data/lib/opennebula/server_cipher_auth.rb +1 -1
  80. data/lib/opennebula/server_x509_auth.rb +1 -1
  81. data/lib/opennebula/ssh_auth.rb +1 -1
  82. data/lib/opennebula/system.rb +1 -1
  83. data/lib/opennebula/template.rb +4 -13
  84. data/lib/opennebula/template_ext.rb +342 -0
  85. data/lib/opennebula/template_pool.rb +1 -1
  86. data/lib/opennebula/user.rb +26 -2
  87. data/lib/opennebula/user_pool.rb +1 -1
  88. data/lib/opennebula/utils.rb +1 -1
  89. data/lib/opennebula/vdc.rb +1 -1
  90. data/lib/opennebula/vdc_pool.rb +1 -1
  91. data/lib/opennebula/virtual_machine.rb +26 -206
  92. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  93. data/lib/opennebula/virtual_machine_pool.rb +1 -1
  94. data/lib/opennebula/virtual_network.rb +4 -10
  95. data/lib/opennebula/virtual_network_pool.rb +1 -1
  96. data/lib/opennebula/virtual_router.rb +4 -12
  97. data/lib/opennebula/virtual_router_pool.rb +1 -1
  98. data/lib/opennebula/vm_group.rb +4 -11
  99. data/lib/opennebula/vm_group_pool.rb +1 -1
  100. data/lib/opennebula/vntemplate.rb +4 -13
  101. data/lib/opennebula/vntemplate_pool.rb +1 -1
  102. data/lib/opennebula/wait_ext.rb +257 -0
  103. data/lib/opennebula/x509_auth.rb +1 -1
  104. data/lib/opennebula/xml_element.rb +1 -1
  105. data/lib/opennebula/xml_pool.rb +1 -1
  106. data/lib/opennebula/xml_utils.rb +1 -1
  107. data/lib/opennebula/zone.rb +1 -1
  108. data/lib/opennebula/zone_pool.rb +1 -1
  109. data/lib/rest_client.rb +201 -0
  110. data/lib/scripts_common.rb +183 -0
  111. data/lib/transport_zone.rb +43 -0
  112. data/lib/vcenter_driver.rb +13 -12
  113. data/lib/vcenter_importer.rb +616 -0
  114. data/lib/vi_client.rb +281 -0
  115. data/lib/vi_helper.rb +313 -0
  116. data/lib/virtual_machine.rb +3477 -0
  117. data/lib/virtual_wire.rb +158 -0
  118. data/lib/vm_device.rb +80 -0
  119. data/lib/vm_disk.rb +202 -0
  120. data/lib/vm_folder.rb +69 -0
  121. data/lib/vm_helper.rb +30 -0
  122. data/lib/vm_monitor.rb +303 -0
  123. data/lib/vm_nic.rb +70 -0
  124. data/lib/vm_template.rb +1963 -0
  125. data/lib/vmm_importer.rb +121 -0
  126. metadata +140 -27
data/lib/nsxv_tz.rb ADDED
@@ -0,0 +1,41 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+ module NSXDriver
17
+
18
+ # Class Transport Zone
19
+ class NSXVtz < TransportZone
20
+
21
+ # ATTRIBUTES
22
+ attr_reader :tz_id
23
+
24
+ # CONSTRUCTOR
25
+ def initialize(nsx_client)
26
+ super(nsx_client)
27
+ # Construct base URLs
28
+ @url_tzs_nsxv = NSXConstants::NSXV_TZS
29
+ end
30
+
31
+ # METHODS
32
+ # Return the transport zones list
33
+ def tzs
34
+ @nsx_client
35
+ .get(@url_tzs_nsxv)
36
+ .xpath(NSXConstants::NSXV_TZS_XPATH)
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,134 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+ module NSXDriver
17
+
18
+ # Class Opaque Network NSX-T Network
19
+ class OpaqueNetwork < LogicalSwitch
20
+
21
+ # ATTRIBUTES
22
+ # attr_reader :ls_id, :admin_display
23
+
24
+ # CONSTRUCTOR
25
+ def initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil)
26
+ super(nsx_client)
27
+ if ls_id
28
+ initialize_with_id(ls_id)
29
+ else
30
+ if tz_id && ls_data
31
+ begin
32
+ @ls_id = new_logical_switch(ls_data)
33
+ rescue NSXError::IncorrectResponseCodeError => e
34
+ raise 'Opaque Network not created in ' \
35
+ "NSX Manager: #{e.message}"
36
+ end
37
+ unless @ls_id
38
+ raise 'Opaque Network not created in NSX Manager: '\
39
+ 'generic error'
40
+ end
41
+
42
+ # Construct URL of the created logical switch
43
+ @url_ls = NSXConstants::NSXT_LS_SECTION + @ls_id
44
+ @ls_vni = ls_vni
45
+ @ls_name = ls_name
46
+ @tz_id = ls_tz
47
+ @admin_display = 'UP'
48
+ end
49
+ end
50
+ end
51
+
52
+ # Creates a OpaqueNetwork from its name
53
+ def self.new_from_name(nsx_client, ls_name)
54
+ lswitch = new(nsx_client)
55
+ ls_id = lswitch.ls_id_from_name(nsx_client, ls_name)
56
+ unless ls_id
57
+ error_msg = "Opaque Network with name: #{ls_name} not found"
58
+ error = NSXError::ObjectNotFound
59
+ .new(error_msg)
60
+ raise error
61
+ end
62
+
63
+ # initialize_with_id(@ls_id)
64
+ lswitch.initialize_with_id(ls_id)
65
+ lswitch
66
+ end
67
+
68
+ # Creates a OpaqueNetwork from its id
69
+ def initialize_with_id(ls_id)
70
+ @ls_id = ls_id
71
+ # Construct URL of the created logical switch
72
+ @url_ls = NSXConstants::NSXT_LS_SECTION + \
73
+ @ls_id
74
+ if ls?
75
+ @ls_vni = ls_vni
76
+ @ls_name = ls_name
77
+ @tz_id = ls_tz
78
+ @admin_display = 'UP'
79
+ else
80
+ error_msg = "Opaque Network with id: #{ls_id} not found"
81
+ error = NSXError::ObjectNotFound
82
+ .new(error_msg)
83
+ raise error
84
+ end
85
+ end
86
+
87
+ # Get the logical switch id from its name
88
+ def ls_id_from_name(nsx_client, name)
89
+ url = NSXConstants::NSXT_LS_SECTION
90
+ lswitches = nsx_client.get(url)['results']
91
+ lswitches.each do |lswitch|
92
+ lsname = lswitch['display_name']
93
+ lsid = lswitch['id']
94
+ if lsname == name && lsid
95
+ return lsid
96
+ end
97
+ end
98
+ nil
99
+ end
100
+
101
+ # METHODS
102
+ # Check if logical switch exists
103
+ def ls?
104
+ @nsx_client.get(@url_ls) ? true : false
105
+ end
106
+
107
+ # Get logical switch's name
108
+ def ls_name
109
+ @nsx_client.get(@url_ls)['display_name']
110
+ end
111
+
112
+ # Get logical switch's vni
113
+ def ls_vni
114
+ @nsx_client.get(@url_ls)['vni']
115
+ end
116
+
117
+ # Get the Transport Zone of the logical switch
118
+ def ls_tz
119
+ @nsx_client.get(@url_ls)['transport_zone_id']
120
+ end
121
+
122
+ # Create a new logical switch (NSX-T: opaque network)
123
+ def new_logical_switch(ls_data)
124
+ @nsx_client.post(NSXConstants::NSXT_LS_SECTION, ls_data)
125
+ end
126
+
127
+ # Delete a logical switch
128
+ def delete_logical_switch
129
+ @nsx_client.delete(@url_ls)
130
+ end
131
+
132
+ end
133
+
134
+ end
data/lib/opennebula.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -49,7 +49,9 @@ require 'opennebula/datastore_pool'
49
49
  require 'opennebula/cluster'
50
50
  require 'opennebula/cluster_pool'
51
51
  require 'opennebula/document'
52
+ require 'opennebula/document_json'
52
53
  require 'opennebula/document_pool'
54
+ require 'opennebula/document_pool_json'
53
55
  require 'opennebula/zone'
54
56
  require 'opennebula/zone_pool'
55
57
  require 'opennebula/security_group'
@@ -70,9 +72,10 @@ require 'opennebula/vntemplate_pool'
70
72
  require 'opennebula/hook'
71
73
  require 'opennebula/hook_pool'
72
74
  require 'opennebula/hook_log'
75
+ require 'opennebula/flow'
73
76
 
74
77
  module OpenNebula
75
78
 
76
79
  # OpenNebula version
77
- VERSION = '5.12.9'
80
+ VERSION = '6.0.0.1'
78
81
  end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -88,7 +88,7 @@ module OpenNebula
88
88
  NO_ONE_AUTH_ERROR = "ONE_AUTH file not present"
89
89
 
90
90
  attr_accessor :one_auth
91
- attr_reader :one_endpoint
91
+ attr_reader :one_endpoint, :one_zmq
92
92
 
93
93
  begin
94
94
  require 'xmlparser'
@@ -152,6 +152,14 @@ module OpenNebula
152
152
 
153
153
  @async = !options[:sync]
154
154
 
155
+ if options[:subscriber_endpoint]
156
+ @one_zmq = options[:subscriber_endpoint]
157
+ elsif ENV["ONE_ZMQ"]
158
+ @one_zmq = ENV["ONE_ZMQ"]
159
+ else
160
+ @one_zmq = 'tcp://localhost:2101'
161
+ end
162
+
155
163
  timeout=nil
156
164
  if options[:timeout]
157
165
  timeout = options[:timeout]
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -14,6 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+ require 'opennebula/lockable_ext'
17
18
  require 'opennebula/pool_element'
18
19
 
19
20
  module OpenNebula
@@ -75,6 +76,8 @@ module OpenNebula
75
76
  # @example
76
77
  # doc = Document.new(Document.build_xml(3),rpc_client)
77
78
  def initialize(xml, client)
79
+ LockableExt.make_lockable(self, DOCUMENT_METHODS)
80
+
78
81
  super(xml,client)
79
82
  end
80
83
 
@@ -86,8 +89,8 @@ module OpenNebula
86
89
  #
87
90
  # @return [nil, OpenNebula::Error] nil in case of success, Error
88
91
  # otherwise
89
- def info()
90
- rc = super(DOCUMENT_METHODS[:info], 'DOCUMENT')
92
+ def info(decrypt = false)
93
+ rc = super(DOCUMENT_METHODS[:info], 'DOCUMENT', decrypt)
91
94
 
92
95
  if !OpenNebula.is_error?(rc) && self['TYPE'].to_i != document_type
93
96
  return OpenNebula::Error.new("[DocumentInfo] Error getting document [#{@pe_id}].")
@@ -108,6 +111,8 @@ module OpenNebula
108
111
  super(DOCUMENT_METHODS[:allocate], description, document_type)
109
112
  end
110
113
 
114
+ alias_method :allocate_xml, :allocate
115
+
111
116
  # Deletes the Document
112
117
  #
113
118
  # @return [nil, OpenNebula::Error] nil in case of success, Error
@@ -217,32 +222,6 @@ module OpenNebula
217
222
  return call(DOCUMENT_METHODS[:rename], @pe_id, name)
218
223
  end
219
224
 
220
- # Locks this object
221
- #
222
- # @param owner [String] String to identify the application requestiong
223
- # the lock
224
- #
225
- # @return [Bool, OpenNebula::Error] In case of success, true if the
226
- # lock was granted, and false if the object is already locked.
227
- def lock(owner="")
228
- return Error.new('ID not defined') if !@pe_id
229
-
230
- rc = @client.call(DOCUMENT_METHODS[:lock], @pe_id, owner)
231
-
232
- return rc
233
- end
234
-
235
- # Unlocks this object
236
- #
237
- # @param owner [String] String to identify the application requestiong
238
- # the unlock
239
- #
240
- # @return [nil, OpenNebula::Error] nil in case of success, Error
241
- # otherwise
242
- def unlock(owner="")
243
- return call(DOCUMENT_METHODS[:unlock], @pe_id, owner)
244
- end
245
-
246
225
  #######################################################################
247
226
  # Helpers to get Document information
248
227
  #######################################################################
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2020, 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 #
@@ -21,6 +21,15 @@ module OpenNebula
21
21
 
22
22
  TEMPLATE_TAG = "BODY"
23
23
 
24
+ # Returns current template tag
25
+ def template_tag
26
+ if @tag
27
+ @tag
28
+ else
29
+ TEMPLATE_TAG
30
+ end
31
+ end
32
+
24
33
  # Allocate a new Document containing the json inside the TEMPLATE
25
34
  #
26
35
  # @param [String] template_json json to be inserted in the TEMPLATE
@@ -30,19 +39,28 @@ module OpenNebula
30
39
  # @return [nil, OpenNebula::Error] nil in case of success, Error
31
40
  # otherwise
32
41
  #
33
- def allocate(template_json, name=nil)
42
+ def allocate(template_json, name = nil, tag = nil)
43
+ @tag = tag if tag
44
+
34
45
  text = build_template_xml(template_json, name)
35
46
 
36
47
  super(text)
37
48
  end
38
49
 
50
+ # Allocate XML Document
51
+ #
52
+ # @param xml [String] XML document content
53
+ def allocate_xml(xml)
54
+ super(xml)
55
+ end
56
+
39
57
  # Retrieves the information of the Service and all its Nodes.
40
58
  #
41
59
  # @return [nil, OpenNebula::Error] nil in case of success, Error
42
60
  # otherwise
43
61
  #
44
- def info
45
- rc = super
62
+ def info(decrypt = false)
63
+ rc = super(decrypt)
46
64
  if OpenNebula.is_error?(rc)
47
65
  return rc
48
66
  end
@@ -90,10 +108,10 @@ module OpenNebula
90
108
  def to_json(pretty_generate=true)
91
109
  hash = self.to_hash
92
110
 
93
- body = hash['DOCUMENT']['TEMPLATE']["#{TEMPLATE_TAG}"]
111
+ body = hash['DOCUMENT']['TEMPLATE']["#{template_tag}"]
94
112
  if body
95
113
  body_hash = JSON.parse(body)
96
- hash['DOCUMENT']['TEMPLATE']["#{TEMPLATE_TAG}"] = body_hash
114
+ hash['DOCUMENT']['TEMPLATE']["#{template_tag}"] = body_hash
97
115
  end
98
116
 
99
117
  if pretty_generate
@@ -106,7 +124,7 @@ module OpenNebula
106
124
 
107
125
  # Fill the @body hash with the values of the template
108
126
  def load_body
109
- body_str = self["TEMPLATE/#{TEMPLATE_TAG}"]
127
+ body_str = self["TEMPLATE/#{template_tag}"]
110
128
 
111
129
  if body_str
112
130
  begin
@@ -116,27 +134,39 @@ module OpenNebula
116
134
  end
117
135
  end
118
136
 
137
+ plain_str = self['TEMPLATE/PLAIN']
138
+
139
+ if plain_str
140
+ begin
141
+ @plain = JSON.parse(plain_str)
142
+ rescue JSON::JSONError
143
+ return OpenNebula::Error.new($!)
144
+ end
145
+ end
146
+
119
147
  return nil
120
148
  end
121
149
 
122
- private
123
-
124
150
  # Build an xml string incluiding the provided json
125
151
  #
126
152
  # @param [String] template_json The template to be inserted
127
153
  # @param [String, nil] name The string to be inserted as name
154
+ # @param [String, nil] plain information to add to the document
128
155
  # @return [String] The xml containing the json
129
156
  #
130
- def build_template_xml(template_json, name=nil)
157
+ def build_template_xml(template_json, name = nil, plain = nil)
131
158
  template_json ||= ""
159
+ plain ||= @plain
160
+ plain = plain.to_json if plain && !(plain.is_a? String)
132
161
 
133
162
  text = "<TEMPLATE>"
134
163
 
135
164
  text << "<NAME>#{name}</NAME>" if name
165
+ text << "<PLAIN><![CDATA[#{plain}]]></PLAIN>" if plain
136
166
 
137
- text << "<#{TEMPLATE_TAG}>"
167
+ text << "<#{template_tag}>"
138
168
  text << "<![CDATA[#{template_json}]]>"
139
- text << "</#{TEMPLATE_TAG}>"
169
+ text << "</#{template_tag}>"
140
170
 
141
171
  text << "</TEMPLATE>"
142
172