-
Notifications
You must be signed in to change notification settings - Fork 10
/
oneuser-sshkey
executable file
·45 lines (36 loc) · 1.01 KB
/
oneuser-sshkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
VAR_LOCATION = "/var/lib/one"
LIB_LOCATION = "/usr/lib/one"
ETC_LOCATION = "/etc/one"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
VAR_LOCATION = ONE_LOCATION+"/var"
LIB_LOCATION = ONE_LOCATION+"/lib"
ETC_LOCATION = ONE_LOCATION + "/etc"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cloud"
$: << RUBY_LIB_LOCATION+"/cli"
################################################
# Required libraries
################################################
require 'opennebula'
include OpenNebula
require 'pp'
client = Client.new
file = ARGV[0] || "#{ENV['HOME']}/.ssh/id_rsa.pub"
ssh_public_key = File.read(file).strip
user = User.new_with_id(OpenNebula::User::SELF, client)
rc = user.info
if OpenNebula.is_error?(rc)
STDERR.puts rc.message
exit 1
end
rc = user.update(%Q{SSH_PUBLIC_KEY="#{ssh_public_key}"}, false)
if OpenNebula.is_error?(rc)
STDERR.puts rc.message
exit 1
end