diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 0dc3f92b06..fcc5f8908d 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -411,32 +411,34 @@ EOT end end - def OpenNebulaHelper.update_template(id, resource) - require 'tempfile' + def OpenNebulaHelper.update_template(id, resource, path=nil) + unless path + require 'tempfile' - tmp = Tempfile.new(id.to_s) - path = tmp.path + tmp = Tempfile.new(id.to_s) + path = tmp.path - rc = resource.info + rc = resource.info - if OpenNebula.is_error?(rc) - puts rc.message - exit -1 + if OpenNebula.is_error?(rc) + puts rc.message + exit -1 + end + + tmp << resource.template_str + tmp.flush + + editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH + system("#{editor_path} #{path}") + + unless $?.exitstatus == 0 + puts "Editor not defined" + exit -1 + end + + tmp.close end - tmp << resource.template_str - tmp.flush - - editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH - system("#{editor_path} #{path}") - - unless $?.exitstatus == 0 - puts "Editor not defined" - exit -1 - end - - tmp.close - str = File.read(path) str end diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 02dbab9189..a4f9e0cc22 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -151,12 +151,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do end update_desc = <<-EOT.unindent - Launches the system editor to modify and update the template contents + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. EOT - command :update, update_desc, :datastoreid do + command :update, update_desc, :datastoreid, [:file, nil] do helper.perform_action(args[0],options,"modified") do |obj| - str = OpenNebulaHelper.update_template(args[0], obj) + str = OpenNebulaHelper.update_template(args[0], obj, args[1]) obj.update(str) end end diff --git a/src/cli/onehost b/src/cli/onehost index 3b7d89fa63..946fa2c311 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -139,12 +139,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do end update_desc = <<-EOT.unindent - Launches the system editor to modify and update the template contents + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. EOT - command :update, update_desc, :hostid do + command :update, update_desc, :hostid, [:file, nil] do helper.perform_action(args[0],options,"updated") do |host| - str = OpenNebulaHelper.update_template(args[0], host) + str = OpenNebulaHelper.update_template(args[0], host, args[1]) host.update(str) end end diff --git a/src/cli/oneimage b/src/cli/oneimage index fca548c8ce..e461ae1371 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -151,21 +151,22 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end - enable_desc = <<-EOT.unindent - Enables the given Image - EOT - update_desc = <<-EOT.unindent - Launches the system editor to modify and update the template contents + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. EOT - command :update, update_desc, :imageid do + command :update, update_desc, :imageid, [:file, nil] do helper.perform_action(args[0],options,"modified") do |image| - str = OpenNebulaHelper.update_template(args[0], image) + str = OpenNebulaHelper.update_template(args[0], image, args[1]) image.update(str) end end + enable_desc = <<-EOT.unindent + Enables the given Image + EOT + command :enable, enable_desc, [:range,:imageid_list] do helper.perform_actions(args[0],options,"enabled") do |image| image.enable diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 163bb2ba8a..47a53b601d 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -197,12 +197,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do end update_desc = <<-EOT.unindent - Launches the system editor to modify and update the template contents + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. EOT - command :update, update_desc, :templateid do + command :update, update_desc, :templateid, [:file, nil] do helper.perform_action(args[0],options,"modified") do |template| - str = OpenNebulaHelper.update_template(args[0], template) + str = OpenNebulaHelper.update_template(args[0], template, args[1]) template.update(str) end end diff --git a/src/cli/oneuser b/src/cli/oneuser index f8f1cb52ac..d61514d17f 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -181,14 +181,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do end update_desc = <<-EOT.unindent - Launches the system editor to modify and update the template contents + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. EOT - command :update, update_desc, :userid do + command :update, update_desc, :userid, [:file, nil] do helper = OneUserHelper.new helper.perform_action(args[0],options,"modified") do |user| - str = OpenNebulaHelper.update_template(args[0], user) + str = OpenNebulaHelper.update_template(args[0], user, args[1]) user.update(str) end end diff --git a/src/cli/onevnet b/src/cli/onevnet index 2c82e5b1fe..50b4adb321 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -213,12 +213,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do end update_desc = <<-EOT.unindent - Launches the system editor to modify and update the template contents + Update the template contents. If a path is not provided the editor will + be launched to modify the current content. EOT - command :update, update_desc, :vnetid do + command :update, update_desc, :vnetid, [:file, nil] do helper.perform_action(args[0],options,"modified") do |vnet| - str = OpenNebulaHelper.update_template(args[0], vnet) + str = OpenNebulaHelper.update_template(args[0], vnet, args[1]) vnet.update(str) end end