Class: VpsAdmin::CLI::Commands::VpsRemoteControl

Inherits:
HaveAPI::CLI::Command
  • Object
show all
Defined in:
lib/vpsadmin/cli/commands/vps_remote_console.rb

Defined Under Namespace

Classes: HttpClient, InputHandler

Instance Method Summary collapse

Instance Method Details

#exec(args) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/vpsadmin/cli/commands/vps_remote_console.rb', line 217

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 server 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

  puts
  puts 'Connecting to the remote console...'
  puts 'Press ENTER ESC . to exit'
  puts

  raw_mode do
    run_console(vps, t.token)
  end
end

#options(opts) ⇒ Object



207
208
209
210
211
212
213
214
215
# File 'lib/vpsadmin/cli/commands/vps_remote_console.rb', line 207

def options(opts)
  @opts = {
    rate: 0.05
  }

  opts.on('--refresh-rate MSEC', 'How often send and receive data, defaults to 50 ms') do |r|
    @opts[:rate] = r.to_i / 1000.0
  end
end