mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Merge branch 'bug-2723'
This commit is contained in:
commit
e8d556caed
@ -100,19 +100,31 @@ EOT
|
||||
:name => 'user',
|
||||
:large => '--user name',
|
||||
:description => 'User name used to connect to OpenNebula',
|
||||
:format => String
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
OneHelper.set_user(o)
|
||||
[0, o]
|
||||
end
|
||||
},
|
||||
{
|
||||
:name => 'password',
|
||||
:large => '--password password',
|
||||
:description => 'Password to authenticate with OpenNebula',
|
||||
:format => String
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
OneHelper.set_password(o)
|
||||
[0, o]
|
||||
end
|
||||
},
|
||||
{
|
||||
:name => 'endpoint',
|
||||
:large => '--endpoint endpoint',
|
||||
:description => 'URL of OpenNebula xmlrpc frontend',
|
||||
:format => String
|
||||
:format => String,
|
||||
:proc => lambda do |o, options|
|
||||
OneHelper.set_endpoint(o)
|
||||
[0, o]
|
||||
end
|
||||
}
|
||||
]
|
||||
|
||||
@ -340,18 +352,31 @@ EOT
|
||||
class OneHelper
|
||||
attr_accessor :client
|
||||
|
||||
def self.get_client(options)
|
||||
if defined?(@@client)
|
||||
def self.get_client(options={}, force=false)
|
||||
if !force && defined?(@@client)
|
||||
@@client
|
||||
else
|
||||
|
||||
secret=nil
|
||||
user=options[:user]
|
||||
password=nil
|
||||
|
||||
if defined?(@@user)
|
||||
user=@@user
|
||||
password=@@password if defined?(@@password)
|
||||
else
|
||||
user=options[:user]
|
||||
end
|
||||
|
||||
if user
|
||||
password=options[:password]||self.get_password
|
||||
password=password||options[:password]||self.get_password
|
||||
secret="#{user}:#{password}"
|
||||
end
|
||||
|
||||
endpoint=options[:endpoint]
|
||||
if defined?(@@endpoint)
|
||||
endpoint=@@endpoint
|
||||
else
|
||||
endpoint=options[:endpoint]
|
||||
end
|
||||
|
||||
@@client=OpenNebula::Client.new(secret, endpoint)
|
||||
end
|
||||
@ -361,10 +386,22 @@ EOT
|
||||
if defined?(@@client)
|
||||
@@client
|
||||
else
|
||||
self.get_client({})
|
||||
self.get_client
|
||||
end
|
||||
end
|
||||
|
||||
def self.set_user(user)
|
||||
@@user=user
|
||||
end
|
||||
|
||||
def self.set_password(password)
|
||||
@@password=password
|
||||
end
|
||||
|
||||
def self.set_endpoint(endpoint)
|
||||
@@endpoint=endpoint
|
||||
end
|
||||
|
||||
if RUBY_VERSION>="1.9.3"
|
||||
require 'io/console'
|
||||
def self.get_password
|
||||
@ -374,6 +411,7 @@ EOT
|
||||
puts
|
||||
|
||||
pass.chop! if pass
|
||||
@@password=pass
|
||||
pass
|
||||
end
|
||||
else
|
||||
@ -381,8 +419,9 @@ EOT
|
||||
def self.get_password
|
||||
print "Password: "
|
||||
system("stty", "-echo")
|
||||
@@password=gets.chop
|
||||
begin
|
||||
return gets.chop
|
||||
return @@password
|
||||
ensure
|
||||
system("stty", "echo")
|
||||
print "\n"
|
||||
@ -397,7 +436,7 @@ EOT
|
||||
end
|
||||
|
||||
def set_client(options)
|
||||
@client=OpenNebulaHelper::OneHelper.get_client(options)
|
||||
@client=OpenNebulaHelper::OneHelper.get_client(options, true)
|
||||
end
|
||||
|
||||
def create_resource(options, &block)
|
||||
|
Loading…
x
Reference in New Issue
Block a user