diff --git a/src/cli/one_helper/onezone_helper.rb b/src/cli/one_helper/onezone_helper.rb index 9ec9af8623..d13f3f5cfb 100644 --- a/src/cli/one_helper/onezone_helper.rb +++ b/src/cli/one_helper/onezone_helper.rb @@ -577,7 +577,23 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper puts "Endpoint changed to \"#{zone['TEMPLATE/ENDPOINT']}\" in " << "#{ENV['HOME']}/.one/one_endpoint" end - return 0 + + return unless zone['TEMPLATE/ONEFLOW_ENDPOINT'] + + # Set ONEFLOW_ENDPOINT + if temporary_zone + puts "Type: export ONEFLOW_URL=#{zone['TEMPLATE/ONEFLOW_ENDPOINT']}" + else + File.open(ENV['HOME'] + '/.one/oneflow_endpoint', 'w') do |f| + f.puts zone['TEMPLATE/ONEFLOW_ENDPOINT'] + end + + puts 'OneFlow Endpoint changed to ' \ + "\"#{zone['TEMPLATE/ONEFLOW_ENDPOINT']}\" in " << + "#{ENV['HOME']}/.one/oneflow_endpoint" + end + + 0 end private diff --git a/src/oca/ruby/opennebula/oneflow_client.rb b/src/oca/ruby/opennebula/oneflow_client.rb index 01224d33c7..df490b3d82 100644 --- a/src/oca/ruby/opennebula/oneflow_client.rb +++ b/src/oca/ruby/opennebula/oneflow_client.rb @@ -319,10 +319,21 @@ module Service class Client def initialize(opts={}) + endpoint = '/.one/oneflow_endpoint' @username = opts[:username] || ENV['ONEFLOW_USER'] @password = opts[:password] || ENV['ONEFLOW_PASSWORD'] - url = opts[:url] || ENV['ONEFLOW_URL'] || 'http://localhost:2474' + if opts[:url] + url = opts[:url] + elsif ENV['ONEFLOW_URL'] + url = ENV['ONEFLOW_URL'] + elsif ENV['HOME'] && File.exists?(ENV['HOME'] + endpoint) + url = File.read(ENV['HOME'] + endpoint).strip + elsif File.exists?('/var/lib/one/.one/oneflow_endpoint') + url = File.read('/var/lib/one/.one/oneflow_endpoint').strip + else + url = 'http://localhost:2474' + end if @username.nil? && @password.nil? if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"])