mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
Feature #2692: Add setzone option to onezone
This commit is contained in:
1 parent
cd3e690f91
commit
57ee51b077
4 files changed
+47
-1
No files matched your search
@@ -1,4 +1,7 @@
|
||||
---
|
||||
:CURRENT:
|
||||
:desc: Active Zone
|
||||
:size: 1
|
||||
:ID:
|
||||
:desc: ONE identifier for the Zone
|
||||
:size: 5
|
||||
@@ -8,6 +11,12 @@
|
||||
:size: 25
|
||||
:left: true
|
||||
|
||||
:ENDPOINT:
|
||||
:desc: Endpoint of the Zone
|
||||
:size: 45
|
||||
|
||||
:default:
|
||||
- :CURRENT
|
||||
- :ID
|
||||
- :NAME
|
||||
- :NAME
|
||||
- :ENDPOINT
|
||||
@@ -30,6 +30,11 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :CURRENT, "Active Zone", :size=>1 do |d|
|
||||
"*" if helper.client.one_endpoint.strip ==
|
||||
d["TEMPLATE"]['ENDPOINT'].strip
|
||||
end
|
||||
|
||||
column :ID, "ONE identifier for the Zone", :size=>5 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
@@ -48,6 +53,27 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
|
||||
table
|
||||
end
|
||||
|
||||
def set_zone(zone_id)
|
||||
zone = factory(zone_id)
|
||||
rc = zone.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return -1, rc.message
|
||||
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
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
|
||||
@@ -134,4 +134,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
command :show, show_desc,:zoneid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
end
|
||||
|
||||
setzone_desc = <<-EOT.unindent
|
||||
Set shell session access point for the CLI to the given Zone
|
||||
EOT
|
||||
|
||||
command :setzone, setzone_desc,:zoneid do
|
||||
helper.set_zone(args[0])
|
||||
end
|
||||
end
|
||||
@@ -81,6 +81,7 @@ module OpenNebula
|
||||
# xml-rpc calls.
|
||||
class Client
|
||||
attr_accessor :one_auth
|
||||
attr_reader :one_endpoint
|
||||
|
||||
begin
|
||||
require 'xmlparser'
|
||||
@@ -120,6 +121,8 @@ module OpenNebula
|
||||
@one_endpoint = endpoint
|
||||
elsif ENV["ONE_XMLRPC"]
|
||||
@one_endpoint = ENV["ONE_XMLRPC"]
|
||||
elsif File.exists?(ENV['HOME']+"/.one/one_endpoint")
|
||||
@one_endpoint = File.read(ENV['HOME']+"/.one/one_endpoint")
|
||||
else
|
||||
@one_endpoint = "http://localhost:2633/RPC2"
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user