-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathonevnc
executable file
·72 lines (54 loc) · 1.26 KB
/
onevnc
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
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
#!/usr/bin/env ruby
require 'getoptlong'
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
require 'opennebula'
include OpenNebula
CLIENT = Client.new
def get_id(name)
pool = VirtualMachinePool.new(CLIENT, -1)
rc = pool.info
if OpenNebula.is_error?(rc)
STDERR.puts rc.message
exit 1
end
pool.each do |vm|
if vm['NAME'] == name
return vm['ID']
end
end
return nil
end
id = ARGV.shift
if !id.match(/^\d+$/)
vm_id = get_id(id)
if vm_id.nil?
STDERR.puts "VM '#{id}' not found"
exit 1
else
id = vm_id
end
end
vm = VirtualMachine.new_with_id(id, CLIENT)
rc = vm.info
if OpenNebula.is_error?(rc)
STDERR.puts rc.message
exit 1
end
host = vm['HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']
port = vm['TEMPLATE/GRAPHICS/PORT']
vncviewer = ARGV.shift || 'vinagre'
cmd = [vncviewer, "#{host}::#{port}"]
puts cmd.join(" ")
exec(*cmd)