From 496166d2da0af893e2be07683636e3a5225b0b14 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Fri, 18 Feb 2022 13:18:55 +0100 Subject: [PATCH] B #5396: set ONEFLOW_ENDPOINT with onezone (#1790) (cherry picked from commit 10fd18d19c8d30692e247ae616a9c239dfa4dc34) --- src/cli/one_helper/onezone_helper.rb | 18 +++++++++++++++++- src/oca/ruby/opennebula/oneflow_client.rb | 13 ++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) 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"])