77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/vpsadmin/cli/commands/vps_remote_console.rb', line 77
def exec(args)
if args.empty?
puts "provide VPS ID as an argument"
exit(false)
end
vps_id = args.first.to_i
write "Locating VPS.."
begin
vps = @api.vps.show(vps_id, meta: { includes: 'node__location' })
rescue HaveAPI::Client::ActionFailed => e
puts " error"
puts e.message
exit(false)
end
puts " VPS is on #{vps.node.domain_name}, located in #{vps.node.location.label}."
puts "Console router URL is #{vps.node.location.remote_console_server}"
write "Obtaining authentication token..."
begin
t = vps.console_token.create
rescue HaveAPI::Client::ActionFailed => e
puts " error"
puts e.message
exit(false)
end
@token = t.token
puts
puts "Connecting to remote console..."
puts "Press ENTER ESC . to exit"
puts
raw_mode do
EventMachine.run do
@input = EventMachine.open_keyboard(InputHandler)
@http = EventMachine::HttpRequest.new(
"#{vps.node.location.remote_console_server}/console/feed/#{vps_id}"
)
communicate
end
end
end
|