28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/morpheus/cli/login.rb', line 28
def login(args)
options = {}
username, password = nil, nil
optparse = OptionParser.new do|opts|
opts.banner = usage
opts.on( '-u', '--username USERNAME', "Username" ) do |val|
username = val
end
opts.on( '-p', '--password PASSWORD', "Password" ) do |val|
password = val
end
build_common_options(opts, options, [:json, :remote, :quiet])
end
optparse.parse!(args)
if options[:remote]
appliance = Morpheus::Cli::Remote.appliances[options[:remote].to_sym]
if appliance
@appliance_name, @appliance_url = options[:remote].to_sym, appliance[:host]
else
@appliance_name, @appliance_url = nil, nil
end
else
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
end
begin
if !@appliance_name
print yellow,"Please specify a remote appliance with -r or see the command `remote use`#{reset}\n"
return false
end
if options[:quiet]
if username.empty? || password.empty?
print yellow,"You have not specified username and password\n"
return false
end
end
options[:remote_username] = username if username
options[:remote_password] = password if password
Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).login(options)
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|