From 491e681d73e1b9236cc75d82a49e0a3016d22ae2 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Date: Mon, 1 Apr 2019 12:49:05 +0200 Subject: [PATCH] F #1414: delete parameter from template * Add function to delete parameters from template * Add new type of update (2 means delete) * Modify the CLI * Modify different APIs * Modify onegate, so attribute can be deleted --- include/ImageTemplate.h | 5 ++ include/PoolObjectSQL.h | 11 ++++ include/RequestManagerUpdateTemplate.h | 3 + include/Template.h | 14 +++++ include/VirtualMachine.h | 10 ++++ include/VirtualMachineTemplate.h | 5 ++ include/VirtualNetworkTemplate.h | 5 ++ share/onegate/onegate | 26 +++++++-- src/cli/one_helper.rb | 21 +++++++ src/cli/onecluster | 17 +++--- src/cli/onedatastore | 17 +++--- src/cli/onegroup | 17 +++--- src/cli/onehost | 19 +++---- src/cli/oneimage | 17 +++--- src/cli/onemarket | 13 ++--- src/cli/onemarketapp | 14 ++--- src/cli/onesecgroup | 17 +++--- src/cli/onetemplate | 17 +++--- src/cli/oneuser | 17 +++--- src/cli/onevdc | 17 +++--- src/cli/onevm | 22 ++++---- src/cli/onevmgroup | 17 +++--- src/cli/onevnet | 17 +++--- src/cli/onevntemplate | 17 +++--- src/cli/onevrouter | 13 ++--- src/cli/onezone | 17 +++--- src/oca/go/src/goca/cluster.go | 2 +- src/oca/go/src/goca/datastore.go | 1 + src/oca/go/src/goca/document.go | 1 + src/oca/go/src/goca/group.go | 1 + src/oca/go/src/goca/host.go | 1 + src/oca/go/src/goca/image.go | 2 +- src/oca/go/src/goca/marketplace.go | 1 + src/oca/go/src/goca/marketplaceapp.go | 1 + src/oca/go/src/goca/securitygroup.go | 1 + src/oca/go/src/goca/template.go | 2 +- src/oca/go/src/goca/user.go | 1 + src/oca/go/src/goca/vdc.go | 1 + src/oca/go/src/goca/virtualnetwork.go | 1 + src/oca/go/src/goca/virtualrouter.go | 2 +- src/oca/go/src/goca/vm.go | 2 +- src/oca/go/src/goca/vntemplate.go | 2 +- src/oca/go/src/goca/zone.go | 1 + .../opennebula/client/cluster/Cluster.java | 20 ++++--- .../client/datastore/Datastore.java | 20 ++++--- .../opennebula/client/document/Document.java | 11 ++-- .../org/opennebula/client/group/Group.java | 20 ++++--- .../src/org/opennebula/client/host/Host.java | 20 ++++--- .../org/opennebula/client/image/Image.java | 20 ++++--- .../client/marketplace/MarketPlace.java | 20 ++++--- .../client/marketplaceapp/MarketPlaceApp.java | 20 ++++--- .../client/secgroup/SecurityGroup.java | 20 ++++--- .../opennebula/client/template/Template.java | 20 ++++--- .../src/org/opennebula/client/user/User.java | 20 ++++--- .../src/org/opennebula/client/vdc/Vdc.java | 20 ++++--- .../opennebula/client/vm/VirtualMachine.java | 20 ++++--- .../opennebula/client/vmgroup/VMGroup.java | 20 ++++--- .../client/vnet/VirtualNetwork.java | 20 ++++--- .../vntemplate/VirtualNetworkTemplate.java | 20 ++++--- .../client/vrouter/VirtualRouter.java | 20 ++++--- .../src/org/opennebula/client/zone/Zone.java | 20 ++++--- src/oca/ruby/opennebula/cluster.rb | 10 ++-- src/oca/ruby/opennebula/datastore.rb | 10 ++-- src/oca/ruby/opennebula/group.rb | 12 ++-- src/oca/ruby/opennebula/host.rb | 10 ++-- src/oca/ruby/opennebula/image.rb | 10 ++-- src/oca/ruby/opennebula/marketplace.rb | 10 ++-- src/oca/ruby/opennebula/marketplaceapp.rb | 10 ++-- src/oca/ruby/opennebula/security_group.rb | 10 ++-- src/oca/ruby/opennebula/template.rb | 10 ++-- src/oca/ruby/opennebula/user.rb | 10 ++-- src/oca/ruby/opennebula/vdc.rb | 10 ++-- src/oca/ruby/opennebula/virtual_machine.rb | 12 ++-- src/oca/ruby/opennebula/virtual_network.rb | 10 ++-- src/oca/ruby/opennebula/virtual_router.rb | 10 ++-- src/oca/ruby/opennebula/vm_group.rb | 10 ++-- src/oca/ruby/opennebula/vntemplate.rb | 10 ++-- src/oca/ruby/opennebula/zone.rb | 10 ++-- src/onegate/onegate-server.rb | 55 +++++++++++++------ src/pool/PoolObjectSQL.cc | 39 +++++++++++++ src/rm/RequestManagerUpdateTemplate.cc | 27 ++++++++- .../models/OpenNebulaJSON/ClusterJSON.rb | 4 +- .../models/OpenNebulaJSON/DatastoreJSON.rb | 4 +- .../models/OpenNebulaJSON/GroupJSON.rb | 4 +- .../models/OpenNebulaJSON/HostJSON.rb | 6 +- .../models/OpenNebulaJSON/ImageJSON.rb | 4 +- .../OpenNebulaJSON/MarketPlaceAppJSON.rb | 4 +- .../OpenNebulaJSON/SecurityGroupJSON.rb | 4 +- .../models/OpenNebulaJSON/TemplateJSON.rb | 4 +- .../models/OpenNebulaJSON/UserJSON.rb | 4 +- .../models/OpenNebulaJSON/VMGroupJSON.rb | 4 +- src/sunstone/models/OpenNebulaJSON/VdcJSON.rb | 4 +- .../OpenNebulaJSON/VirtualMachineJSON.rb | 4 +- .../OpenNebulaJSON/VirtualNetworkJSON.rb | 4 +- .../VirtualNetworkTemplateJSON.rb | 4 +- .../OpenNebulaJSON/VirtualRouterJSON.rb | 4 +- .../models/OpenNebulaJSON/ZoneJSON.rb | 4 +- src/sunstone/public/app/opennebula/cluster.js | 2 +- .../public/app/opennebula/datastore.js | 2 +- src/sunstone/public/app/opennebula/group.js | 2 +- src/sunstone/public/app/opennebula/host.js | 2 +- src/sunstone/public/app/opennebula/image.js | 2 +- .../public/app/opennebula/marketplace.js | 2 +- .../public/app/opennebula/marketplaceapp.js | 2 +- src/sunstone/public/app/opennebula/network.js | 2 +- .../public/app/opennebula/securitygroup.js | 2 +- .../public/app/opennebula/servicetemplate.js | 2 +- .../public/app/opennebula/template.js | 2 +- src/sunstone/public/app/opennebula/user.js | 2 +- src/sunstone/public/app/opennebula/vdc.js | 2 +- .../public/app/opennebula/virtualrouter.js | 2 +- src/sunstone/public/app/opennebula/vm.js | 2 +- .../public/app/opennebula/vntemplate.js | 2 +- src/sunstone/public/app/opennebula/zone.js | 2 +- src/template/Template.cc | 46 ++++++++++++++++ src/vm/VirtualMachine.cc | 50 +++++++++++++++-- 116 files changed, 823 insertions(+), 427 deletions(-) mode change 100644 => 100755 src/onegate/onegate-server.rb diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index 838ee4398e8..683609780c5 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -60,6 +60,11 @@ class ImageTemplate : public Template return Template::check_restricted(rs_attr, restricted); } + virtual bool is_restricted(const string& attr) + { + return Template::is_restricted(attr, restricted); + } + static void parse_restricted(vector& ra) { Template::parse_restricted(ra, restricted); diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index 34a84d162de..81128b64539 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -530,6 +530,17 @@ class PoolObjectSQL : public ObjectSQL, public ObjectXML */ virtual int append_template(const string& tmpl_str, bool keep_restricted, string& error); + /** + * Delete attributes from this object's template. Object should be updated + * after calling this method + * @param attributes attributes to delete + * @param delete_restricted If true, the restricted attributes of the + * current template can be deleted + * @param error string describing the error if any + * @return 0 on success + */ + virtual int delete_template(const string& attributes, bool delete_restricted, string& error); + /** * Fills a auth class to perform an authZ/authN request based on the object * attributes diff --git a/include/RequestManagerUpdateTemplate.h b/include/RequestManagerUpdateTemplate.h index ad62b25fd43..007a042f8b8 100644 --- a/include/RequestManagerUpdateTemplate.h +++ b/include/RequestManagerUpdateTemplate.h @@ -48,6 +48,9 @@ class RequestManagerUpdateTemplate: public Request virtual int append_template(PoolObjectSQL * object, const string & tmpl, const RequestAttributes &att, string &error_str); + + virtual int delete_template(PoolObjectSQL * object, const string & attributes, + const RequestAttributes &att, string &error_str); }; /* ------------------------------------------------------------------------- */ diff --git a/include/Template.h b/include/Template.h index aa086d671b7..4e003591296 100644 --- a/include/Template.h +++ b/include/Template.h @@ -436,6 +436,17 @@ class Template return false; } + /** + * Check if an attribute is restricted + * @param attr the attribute + * + * @return true if the attribute is restricted + */ + virtual bool is_restricted(const string& attr) + { + return false; + } + /** * @return true if template is empty */ @@ -498,6 +509,9 @@ class Template bool check_restricted(string& rs_attr, const std::map >& ras); + + bool is_restricted(const string& attr, + const std::map >& ras); /** * Updates the xml root element name * diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index cbf67c4a6a7..cb6684e3ed7 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -941,6 +941,16 @@ class VirtualMachine : public PoolObjectSQL int append_template(const string& tmpl_str, bool keep_restricted, string& error); + /** + * Delete attributes from the *user template*. + * @param attributes attributes to delete + * @param delete_restricted If true, the restricted attributes of the + * current template can be deleted + * @param error string describing the error if any + * @return 0 on success + */ + int delete_template(const string& attributes, bool delete_restricted, string& error); + /** * This function gets an attribute from the user template * @param name of the attribute diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 006430c8f65..4bcd327eecd 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -71,6 +71,11 @@ class VirtualMachineTemplate : public Template return Template::check_restricted(rs_attr, restricted); } + virtual bool is_restricted(const string& attr) + { + return Template::is_restricted(attr, restricted); + } + static void parse_restricted(vector& ra) { Template::parse_restricted(ra, restricted); diff --git a/include/VirtualNetworkTemplate.h b/include/VirtualNetworkTemplate.h index af6f3a15e89..34f19dc22e0 100644 --- a/include/VirtualNetworkTemplate.h +++ b/include/VirtualNetworkTemplate.h @@ -46,6 +46,11 @@ class VirtualNetworkTemplate : public Template return Template::check_restricted(rs_attr, restricted); } + virtual bool is_restricted(const string& attr) + { + return Template::is_restricted(attr, restricted); + } + static void parse_restricted(vector& ra) { Template::parse_restricted(ra, restricted); diff --git a/share/onegate/onegate b/share/onegate/onegate index e4a6de16fb2..b8d43c60d59 100755 --- a/share/onegate/onegate +++ b/share/onegate/onegate @@ -498,6 +498,8 @@ Available commands $ onegate vm update [VMID] --data KEY=VALUE[\\nKEY2=VALUE2] + $ onegate vm update [VMID] --erase KEY + $ onegate vm ACTION VMID $ onegate resume [VMID] $ onegate stop [VMID] @@ -526,6 +528,10 @@ OptionParser.new do |opts| options[:data] = data end + opts.on("-e", "--erase DATA", "Data to be removed from the VM") do |data| + options[:erase] = data + end + opts.on("-r", "--role ROLE", "Service role") do |role| options[:role] = role end @@ -567,15 +573,27 @@ when "vm" OneGate::VirtualMachine.print(json_hash) end when "update" - if !options[:data] - puts "You have to provide the data as a param (--data)" + if !options[:data] && !options[:erase] + puts "You have to provide the data as a param (--data, --erase)" exit -1 end + data = {} + + if options[:data] + data[:data] = options[:data] + data[:type] = 1 + else + data[:data] = options[:erase] + data[:type] = 2 + end + + data = URI.encode_www_form(data) + if ARGV[2] - response = client.put("/vms/"+ARGV[2], options[:data]) + response = client.put("/vms/" + ARGV[2], data) else - response = client.put("/vm", options[:data]) + response = client.put("/vm", data) end if CloudClient::is_error?(response) diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 3906290d12c..44937ce1309 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -86,6 +86,14 @@ module OpenNebulaHelper :description => "Append new attributes to the current template" } + DELETE_TEMPLATE = { + :name => "delete_template", + :large => "--delete-template list", + :description => "Comma separated attributes to delete " \ + "from the current template.", + :format => String + } + # Command line VM template options TEMPLATE_NAME_VM={ :name => 'name', @@ -1183,6 +1191,19 @@ def OpenNebulaHelper.update_template_helper(append, id, resource, path, xpath, u end end + def OpenNebulaHelper.get_update(args, obj, options, xpath = 'TEMPLATE') + if options[:append] + { :type => 1, + :data => append_template(args[0], obj, args[1], xpath) } + elsif options[:delete_template] + { :type => 2, + :data => options[:delete_template] } + else + { :type => 0, + :data => update_template(args[0], obj, args[1], xpath) } + end + end + def OpenNebulaHelper.editor_input(contents=nil) require 'tempfile' diff --git a/src/cli/onecluster b/src/cli/onecluster index e93209c3442..c5e8ded5c46 100755 --- a/src/cli/onecluster +++ b/src/cli/onecluster @@ -186,18 +186,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :clusterid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 381dfaa916f..e87cecb8e53 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -163,18 +163,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :datastoreid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onegroup b/src/cli/onegroup index 42ba01bccc9..c1e10af72d5 100755 --- a/src/cli/onegroup +++ b/src/cli/onegroup @@ -121,18 +121,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :groupid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onehost b/src/cli/onehost index 3ab77000d11..11dbe8f4c08 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -127,7 +127,7 @@ CommandParser::CmdParser.new(ARGV) do end rc = host.allocate(args[0], options[:im], options[:vm], cid) if !OpenNebula.is_error?(rc) && !options[:type].nil? - host.update(str, true) + host.update(str, 1) end rc @@ -186,18 +186,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :hostid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'updated') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/oneimage b/src/cli/oneimage index 804a1e9c868..f6d00e94f34 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -249,18 +249,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :imageid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onemarket b/src/cli/onemarket index f52b7d44870..7e5339b9950 100755 --- a/src/cli/onemarket +++ b/src/cli/onemarket @@ -156,15 +156,14 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :marketplaceid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] - obj.update(str, options[:append]) + obj.update(str, type) end end diff --git a/src/cli/onemarketapp b/src/cli/onemarketapp index 2e920c539db..4722e80f966 100755 --- a/src/cli/onemarketapp +++ b/src/cli/onemarketapp @@ -215,16 +215,14 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :appid, [:file, nil], - :options => OpenNebulaHelper::APPEND do - + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] - obj.update(str, options[:append]) + obj.update(str, type) end end diff --git a/src/cli/onesecgroup b/src/cli/onesecgroup index b2d05c70a12..dae33438d96 100755 --- a/src/cli/onesecgroup +++ b/src/cli/onesecgroup @@ -162,18 +162,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :secgroupid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 2f5031705bc..0f5f3d07b55 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -320,18 +320,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :templateid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/oneuser b/src/cli/oneuser index d6d85754c42..f06e88a3fe8 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -281,18 +281,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :userid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onevdc b/src/cli/onevdc index 26d16862af0..bb2078f1ab4 100755 --- a/src/cli/onevdc +++ b/src/cli/onevdc @@ -152,18 +152,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :vdcid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onevm b/src/cli/onevm index 3611e40449d..8e7017762f5 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -301,20 +301,20 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :vmid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper - .append_template(args[0], obj, args[1], 'USER_TEMPLATE') - else - str = OpenNebulaHelper - .update_template(args[0], obj, args[1], 'USER_TEMPLATE') - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, + obj, + options, + 'USER_TEMPLATE') + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onevmgroup b/src/cli/onevmgroup index 53d0a602a38..235b2babce7 100755 --- a/src/cli/onevmgroup +++ b/src/cli/onevmgroup @@ -182,18 +182,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :vmgroupid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onevnet b/src/cli/onevnet index f9e2eba8b5f..2c7eaabefa6 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -315,18 +315,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :vnetid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onevntemplate b/src/cli/onevntemplate index 647320d78e8..8d4fb30e8fd 100755 --- a/src/cli/onevntemplate +++ b/src/cli/onevntemplate @@ -268,18 +268,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :templateid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/cli/onevrouter b/src/cli/onevrouter index 32017fcfca1..bc590e908a2 100755 --- a/src/cli/onevrouter +++ b/src/cli/onevrouter @@ -240,15 +240,14 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :vrouterid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] - obj.update(str, options[:append]) + obj.update(str, type) end end diff --git a/src/cli/onezone b/src/cli/onezone index 09291b6771d..c2ba60ee026 100755 --- a/src/cli/onezone +++ b/src/cli/onezone @@ -153,18 +153,17 @@ CommandParser::CmdParser.new(ARGV) do EOT command :update, update_desc, :zoneid, [:file, nil], - :options => OpenNebulaHelper::APPEND do + :options => [OpenNebulaHelper::APPEND, + OpenNebulaHelper::DELETE_TEMPLATE] do helper.perform_action(args[0], options, 'modified') do |obj| - if options[:append] - str = OpenNebulaHelper.append_template(args[0], obj, args[1]) - else - str = OpenNebulaHelper.update_template(args[0], obj, args[1]) - end - helper.set_client(options) - obj = helper.retrieve_resource(obj.id) - obj.update(str, options[:append]) + obj = helper.retrieve_resource(obj.id) + data = OpenNebulaHelper.get_update(args, obj, options) + str = data[:data] + type = data[:type] + + obj.update(str, type) end end diff --git a/src/oca/go/src/goca/cluster.go b/src/oca/go/src/goca/cluster.go index b9c8e025e8e..ef5adffe969 100644 --- a/src/oca/go/src/goca/cluster.go +++ b/src/oca/go/src/goca/cluster.go @@ -115,7 +115,7 @@ func (cluster *Cluster) Delete() error { // * tpl: The new cluster contents. Syntax can be the usual attribute=value or // XML. // * appendCluster: Update type: 0: Replace the whole cluster. 1: Merge new -// cluster with the existing one. +// cluster with the existing one. 2: Delete the attributes. func (cluster *Cluster) Update(tpl string, appendCluster int) error { _, err := client.Call("one.cluster.update", cluster.ID, tpl, appendCluster) return err diff --git a/src/oca/go/src/goca/datastore.go b/src/oca/go/src/goca/datastore.go index b2a4c1a2616..b1fc3ac6c8b 100644 --- a/src/oca/go/src/goca/datastore.go +++ b/src/oca/go/src/goca/datastore.go @@ -151,6 +151,7 @@ func (datastore *Datastore) Delete() error { // Update replaces the datastore template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (datastore *Datastore) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.datastore.update", datastore.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/document.go b/src/oca/go/src/goca/document.go index 2935490196c..ee93881c736 100644 --- a/src/oca/go/src/goca/document.go +++ b/src/oca/go/src/goca/document.go @@ -140,6 +140,7 @@ func (document *Document) Delete() error { // Update replaces the document template contents. // * tpl: The new document template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (document *Document) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.document.update", document.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/group.go b/src/oca/go/src/goca/group.go index a293391886e..ef138990a1c 100644 --- a/src/oca/go/src/goca/group.go +++ b/src/oca/go/src/goca/group.go @@ -125,6 +125,7 @@ func (group *Group) Info() error { // Update replaces the group template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attibutes. func (group *Group) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.group.update", group.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/host.go b/src/oca/go/src/goca/host.go index 3667bc699c8..0dc90499915 100644 --- a/src/oca/go/src/goca/host.go +++ b/src/oca/go/src/goca/host.go @@ -217,6 +217,7 @@ func (host *Host) Status(status int) error { // Update replaces the host’s template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// 2: Delete the attributes. func (host *Host) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.host.update", host.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/image.go b/src/oca/go/src/goca/image.go index 8a3674ae370..11426b3bb57 100644 --- a/src/oca/go/src/goca/image.go +++ b/src/oca/go/src/goca/image.go @@ -242,7 +242,7 @@ func (image *Image) Clone(cloneName string, dsid int) (uint, error) { } // Update will modify the image's template. If appendTemplate is 0, it will -// replace the whole template. If its 1, it will merge. +// replace the whole template. If its 1, it will merge. If its 2, it will delete. func (image *Image) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.image.update", image.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/marketplace.go b/src/oca/go/src/goca/marketplace.go index 0ad22113019..d92fc4cee08 100644 --- a/src/oca/go/src/goca/marketplace.go +++ b/src/oca/go/src/goca/marketplace.go @@ -139,6 +139,7 @@ func (market *MarketPlace) Delete() error { // Update replaces the marketplace template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (market *MarketPlace) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.market.update", market.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/marketplaceapp.go b/src/oca/go/src/goca/marketplaceapp.go index aa8aef15c60..f224d37a54b 100644 --- a/src/oca/go/src/goca/marketplaceapp.go +++ b/src/oca/go/src/goca/marketplaceapp.go @@ -155,6 +155,7 @@ func (marketApp *MarketPlaceApp) Enable(enable bool) error { // Update replaces the marketplace app template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (marketApp *MarketPlaceApp) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.marketapp.update", marketApp.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/securitygroup.go b/src/oca/go/src/goca/securitygroup.go index 80531a5aab0..fdc5c3b21b6 100644 --- a/src/oca/go/src/goca/securitygroup.go +++ b/src/oca/go/src/goca/securitygroup.go @@ -154,6 +154,7 @@ func (sg *SecurityGroup) Delete() error { // Update replaces the security group template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (sg *SecurityGroup) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.secgroup.update", sg.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/template.go b/src/oca/go/src/goca/template.go index b5402a3d3fb..bb390ac7093 100644 --- a/src/oca/go/src/goca/template.go +++ b/src/oca/go/src/goca/template.go @@ -165,7 +165,7 @@ func (template *Template) Info() error { } // Update will modify the template. If appendTemplate is 0, it will -// replace the whole template. If its 1, it will merge. +// replace the whole template. If its 1, it will merge. If its 2, it will delete. func (template *Template) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.template.update", template.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/user.go b/src/oca/go/src/goca/user.go index ae2fcf65485..125d6d00795 100644 --- a/src/oca/go/src/goca/user.go +++ b/src/oca/go/src/goca/user.go @@ -146,6 +146,7 @@ func (user *User) Login(token string, timeSeconds int, effectiveGID int) error { // Update replaces the user template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (user *User) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.user.update", user.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/vdc.go b/src/oca/go/src/goca/vdc.go index d45e2e5c744..4dd088b54cf 100644 --- a/src/oca/go/src/goca/vdc.go +++ b/src/oca/go/src/goca/vdc.go @@ -136,6 +136,7 @@ func (vdc *Vdc) Delete() error { // Update replaces the VDC template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (vdc *Vdc) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.vdc.update", vdc.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/virtualnetwork.go b/src/oca/go/src/goca/virtualnetwork.go index 0f912f0ad92..5faa94f9f1c 100644 --- a/src/oca/go/src/goca/virtualnetwork.go +++ b/src/oca/go/src/goca/virtualnetwork.go @@ -235,6 +235,7 @@ func (vn *VirtualNetwork) Release(tpl string) error { // Update replaces the virtual network template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (vn *VirtualNetwork) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.vn.update", vn.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/virtualrouter.go b/src/oca/go/src/goca/virtualrouter.go index 007ada899c0..6cd95fea7fa 100644 --- a/src/oca/go/src/goca/virtualrouter.go +++ b/src/oca/go/src/goca/virtualrouter.go @@ -142,7 +142,7 @@ func (vr *VirtualRouter) Info() error { } // Update will modify the virtual router. If appendVirtualRouter is 0, it will -// replace the whole virtual router. If its 1, it will merge. +// replace the whole virtual router. If its 1, it will merge. If its 2, it will delete. func (vr *VirtualRouter) Update(tpl string, appendVirtualRouter int) error { _, err := client.Call("one.vrouter.update", vr.ID, tpl, appendVirtualRouter) return err diff --git a/src/oca/go/src/goca/vm.go b/src/oca/go/src/goca/vm.go index 642b4713bee..6e325a5f1ae 100644 --- a/src/oca/go/src/goca/vm.go +++ b/src/oca/go/src/goca/vm.go @@ -780,7 +780,7 @@ func (vm *VM) Info() error { } // Update will modify the VM's template. If appendTemplate is 0, it will -// replace the whole template. If its 1, it will merge. +// replace the whole template. If its 1, it will merge. If its 2, it will delete. func (vm *VM) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.vm.update", vm.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/vntemplate.go b/src/oca/go/src/goca/vntemplate.go index 242b5defb86..2e829e9cfbb 100644 --- a/src/oca/go/src/goca/vntemplate.go +++ b/src/oca/go/src/goca/vntemplate.go @@ -135,7 +135,7 @@ func (vntemplate *VNTemplate) Info() error { } // Update will modify the vntemplate. If appendTemplate is 0, it will -// replace the whole vntemplate. If its 1, it will merge. +// replace the whole vntemplate. If its 1, it will merge. If its 2, it will delete. func (vntemplate *VNTemplate) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.vntemplate.update", vntemplate.ID, tpl, appendTemplate) return err diff --git a/src/oca/go/src/goca/zone.go b/src/oca/go/src/goca/zone.go index 79322bbc9b4..8eb1cb0fbd2 100644 --- a/src/oca/go/src/goca/zone.go +++ b/src/oca/go/src/goca/zone.go @@ -154,6 +154,7 @@ func (zone *Zone) Delete() error { // Update replaces the zone template contents. // * tpl: The new template contents. Syntax can be the usual attribute=value or XML. // * appendTemplate: Update type: 0: Replace the whole template. 1: Merge new template with the existing one. +// * 2: Delete the attributes. func (zone *Zone) Update(tpl string, appendTemplate int) error { _, err := client.Call("one.zone.update", zone.ID, tpl, appendTemplate) return err diff --git a/src/oca/java/src/org/opennebula/client/cluster/Cluster.java b/src/oca/java/src/org/opennebula/client/cluster/Cluster.java index 279f1f9f782..eced8f6d659 100644 --- a/src/oca/java/src/org/opennebula/client/cluster/Cluster.java +++ b/src/oca/java/src/org/opennebula/client/cluster/Cluster.java @@ -107,13 +107,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The id of the target cluster we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the cluster id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -248,19 +251,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the cluster template. * * @param new_template New cluster template. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the cluster id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java index 756731ddfb8..2e2c9e5f036 100644 --- a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java +++ b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java @@ -128,13 +128,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The id of the target datastore we want to modify. * @param new_template New datastore contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the datastore id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -280,19 +283,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the datastore template. * * @param new_template New datastore template. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the datastore id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/document/Document.java b/src/oca/java/src/org/opennebula/client/document/Document.java index 8d264c0ebe1..37625ed1bf6 100644 --- a/src/oca/java/src/org/opennebula/client/document/Document.java +++ b/src/oca/java/src/org/opennebula/client/document/Document.java @@ -158,19 +158,22 @@ public OneResponse delete() */ public OneResponse update(String new_document) { - return update(new_document, false); + return update(new_document, 0); } /** * Replaces the document template contents. * * @param new_document New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the document id. */ - public OneResponse update(String new_document, boolean append) + public OneResponse update(String new_document, int type) { - return client.call(UPDATE, id, new_document, append); + return client.call(UPDATE, id, new_document, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/group/Group.java b/src/oca/java/src/org/opennebula/client/group/Group.java index f2f8cd64146..2972bec28ec 100644 --- a/src/oca/java/src/org/opennebula/client/group/Group.java +++ b/src/oca/java/src/org/opennebula/client/group/Group.java @@ -117,13 +117,16 @@ public static OneResponse setQuota(Client client, int id, String quota_template) * @param client XML-RPC Client. * @param id The group id of the target group we want to modify. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the group id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -198,19 +201,22 @@ public OneResponse setQuota(String quota_template) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the group id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/host/Host.java b/src/oca/java/src/org/opennebula/client/host/Host.java index 57f878649c5..126cd303fb3 100644 --- a/src/oca/java/src/org/opennebula/client/host/Host.java +++ b/src/oca/java/src/org/opennebula/client/host/Host.java @@ -175,13 +175,16 @@ public static OneResponse status(Client client, int id, Status status) * @param client XML-RPC Client. * @param id The image id of the target host we want to modify. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the host id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -275,19 +278,22 @@ public OneResponse offline() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the host id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/image/Image.java b/src/oca/java/src/org/opennebula/client/image/Image.java index 21b880498df..b938bd08798 100644 --- a/src/oca/java/src/org/opennebula/client/image/Image.java +++ b/src/oca/java/src/org/opennebula/client/image/Image.java @@ -151,13 +151,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The image id of the target image we want to modify. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the image id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -405,19 +408,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the image id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java b/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java index e6e17583237..7413365dbcd 100644 --- a/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java +++ b/src/oca/java/src/org/opennebula/client/marketplace/MarketPlace.java @@ -102,13 +102,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The id of the target MarketPlace we want to modify. * @param new_template New MarketPlace contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the MarketPlace id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -226,19 +229,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the MarketPlace template. * * @param new_template New MarketPlace template. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the MarketPlace id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java b/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java index 16ac730f57a..7fd0e56f363 100644 --- a/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java +++ b/src/oca/java/src/org/opennebula/client/marketplaceapp/MarketPlaceApp.java @@ -122,13 +122,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The MarketPlaceApp id of the target MarketPlaceApp we want to modify. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the MarketPlaceApp id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -284,19 +287,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the MarketPlaceApp id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java b/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java index b0d771e6e4d..fe38244f432 100644 --- a/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java +++ b/src/oca/java/src/org/opennebula/client/secgroup/SecurityGroup.java @@ -177,13 +177,16 @@ public static OneResponse chmod(Client client, int id, int octet) * @param client XML-RPC Client. * @param id The id of the target security group we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the security group id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -342,19 +345,22 @@ public OneResponse chmod(int octet) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the security group template contents. * * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the security group id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/template/Template.java b/src/oca/java/src/org/opennebula/client/template/Template.java index 014235194af..57fb0475cc8 100644 --- a/src/oca/java/src/org/opennebula/client/template/Template.java +++ b/src/oca/java/src/org/opennebula/client/template/Template.java @@ -123,13 +123,16 @@ public static OneResponse delete(Client client, int id, boolean recursive) * @param client XML-RPC Client. * @param id The template id of the target template we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the template id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -438,19 +441,22 @@ public OneResponse delete(boolean recursive) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the template id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/user/User.java b/src/oca/java/src/org/opennebula/client/user/User.java index fc8469a6de5..15208c87fae 100644 --- a/src/oca/java/src/org/opennebula/client/user/User.java +++ b/src/oca/java/src/org/opennebula/client/user/User.java @@ -205,13 +205,16 @@ public static OneResponse chauth(Client client, * @param client XML-RPC Client. * @param id The user id of the target user we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the user id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -371,19 +374,22 @@ public OneResponse chauth(String auth) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the user template contents. * * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the user id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/vdc/Vdc.java b/src/oca/java/src/org/opennebula/client/vdc/Vdc.java index c355c17d108..4f2917e766b 100644 --- a/src/oca/java/src/org/opennebula/client/vdc/Vdc.java +++ b/src/oca/java/src/org/opennebula/client/vdc/Vdc.java @@ -113,13 +113,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The vdc id of the target vdc we want to modify. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vdc id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -308,19 +311,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vdc id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index a795d779007..ed8134a0300 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -282,13 +282,16 @@ public static OneResponse allocate(Client client, String description, * @param client XML-RPC Client. * @param id The id of the target vm. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If an error occurs the error message contains the reason. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -973,19 +976,22 @@ public OneResponse rename(String name) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces this VM's user template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If an error occurs the error message contains the reason. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/vmgroup/VMGroup.java b/src/oca/java/src/org/opennebula/client/vmgroup/VMGroup.java index 0ab4207322d..bcc9d6a6042 100644 --- a/src/oca/java/src/org/opennebula/client/vmgroup/VMGroup.java +++ b/src/oca/java/src/org/opennebula/client/vmgroup/VMGroup.java @@ -177,13 +177,16 @@ public static OneResponse chmod(Client client, int id, int octet) * @param client XML-RPC Client. * @param id The id of the target vmgroup we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vmgroup id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -339,19 +342,22 @@ public OneResponse chmod(int octet) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the vmgroup template contents. * * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vmgroup id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java index 5a75af07523..63d0feb0a07 100644 --- a/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java +++ b/src/oca/java/src/org/opennebula/client/vnet/VirtualNetwork.java @@ -305,13 +305,16 @@ public static OneResponse chmod(Client client, int id, int octet) * @param client XML-RPC Client. * @param id The vnet id of the target vnet we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vnet id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -647,19 +650,22 @@ public OneResponse chmod(int octet) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the VirtualNetwork template contents. * * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vnet id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/vntemplate/VirtualNetworkTemplate.java b/src/oca/java/src/org/opennebula/client/vntemplate/VirtualNetworkTemplate.java index 2c71327306d..bbca7fc308f 100644 --- a/src/oca/java/src/org/opennebula/client/vntemplate/VirtualNetworkTemplate.java +++ b/src/oca/java/src/org/opennebula/client/vntemplate/VirtualNetworkTemplate.java @@ -107,13 +107,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The vntemplate id of the target vntemplate we want to modify. * @param new_template New vntemplate contents. - * @param append True to append new attributes instead of replace the whole vntemplate + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vntemplate id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -328,19 +331,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the vntemplate contents. * * @param new_template New vntemplate contents. - * @param append True to append new attributes instead of replace the whole vntemplate + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the vntemplate id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/vrouter/VirtualRouter.java b/src/oca/java/src/org/opennebula/client/vrouter/VirtualRouter.java index dc10a4203f0..c58c05f5879 100644 --- a/src/oca/java/src/org/opennebula/client/vrouter/VirtualRouter.java +++ b/src/oca/java/src/org/opennebula/client/vrouter/VirtualRouter.java @@ -129,13 +129,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The id of the target VirtualRouter we want to modify. * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the VirtualRouter id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -321,19 +324,22 @@ public OneResponse delete() */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents. - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the VirtualRouter id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } /** diff --git a/src/oca/java/src/org/opennebula/client/zone/Zone.java b/src/oca/java/src/org/opennebula/client/zone/Zone.java index 20ad079e492..236d5dfabab 100644 --- a/src/oca/java/src/org/opennebula/client/zone/Zone.java +++ b/src/oca/java/src/org/opennebula/client/zone/Zone.java @@ -102,13 +102,16 @@ public static OneResponse delete(Client client, int id) * @param client XML-RPC Client. * @param id The zone id of the target zone we want to modify. * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the zone id. */ public static OneResponse update(Client client, int id, String new_template, - boolean append) + int type) { - return client.call(UPDATE, id, new_template, append ? 1 : 0); + return client.call(UPDATE, id, new_template, type); } /** @@ -170,18 +173,21 @@ public OneResponse rename(String name) */ public OneResponse update(String new_template) { - return update(new_template, false); + return update(new_template, 0); } /** * Replaces the template contents. * * @param new_template New template contents - * @param append True to append new attributes instead of replace the whole template + * @param type Update type + * - 0: Replace the whole template + * - 1: Append the new attributes to the template + * - 2: Delete the attributes from the template * @return If successful the message contains the zone id. */ - public OneResponse update(String new_template, boolean append) + public OneResponse update(String new_template, int type) { - return update(client, id, new_template, append); + return update(client, id, new_template, type); } } diff --git a/src/oca/ruby/opennebula/cluster.rb b/src/oca/ruby/opennebula/cluster.rb index 1e3e5b019e7..608e12cd686 100644 --- a/src/oca/ruby/opennebula/cluster.rb +++ b/src/oca/ruby/opennebula/cluster.rb @@ -163,13 +163,15 @@ def delvnet(vnet_id) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(CLUSTER_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(CLUSTER_METHODS[:update], new_template, type) end # Renames this Cluster diff --git a/src/oca/ruby/opennebula/datastore.rb b/src/oca/ruby/opennebula/datastore.rb index 7670b5a6d5b..4e4093fc9c2 100644 --- a/src/oca/ruby/opennebula/datastore.rb +++ b/src/oca/ruby/opennebula/datastore.rb @@ -101,13 +101,15 @@ def delete() # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(DATASTORE_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(DATASTORE_METHODS[:update], new_template, type) end # Changes the owner/group diff --git a/src/oca/ruby/opennebula/group.rb b/src/oca/ruby/opennebula/group.rb index dac844b6624..4dc7924c093 100644 --- a/src/oca/ruby/opennebula/group.rb +++ b/src/oca/ruby/opennebula/group.rb @@ -193,7 +193,7 @@ def create(group_hash) end if do_update - rc = update(update_str, true) + rc = update(update_str, 1) if OpenNebula.is_error?(rc) delete @@ -215,13 +215,15 @@ def allocate(groupname) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template=nil, append=false) - super(GROUP_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template=nil, type = 0) + super(GROUP_METHODS[:update], new_template, type) end # Deletes the Group diff --git a/src/oca/ruby/opennebula/host.rb b/src/oca/ruby/opennebula/host.rb index fb63e0dd47e..546a8055a64 100644 --- a/src/oca/ruby/opennebula/host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -155,13 +155,15 @@ def flush(action) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(HOST_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(HOST_METHODS[:update], new_template, type) end # Retrieves this Host's monitoring data from OpenNebula diff --git a/src/oca/ruby/opennebula/image.rb b/src/oca/ruby/opennebula/image.rb index e3319e95fe3..5e7e6f1cd3f 100644 --- a/src/oca/ruby/opennebula/image.rb +++ b/src/oca/ruby/opennebula/image.rb @@ -122,13 +122,15 @@ def allocate(description, ds_id, check_capacity=true) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template=nil, append=false) - super(IMAGE_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template=nil, type = 0) + super(IMAGE_METHODS[:update], new_template, type) end # Enables an Image diff --git a/src/oca/ruby/opennebula/marketplace.rb b/src/oca/ruby/opennebula/marketplace.rb index 03e9609eb29..38b99542948 100644 --- a/src/oca/ruby/opennebula/marketplace.rb +++ b/src/oca/ruby/opennebula/marketplace.rb @@ -83,13 +83,15 @@ def delete() # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(MARKETPLACE_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(MARKETPLACE_METHODS[:update], new_template, type) end # Changes the owner/group diff --git a/src/oca/ruby/opennebula/marketplaceapp.rb b/src/oca/ruby/opennebula/marketplaceapp.rb index 2c88ffbf743..33a85599ae3 100644 --- a/src/oca/ruby/opennebula/marketplaceapp.rb +++ b/src/oca/ruby/opennebula/marketplaceapp.rb @@ -108,13 +108,15 @@ def delete # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append = false) - super(MARKETPLACEAPP_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(MARKETPLACEAPP_METHODS[:update], new_template, type) end # Changes the owner/group diff --git a/src/oca/ruby/opennebula/security_group.rb b/src/oca/ruby/opennebula/security_group.rb index fbb758bc3fb..8f5ecfa72df 100644 --- a/src/oca/ruby/opennebula/security_group.rb +++ b/src/oca/ruby/opennebula/security_group.rb @@ -85,13 +85,15 @@ def delete() # Replaces the securitygroup contents # # @param new_securitygroup [String] New securitygroup contents - # @param append [true, false] True to append new attributes instead of - # replace the whole securitygroup + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_securitygroup, append=false) - super(SECGROUP_METHODS[:update], new_securitygroup, append ? 1 : 0) + def update(new_securitygroup, type = 0) + super(SECGROUP_METHODS[:update], new_securitygroup, type) end # Changes the owner/group diff --git a/src/oca/ruby/opennebula/template.rb b/src/oca/ruby/opennebula/template.rb index 16457ee2ba2..c4b22271843 100644 --- a/src/oca/ruby/opennebula/template.rb +++ b/src/oca/ruby/opennebula/template.rb @@ -139,13 +139,15 @@ def instantiate(name="", hold=false, template="", persistent=false) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(TEMPLATE_METHODS[:update], new_template, type) end # Publishes the Template, to be used by other users diff --git a/src/oca/ruby/opennebula/user.rb b/src/oca/ruby/opennebula/user.rb index fa1ca5f0767..85276ce0f48 100644 --- a/src/oca/ruby/opennebula/user.rb +++ b/src/oca/ruby/opennebula/user.rb @@ -114,13 +114,15 @@ def allocate(username, password, driver=nil, gids=[]) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(USER_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(USER_METHODS[:update], new_template, type) end # Deletes the User diff --git a/src/oca/ruby/opennebula/vdc.rb b/src/oca/ruby/opennebula/vdc.rb index b3c7a1f31a7..12c5e2895a8 100644 --- a/src/oca/ruby/opennebula/vdc.rb +++ b/src/oca/ruby/opennebula/vdc.rb @@ -91,13 +91,15 @@ def allocate(description) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template=nil, append=false) - super(VDC_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template=nil, type = 0) + super(VDC_METHODS[:update], new_template, type) end # Deletes the Vdc diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 2a4a1b6245c..80a7b1f5d9e 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -299,13 +299,15 @@ def allocate(description, hold=false) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template=nil, append=false) - super(VM_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template=nil, type = 0) + super(VM_METHODS[:update], new_template, type) end # Returns the element in text form @@ -926,7 +928,7 @@ def save_as_template(name,description, persistent=nil) new_tmpl = OpenNebula::Template.new_with_id(new_tid, @client) - rc = new_tmpl.update(replace, true) + rc = new_tmpl.update(replace, 1) raise if OpenNebula.is_error?(rc) return new_tid diff --git a/src/oca/ruby/opennebula/virtual_network.rb b/src/oca/ruby/opennebula/virtual_network.rb index 197a8d975df..39f695410ee 100644 --- a/src/oca/ruby/opennebula/virtual_network.rb +++ b/src/oca/ruby/opennebula/virtual_network.rb @@ -90,13 +90,15 @@ def allocate(description,cluster_id=ClusterPool::NONE_CLUSTER_ID) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template=nil, append=false) - super(VN_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template=nil, type = 0) + super(VN_METHODS[:update], new_template, type) end # Publishes the VirtualNetwork, to be used by other users diff --git a/src/oca/ruby/opennebula/virtual_router.rb b/src/oca/ruby/opennebula/virtual_router.rb index 09a5bb835c5..cc5bd02ad40 100644 --- a/src/oca/ruby/opennebula/virtual_router.rb +++ b/src/oca/ruby/opennebula/virtual_router.rb @@ -111,13 +111,15 @@ def delete() # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(VIRTUAL_ROUTER_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(VIRTUAL_ROUTER_METHODS[:update], new_template, type) end # Changes the owner/group diff --git a/src/oca/ruby/opennebula/vm_group.rb b/src/oca/ruby/opennebula/vm_group.rb index d4b1282c233..143d994450d 100644 --- a/src/oca/ruby/opennebula/vm_group.rb +++ b/src/oca/ruby/opennebula/vm_group.rb @@ -82,13 +82,15 @@ def delete() # Replaces the vm group contents # # @param new_vmgroup [String] New vmgroup contents - # @param append [true, false] True to append new attributes instead of - # replace the whole securitygroup + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_vmgroup, append=false) - super(VMGROUP_METHODS[:update], new_vmgroup, append ? 1 : 0) + def update(new_vmgroup, type = 0) + super(VMGROUP_METHODS[:update], new_vmgroup, type) end # Changes the owner/group diff --git a/src/oca/ruby/opennebula/vntemplate.rb b/src/oca/ruby/opennebula/vntemplate.rb index a8de76b678e..7941e502095 100644 --- a/src/oca/ruby/opennebula/vntemplate.rb +++ b/src/oca/ruby/opennebula/vntemplate.rb @@ -128,13 +128,15 @@ def instantiate(name="", template="") # Replaces the vntemplate contents # # @param new_template [String] New vntemplate contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template, append=false) - super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template, type = 0) + super(TEMPLATE_METHODS[:update], new_template, type) end # Publishes the Template, to be used by other users diff --git a/src/oca/ruby/opennebula/zone.rb b/src/oca/ruby/opennebula/zone.rb index 42fcb516ff8..f8d82a40894 100644 --- a/src/oca/ruby/opennebula/zone.rb +++ b/src/oca/ruby/opennebula/zone.rb @@ -122,13 +122,15 @@ def allocate(description) # Replaces the template contents # # @param new_template [String] New template contents - # @param append [true, false] True to append new attributes instead of - # replace the whole template + # @param type [Integer] Update type + # - 0: Replace the whole template + # - 1: Append the new attributes to the template + # - 2: Delete the attributes from the template # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def update(new_template=nil, append=false) - super(ZONE_METHODS[:update], new_template, append ? 1 : 0) + def update(new_template=nil, type = 0) + super(ZONE_METHODS[:update], new_template, type) end # Deletes the Zone diff --git a/src/onegate/onegate-server.rb b/src/onegate/onegate-server.rb old mode 100644 new mode 100755 index 5f9787f1003..d6c20cd7a2c --- a/src/onegate/onegate-server.rb +++ b/src/onegate/onegate-server.rb @@ -165,7 +165,7 @@ def get_requested_vm(requested_vm_id, request_env, client) end end - # Perform the action provided in the body of the request on the + # Perform the action provided in the body of the request on the # given VM. If error trigger a halt def perform_action(vm, body) action_hash = parse_json(body, 'action') @@ -249,22 +249,19 @@ def parse_json(json_str, root_element) end # Attrs that cannot be modified when updating a VM template - def check_restricted_attrs(request) - body = request.body.read - - body.split("\n").each{ |key_value| + def check_restricted_attrs(data, error) + data.split("\n").each{ |key_value| parts = key_value.split('=') if parts[0] && get_restricted_attrs.include?(parts[0].upcase) - error_msg = "Attribute (#{parts[0]}) cannot be modified" + error_msg = "Attribute (#{parts[0]}) #{error}" logger.error {error_msg} halt 403, error_msg end } - request.body.rewind end def get_restricted_attrs - $conf[':restricted_attrs'] || RESTRICTED_ATTRS + $conf[:restricted_attrs] || RESTRICTED_ATTRS end # Actions that cannot be performed on a VM @@ -277,7 +274,7 @@ def check_restricted_actions(action) end def get_restricted_actions - $conf[':restricted_actions'] || RESTRICTED_ACTIONS + $conf[:restricted_actions] || RESTRICTED_ACTIONS end def check_permissions(resource, action) @@ -291,10 +288,10 @@ def check_permissions(resource, action) # Check if the source VM is part of a service and if the requested # VM is part of the same Service as the source VM. - # + # # If true the service hash is returned - # If false a halt is triggered - # + # If false a halt is triggered + # def check_vm_in_service(requested_vm_id, service_id, client) service = get_service(service_id, client) @@ -427,8 +424,21 @@ def build_service_hash(service_hash) source_vm = get_source_vm(request.env, client) - check_restricted_attrs(request) - rc = source_vm.update(request.body.read, true) + attr = params[:data] + type = params[:type].to_i + + type = 1 if type.nil? + + if type == 1 + error = " cannot be modified" + else + error = " cannot be deleted" + end + + check_restricted_attrs(attr, error) + + rc = source_vm.update(attr, type) + if OpenNebula.is_error?(rc) logger.error {"VMID:#{source_vm['ID']} vm.update error: #{rc.message}"} halt 500, rc.message @@ -506,8 +516,21 @@ def build_service_hash(service_hash) requested_vm = get_requested_vm(params[:id].to_i, request.env, client) - check_restricted_attrs(request) - rc = requested_vm.update(request.body.read, true) + attr = data[:data] + type = data[:type].to_i + + type = 1 if type.nil? + + if type == 1 + error = " cannot be modified" + else + error = " cannot be deleted" + end + + check_restricted_attrs(attr, error) + + rc = source_vm.update(attr, type) + if OpenNebula.is_error?(rc) logger.error {"VMID:#{params[:id]} vm.update error: #{rc.message}"} halt 500, rc.message diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index 781c522ca00..c3bf7494a7e 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -381,6 +381,45 @@ int PoolObjectSQL::append_template( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int PoolObjectSQL::delete_template( + const string& attributes, bool delete_restricted, string& error) +{ + std::vector attrs = one_util::split(attributes, ','); + vector::const_iterator it; + std::string attr; + + /* ---------------------------------------------------------------------- */ + /* Delete attributes from the current user_template */ + /* ---------------------------------------------------------------------- */ + + if (obj_template != 0) + { + for (it = attrs.begin(); it != attrs.end(); it++) + { + attr = *it; + + if (!delete_restricted && obj_template->is_restricted(attr)) + { + error = "Restricted attribute " + attr + " can't be deleted"; + return -1; + } + + int rc = obj_template->erase(*it); + + if (rc == 0) + { + error = "Attribute " + attr + " not found"; + return -1; + } + } + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + string& PoolObjectSQL::perms_to_xml(string& xml) const { ostringstream oss; diff --git a/src/rm/RequestManagerUpdateTemplate.cc b/src/rm/RequestManagerUpdateTemplate.cc index 45623a28f21..645f30ed41f 100644 --- a/src/rm/RequestManagerUpdateTemplate.cc +++ b/src/rm/RequestManagerUpdateTemplate.cc @@ -59,6 +59,25 @@ int RequestManagerUpdateTemplate::append_template( /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ +int RequestManagerUpdateTemplate::delete_template( + PoolObjectSQL * object, + const string & attributes, + const RequestAttributes &att, + string &error_str) +{ + if (!att.is_admin()) + { + return object->delete_template(attributes, false, error_str); + } + else + { + return object->delete_template(attributes, true, error_str); + } +} + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + void RequestManagerUpdateTemplate::request_execute( xmlrpc_c::paramList const& paramList, RequestAttributes& att) @@ -82,7 +101,7 @@ void RequestManagerUpdateTemplate::request_execute( return; } - if ( update_type < 0 || update_type > 1 ) + if ( update_type < 0 || update_type > 2 ) { att.resp_msg = "Wrong update type"; failure_response(XML_RPC_API, att); @@ -103,10 +122,14 @@ void RequestManagerUpdateTemplate::request_execute( { rc = replace_template(object, tmpl, att, att.resp_msg); } - else //if (update_type == 1) + else if (update_type == 1) { rc = append_template(object, tmpl, att, att.resp_msg); } + else //if (update_type == 2) + { + rc = delete_template(object, tmpl, att, att.resp_msg); + } if ( rc != 0 ) { diff --git a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb index 187392a9c1d..20cfb0ca97c 100644 --- a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb @@ -77,8 +77,8 @@ def delvnet(params=Hash.new) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb b/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb index 2df53fab5e3..ea8a671ac0a 100644 --- a/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb @@ -61,8 +61,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/GroupJSON.rb b/src/sunstone/models/OpenNebulaJSON/GroupJSON.rb index f4d65368235..57cb820b4b4 100644 --- a/src/sunstone/models/OpenNebulaJSON/GroupJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/GroupJSON.rb @@ -53,8 +53,8 @@ def chown(params=Hash.new) end def update_json(params=Hash.new) - if !params['append'].nil? - update(params['template_raw'], params['append']) + if !params['type'].nil? + update(params['template_raw'], params['type']) else update(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb index 26625f01bea..77bac61d822 100644 --- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb @@ -36,7 +36,7 @@ def create(template_json) if !template_str.nil? params=Hash.new params['template_raw'] = template_str - params['append'] = true + params['type'] = 1 self.update(params) end end @@ -70,8 +70,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb index 5ee9f7bc19f..b7e8a36e2dc 100644 --- a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb @@ -73,8 +73,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb b/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb index 8ef2ab72835..8762f91ad25 100644 --- a/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb @@ -64,8 +64,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/SecurityGroupJSON.rb b/src/sunstone/models/OpenNebulaJSON/SecurityGroupJSON.rb index fffdb053712..c8a0186e5ec 100644 --- a/src/sunstone/models/OpenNebulaJSON/SecurityGroupJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/SecurityGroupJSON.rb @@ -58,8 +58,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb index 450dcc23aa5..4b964a4e188 100644 --- a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -69,8 +69,8 @@ def info(extended=false) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/UserJSON.rb b/src/sunstone/models/OpenNebulaJSON/UserJSON.rb index b62e92b6a1d..179a7603f53 100644 --- a/src/sunstone/models/OpenNebulaJSON/UserJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/UserJSON.rb @@ -67,8 +67,8 @@ def chauth(params=Hash.new) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/VMGroupJSON.rb b/src/sunstone/models/OpenNebulaJSON/VMGroupJSON.rb index 4a59e8945f2..16237b1c5ee 100644 --- a/src/sunstone/models/OpenNebulaJSON/VMGroupJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VMGroupJSON.rb @@ -69,8 +69,8 @@ def chmod_octet(params=Hash.new) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/VdcJSON.rb b/src/sunstone/models/OpenNebulaJSON/VdcJSON.rb index 9608625b27c..81ad4cb0907 100644 --- a/src/sunstone/models/OpenNebulaJSON/VdcJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VdcJSON.rb @@ -104,8 +104,8 @@ def del_vnet(params=Hash.new) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb index 8b646029654..29de284472b 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb @@ -185,8 +185,8 @@ def nic_detach(params=Hash.new) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb index 43a115563ea..196d2a7c6be 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb @@ -69,8 +69,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkTemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkTemplateJSON.rb index 99355649b3c..4c57bdc84c0 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkTemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkTemplateJSON.rb @@ -61,8 +61,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualRouterJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualRouterJSON.rb index ca1903aa9ac..168a480c6b6 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualRouterJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualRouterJSON.rb @@ -75,8 +75,8 @@ def instantiate(params=Hash.new) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/models/OpenNebulaJSON/ZoneJSON.rb b/src/sunstone/models/OpenNebulaJSON/ZoneJSON.rb index 096c59a49eb..5ba6a8c0c80 100644 --- a/src/sunstone/models/OpenNebulaJSON/ZoneJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ZoneJSON.rb @@ -49,8 +49,8 @@ def perform_action(template_json) end def update(params=Hash.new) - if !params['append'].nil? - super(params['template_raw'], params['append']) + if !params['type'].nil? + super(params['template_raw'], params['type']) else super(params['template_raw']) end diff --git a/src/sunstone/public/app/opennebula/cluster.js b/src/sunstone/public/app/opennebula/cluster.js index 2085413e649..55f1811170c 100644 --- a/src/sunstone/public/app/opennebula/cluster.js +++ b/src/sunstone/public/app/opennebula/cluster.js @@ -65,7 +65,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/datastore.js b/src/sunstone/public/app/opennebula/datastore.js index b5cdefde0a3..9beab1094d6 100644 --- a/src/sunstone/public/app/opennebula/datastore.js +++ b/src/sunstone/public/app/opennebula/datastore.js @@ -97,7 +97,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/group.js b/src/sunstone/public/app/opennebula/group.js index 2d2c3f8bb66..7456a8d8066 100644 --- a/src/sunstone/public/app/opennebula/group.js +++ b/src/sunstone/public/app/opennebula/group.js @@ -64,7 +64,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "set_quota" : function(params) { diff --git a/src/sunstone/public/app/opennebula/host.js b/src/sunstone/public/app/opennebula/host.js index 93582c4ba0c..b09a163dd05 100644 --- a/src/sunstone/public/app/opennebula/host.js +++ b/src/sunstone/public/app/opennebula/host.js @@ -105,7 +105,7 @@ define(function(require) { _clearCache(); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); _clearCache(); }, diff --git a/src/sunstone/public/app/opennebula/image.js b/src/sunstone/public/app/opennebula/image.js index 11b4905cfd6..c45efd0c611 100644 --- a/src/sunstone/public/app/opennebula/image.js +++ b/src/sunstone/public/app/opennebula/image.js @@ -119,7 +119,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "chmod", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "update": function(params) { diff --git a/src/sunstone/public/app/opennebula/marketplace.js b/src/sunstone/public/app/opennebula/marketplace.js index 4a339e88b5e..5ad67d7c060 100644 --- a/src/sunstone/public/app/opennebula/marketplace.js +++ b/src/sunstone/public/app/opennebula/marketplace.js @@ -52,7 +52,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/marketplaceapp.js b/src/sunstone/public/app/opennebula/marketplaceapp.js index 8ae2b03d41b..87347e553c2 100644 --- a/src/sunstone/public/app/opennebula/marketplaceapp.js +++ b/src/sunstone/public/app/opennebula/marketplaceapp.js @@ -90,7 +90,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/network.js b/src/sunstone/public/app/opennebula/network.js index ae1bf269ac2..381a2f78840 100644 --- a/src/sunstone/public/app/opennebula/network.js +++ b/src/sunstone/public/app/opennebula/network.js @@ -81,7 +81,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/securitygroup.js b/src/sunstone/public/app/opennebula/securitygroup.js index cf68b6bc670..3cbce406dcd 100644 --- a/src/sunstone/public/app/opennebula/securitygroup.js +++ b/src/sunstone/public/app/opennebula/securitygroup.js @@ -49,7 +49,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "clone" : function(params) { diff --git a/src/sunstone/public/app/opennebula/servicetemplate.js b/src/sunstone/public/app/opennebula/servicetemplate.js index 7f05a399e7d..221ec69d356 100644 --- a/src/sunstone/public/app/opennebula/servicetemplate.js +++ b/src/sunstone/public/app/opennebula/servicetemplate.js @@ -67,7 +67,7 @@ define(function(require) { }, "update_labels": function(params) { params.cache_name = CACHE_NAME; - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj, PATH); }, "del": function(params) { diff --git a/src/sunstone/public/app/opennebula/template.js b/src/sunstone/public/app/opennebula/template.js index 48ff1aad6c3..94d77bd1b44 100644 --- a/src/sunstone/public/app/opennebula/template.js +++ b/src/sunstone/public/app/opennebula/template.js @@ -50,7 +50,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "chmod", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "update" : function(params) { diff --git a/src/sunstone/public/app/opennebula/user.js b/src/sunstone/public/app/opennebula/user.js index 46da82b5e6a..672aec64568 100644 --- a/src/sunstone/public/app/opennebula/user.js +++ b/src/sunstone/public/app/opennebula/user.js @@ -97,7 +97,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "accounting" : function(params) { diff --git a/src/sunstone/public/app/opennebula/vdc.js b/src/sunstone/public/app/opennebula/vdc.js index ab208035b0c..23ce415f692 100644 --- a/src/sunstone/public/app/opennebula/vdc.js +++ b/src/sunstone/public/app/opennebula/vdc.js @@ -38,7 +38,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/virtualrouter.js b/src/sunstone/public/app/opennebula/virtualrouter.js index 80dd1e28f3e..bec3e7ad3c7 100644 --- a/src/sunstone/public/app/opennebula/virtualrouter.js +++ b/src/sunstone/public/app/opennebula/virtualrouter.js @@ -53,7 +53,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/vm.js b/src/sunstone/public/app/opennebula/vm.js index 5b6b1357067..3db7856cc57 100644 --- a/src/sunstone/public/app/opennebula/vm.js +++ b/src/sunstone/public/app/opennebula/vm.js @@ -520,7 +520,7 @@ define(function(require) { }); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "update": function(params) { diff --git a/src/sunstone/public/app/opennebula/vntemplate.js b/src/sunstone/public/app/opennebula/vntemplate.js index 58bc3fb5fa0..2c52c0a201c 100644 --- a/src/sunstone/public/app/opennebula/vntemplate.js +++ b/src/sunstone/public/app/opennebula/vntemplate.js @@ -65,7 +65,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/sunstone/public/app/opennebula/zone.js b/src/sunstone/public/app/opennebula/zone.js index b13ff26d81f..c94f75823fa 100644 --- a/src/sunstone/public/app/opennebula/zone.js +++ b/src/sunstone/public/app/opennebula/zone.js @@ -38,7 +38,7 @@ define(function(require) { OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "append": function(params) { - var action_obj = {"template_raw" : params.data.extra_param, append : true}; + var action_obj = {"template_raw" : params.data.extra_param, type : 1}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj); }, "rename" : function(params) { diff --git a/src/template/Template.cc b/src/template/Template.cc index b14995a8173..97708bb6813 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -889,3 +889,49 @@ bool Template::check_restricted(string& ra, return false; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +bool Template::is_restricted(const string& attr, + const std::map >& ras) +{ + std::map >::const_iterator rit; + + for ( rit = ras.begin(); rit != ras.end(); ++rit ) + { + const std::set& sub = rit->second; + + if (!sub.empty()) //Vector Attribute + { + // ----------------------------------------------------------------- + // ----------------------------------------------------------------- + std::set::iterator jt; + std::vector::iterator va_it; + + std::vector va; + + get(rit->first, va); + + for ( va_it = va.begin(); va_it != va.end() ; ++va_it ) + { + for ( jt = sub.begin(); jt != sub.end(); ++jt ) + { + if (*jt == attr) + { + return true; + } + } + } + } + else + { + if (rit->first == attr) + { + return true; + } + } + } + + return false; +} diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 8e8ffa8f11f..af326c888df 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1172,7 +1172,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) /** * @return -1 for incompatible datastore IDs, -2 for missing datastore IDs */ -static int check_and_set_datastores_id(const set &csystem_ds, +static int check_and_set_datastores_id(const set &csystem_ds, set &ds_ids) { if ( csystem_ds.empty() ) @@ -1498,7 +1498,7 @@ static int get_cluster_requirements(Template *tmpl, set& cluster_ids, * @param error_str Returns the error reason, if any * @return 0 on success */ -static int get_datastore_requirements(Template *tmpl, set& ds_ids, +static int get_datastore_requirements(Template *tmpl, set& ds_ids, string& error_str) { ostringstream oss; @@ -2779,6 +2779,46 @@ int VirtualMachine::append_template( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachine::delete_template( + const string& attributes, + bool delete_restricted, + string& error) +{ + std::vector attrs = one_util::split(attributes, ','); + vector::const_iterator it; + std::string attr; + + /* ---------------------------------------------------------------------- */ + /* Delete attributes from the current user_template */ + /* ---------------------------------------------------------------------- */ + if (user_obj_template != 0) + { + for (it = attrs.begin(); it != attrs.end(); it++) + { + attr = *it; + + if (!delete_restricted && user_obj_template->is_restricted(attr)) + { + error = "Restricted attribute " + attr + " can't be deleted"; + return -1; + } + + int rc = user_obj_template->erase(*it); + + if (rc == 0) + { + error = "Attribute " + attr + " not found"; + return -1; + } + } + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachine::set_template_error_message(const string& message) { set_template_error_message("ERROR", message); @@ -3178,7 +3218,7 @@ int VirtualMachine::get_disk_images(string& error_str) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachine::release_disk_images(vector