Class: DimensionShell::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/dimension_shell/cli.rb

Instance Method Summary collapse

Instance Method Details

#connect(servername, *ssh_options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dimension_shell/cli.rb', line 20

def connect(servername, *ssh_options)
  _init_command(options)
  shell_user = options[:shell_user] || configatron.shell_user || 'root'

  result = @cloud_control.get_server servername

  if result[:failure] then
    _api_access_failed result
  elsif result['totalCount'] != 1 then
    _puts %Q(No servername matched to "#{servername}".)
  else
    server = result['server'].first
    primary_ipv6 = server['networkInfo']['primaryNic']['ipv6']
    puts "Server \"#{servername}\" found, opening secure shell to #{shell_user}@#{primary_ipv6}."
    call = "ssh #{shell_user}@#{primary_ipv6}"
    call += " " + ssh_options.join(" ") if ssh_options.any?
    puts call
    Kernel.exec(call)
  end
end

#listObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dimension_shell/cli.rb', line 43

def list
  _init_command(options)

  result = @cloud_control.get_server_list

  if result[:failure] then
    _api_access_failed result
  else
    result['server'].each { |server|
      primary_ipv6 = server['networkInfo']['primaryNic']['ipv6']

      puts "#{server['name']} (#{server['operatingSystem']['displayName']}) - #{server['state']}\tipv6: #{primary_ipv6}"
    }
    puts %Q(#{result['totalCount']} server/s in total.)
  end
end