From 6871d64c81ac83b3698b3169845ce3827aaadf00 Mon Sep 17 00:00:00 2001 From: joseangelgm Date: Mon, 20 Aug 2018 16:28:01 +0200 Subject: [PATCH] F #2190 Onezone set should allow temporary zone changes (cherry picked from commit 2867773f4ef25b3d9cd0ff41859d25c095e2e0d7) --- src/cli/one_helper/onezone_helper.rb | 35 +++++++++++++++------------- src/cli/onezone | 16 +++++++++++-- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/cli/one_helper/onezone_helper.rb b/src/cli/one_helper/onezone_helper.rb index 9dcd1507f3..5126b16b51 100644 --- a/src/cli/one_helper/onezone_helper.rb +++ b/src/cli/one_helper/onezone_helper.rb @@ -83,25 +83,28 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper table end - def set_zone(zone_id) - zone = factory(zone_id) - rc = zone.info + def set_zone(zone_id, temporary_zone) + zone = factory(zone_id) + rc = zone.info - if OpenNebula.is_error?(rc) - return -1, rc.message - end + if OpenNebula.is_error?(rc) + return -1, rc.message + end - if !zone['TEMPLATE/ENDPOINT'] - return -1, "No Endpoint defined for Zone #{zone_id}" - end + if !zone['TEMPLATE/ENDPOINT'] + return -1, "No Endpoint defined for Zone #{zone_id}" + end - File.open(ENV['HOME']+"/.one/one_endpoint", 'w'){|f| - f.puts zone['TEMPLATE/ENDPOINT'] - } - - puts "Endpoint changed to \"#{zone['TEMPLATE/ENDPOINT']}\" in " << - "#{ENV['HOME']}/.one/one_endpoint" - return 0 + if temporary_zone + puts "Type: export ONE_XMLRPC=#{zone['TEMPLATE/ENDPOINT']}" + else + File.open(ENV['HOME']+"/.one/one_endpoint", 'w'){|f| + f.puts zone['TEMPLATE/ENDPOINT'] + } + puts "Endpoint changed to \"#{zone['TEMPLATE/ENDPOINT']}\" in " << + "#{ENV['HOME']}/.one/one_endpoint" + end + return 0 end private diff --git a/src/cli/onezone b/src/cli/onezone index 997e3fd0d9..693a417644 100755 --- a/src/cli/onezone +++ b/src/cli/onezone @@ -36,6 +36,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper = OneZoneHelper.new + ENDPOINT = { + :name => "keep", + :short => "-k", + :large => "--keep", + :description => "Not overwrite endpoint file located in home folder, just a temporary zone.", + :format => String + } + before_proc do helper.set_client(options) end @@ -191,7 +199,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do Set shell session access point for the CLI to the given Zone EOT - command :set, set_desc,:zoneid do - helper.set_zone(args[0]) + command :set, set_desc,:zoneid, :options=>ENDPOINT do + if options.has_key? :keep + helper.set_zone(args[0], true) + else + helper.set_zone(args[0], false) + end end end