Class: AppCommand::SSH

Inherits:
Convoy::ActionCommand::Base
  • Object
show all
Defined in:
lib/routes/ssh.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/routes/ssh.rb', line 7

def execute

    begin

        @opts = command_options
        @args = arguments

        opts_validate
        opts_routing

    rescue => e

        Blufin::Terminal::print_exception(e)

    end

end

#opts_routingObject



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
# File 'lib/routes/ssh.rb', line 29

def opts_routing

    puts
    result = Blufin::Terminal::execute('awx l -r EC2Instances -j', capture: true, text: 'Getting EC2 instance data...')
    puts

    begin
        instances = JSON.parse(result)
    rescue => e
        puts
        puts result
        Blufin::Terminal::error('Failed to parse AWS response JSON.', e.message)
    end

    accessible_instances = []

    instances.each do |instance|
        if instance.has_key?('State') && instance['State']['Name'] == 'running'
            accessible_instances << {
                :instance_id       => instance['InstanceId'],
                :public_ip         => instance['PublicIpAddress'],
                :public_dns        => instance['PublicDnsName'],
                :key               => instance.has_key?('KeyName') ? instance['KeyName'] : "\xe2\x80\x94",
                :tags              => instance['Tags'],
                :region            => instance['region'],
                :availability_zone => instance['Placement']['AvailabilityZone']
            }
        end
    end

    # TODO - REMOVE
    puts
    puts "\x1B[38;5;198m#{accessible_instances.to_yaml}\x1B[0m"

    # TODO - Need to take Hash and create a Select list to A) select instance and B) select SSH (public) Key.
    # TODO - A pre-requisite for this is that EC2 available Keys need to be in the Tags somehow.

end

#opts_validateObject



25
26
27
# File 'lib/routes/ssh.rb', line 25

def opts_validate

end