From 5c4b9b29cc270b16510cb211e155a86cc77c6a46 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Thu, 15 Apr 2021 15:54:10 +0200 Subject: [PATCH] B #5338: add register time to cloned service tmpl (#1106) (cherry picked from commit 2661e199af7f37389152c4defa6a3b1396355221) --- .../ruby/opennebula/flow/service_template.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/oca/ruby/opennebula/flow/service_template.rb b/src/oca/ruby/opennebula/flow/service_template.rb index 7413b95d60..ae02fb53b8 100644 --- a/src/oca/ruby/opennebula/flow/service_template.rb +++ b/src/oca/ruby/opennebula/flow/service_template.rb @@ -384,6 +384,9 @@ module OpenNebula return rc end + # add registration time, as the template is new + body['registration_time'] = Integer(Time.now) + # update the template with the new body doc.update(body.to_json) @@ -391,6 +394,31 @@ module OpenNebula new_id end + # Clones a service template + # + # @param name [Stirng] New name + # + # @return [Integer] New template ID + def clone(name) + new_id = super + + doc = OpenNebula::ServiceTemplate.new_with_id(new_id, @client) + rc = doc.info + + return rc if OpenNebula.is_error?(rc) + + body = JSON.parse(doc["TEMPLATE/#{TEMPLATE_TAG}"]) + + # add registration time, as the template is new + body['registration_time'] = Integer(Time.now) + + # update the template with the new body + DocumentJSON.instance_method(:update).bind(doc).call(body.to_json) + + # return the new document ID + new_id + end + # Replaces the raw template contents # # @param template [String] New template contents, in the form KEY = VAL