|
8 | 8 | require 'vmfloaty/version'
|
9 | 9 | require 'vmfloaty/conf'
|
10 | 10 | require 'vmfloaty/utils'
|
| 11 | +require 'vmfloaty/ssh' |
11 | 12 |
|
12 | 13 | class Vmfloaty
|
13 | 14 | include Commander::Methods
|
@@ -50,6 +51,9 @@ def run
|
50 | 51 | else
|
51 | 52 | unless token
|
52 | 53 | puts "No token found. Retrieving a token..."
|
| 54 | + if !user |
| 55 | + raise "You did not provide a user to authenticate to vmpooler with" |
| 56 | + end |
53 | 57 | pass = password "Enter your password please:", '*'
|
54 | 58 | token = Auth.get_token(verbose, url, user, pass)
|
55 | 59 | puts "\nToken retrieved!"
|
@@ -345,6 +349,46 @@ def run
|
345 | 349 | end
|
346 | 350 | end
|
347 | 351 |
|
| 352 | + command :ssh do |c| |
| 353 | + c.syntax = 'floaty ssh os_type' |
| 354 | + c.summary = 'Grabs a single vm and sshs into it' |
| 355 | + c.description = '' |
| 356 | + c.example 'SSHs into a centos vm', 'floaty ssh centos7 --url https://vmpooler.example.com' |
| 357 | + c.option '--verbose', 'Enables verbose output' |
| 358 | + c.option '--url STRING', String, 'URL of vmpooler' |
| 359 | + c.option '--user STRING', String, 'User to authenticate with' |
| 360 | + c.option '--token STRING', String, 'Token for vmpooler' |
| 361 | + c.option '--notoken', 'Makes a request without a token' |
| 362 | + c.action do |args, options| |
| 363 | + verbose = options.verbose || config['verbose'] |
| 364 | + url = options.url ||= config['url'] |
| 365 | + token = options.token ||= config['token'] |
| 366 | + user = options.user ||= config['user'] |
| 367 | + no_token = options.notoken |
| 368 | + |
| 369 | + if args.empty? |
| 370 | + STDERR.puts "No operating systems provided to obtain. See `floaty ssh --help` for more information on how to get VMs." |
| 371 | + exit 1 |
| 372 | + end |
| 373 | + |
| 374 | + host_os = args.first |
| 375 | + |
| 376 | + if !no_token && !token |
| 377 | + puts "No token found. Retrieving a token..." |
| 378 | + if !user |
| 379 | + raise "You did not provide a user to authenticate to vmpooler with" |
| 380 | + end |
| 381 | + pass = password "Enter your password please:", '*' |
| 382 | + token = Auth.get_token(verbose, url, user, pass) |
| 383 | + puts "\nToken retrieved!" |
| 384 | + puts token |
| 385 | + end |
| 386 | + |
| 387 | + Ssh.ssh(verbose, host_os, token, url) |
| 388 | + exit 0 |
| 389 | + end |
| 390 | + end |
| 391 | + |
348 | 392 | run!
|
349 | 393 | end
|
350 | 394 | end
|
0 commit comments