From 57ee51b07718e84f10bf7d2ec404504f7fe784e5 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 6 Feb 2014 19:01:46 +0100 Subject: [PATCH] Feature #2692: Add setzone option to onezone --- src/cli/etc/onezone.yaml | 11 ++++++++++- src/cli/one_helper/onezone_helper.rb | 26 ++++++++++++++++++++++++++ src/cli/onezone | 8 ++++++++ src/oca/ruby/opennebula/client.rb | 3 +++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/cli/etc/onezone.yaml b/src/cli/etc/onezone.yaml index 5124d39610..3a96c18cdf 100644 --- a/src/cli/etc/onezone.yaml +++ b/src/cli/etc/onezone.yaml @@ -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 \ No newline at end of file +- :NAME +- :ENDPOINT \ No newline at end of file diff --git a/src/cli/one_helper/onezone_helper.rb b/src/cli/one_helper/onezone_helper.rb index 4dbd29d5c9..f854201794 100644 --- a/src/cli/one_helper/onezone_helper.rb +++ b/src/cli/one_helper/onezone_helper.rb @@ -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) diff --git a/src/cli/onezone b/src/cli/onezone index f8d9723b70..2b196d0cb7 100755 --- a/src/cli/onezone +++ b/src/cli/onezone @@ -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 diff --git a/src/oca/ruby/opennebula/client.rb b/src/oca/ruby/opennebula/client.rb index 16a9ca8bbb..72e19c0274 100644 --- a/src/oca/ruby/opennebula/client.rb +++ b/src/oca/ruby/opennebula/client.rb @@ -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