1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

feature #1234: Add to the update commands the option to take a file as input

This commit is contained in:
Daniel Molina 2012-04-20 11:44:09 +03:00
parent 2a8b04a32b
commit 0d76bed9bf
7 changed files with 51 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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