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

F #2190 Onezone set should allow temporary zone changes

(cherry picked from commit 2867773f4ef25b3d9cd0ff41859d25c095e2e0d7)
This commit is contained in:
joseangelgm 2018-08-20 16:28:01 +02:00 committed by Tino Vazquez
parent f7f14f304c
commit 6871d64c81
2 changed files with 33 additions and 18 deletions

View File

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

View File

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