ecl 1.2.1 → 3.0.0.pre.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +48 -0
  5. data/README.md +112 -89
  6. data/Rakefile +1 -0
  7. data/eclair.gemspec +7 -4
  8. data/exe/ecl +62 -4
  9. data/lib/eclair.rb +21 -18
  10. data/lib/eclair/color.rb +3 -0
  11. data/lib/eclair/config.rb +68 -21
  12. data/lib/eclair/grid.rb +242 -274
  13. data/lib/eclair/group_item.rb +33 -0
  14. data/lib/eclair/item.rb +42 -0
  15. data/lib/eclair/less_viewer.rb +2 -1
  16. data/lib/eclair/provider.rb +15 -0
  17. data/lib/eclair/providers/ec2.rb +2 -0
  18. data/lib/eclair/providers/ec2/ec2_group_item.rb +16 -0
  19. data/lib/eclair/providers/ec2/ec2_item.rb +136 -0
  20. data/lib/eclair/providers/ec2/ec2_provider.rb +118 -0
  21. data/lib/eclair/providers/gce.rb +2 -0
  22. data/lib/eclair/providers/gce/gce_group_item.rb +15 -0
  23. data/lib/eclair/providers/gce/gce_item.rb +117 -0
  24. data/lib/eclair/providers/gce/gce_provider.rb +34 -0
  25. data/lib/eclair/providers/k8s.rb +2 -0
  26. data/lib/eclair/providers/k8s/k8s_group_item.rb +15 -0
  27. data/lib/eclair/providers/k8s/k8s_item.rb +92 -0
  28. data/lib/eclair/providers/k8s/k8s_provider.rb +34 -0
  29. data/lib/eclair/version.rb +2 -1
  30. data/out.gif +0 -0
  31. data/templates/eclrc.template +81 -35
  32. metadata +60 -27
  33. data/bin/console +0 -10
  34. data/lib/eclair/cell.rb +0 -101
  35. data/lib/eclair/column.rb +0 -52
  36. data/lib/eclair/console.rb +0 -56
  37. data/lib/eclair/group.rb +0 -55
  38. data/lib/eclair/helpers/aws_helper.rb +0 -157
  39. data/lib/eclair/helpers/benchmark_helper.rb +0 -19
  40. data/lib/eclair/helpers/common_helper.rb +0 -24
  41. data/lib/eclair/instance.rb +0 -165
  42. data/lib/eclair/matcher.rb +0 -19
data/bin/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "eclair"
4
-
5
- # You can add fixtures and/or initialization code here to make experimenting
6
- # with your gem easier. You can also use a different console, if you like.
7
-
8
- # (If you use this, don't forget to add pry to your Gemfile!)
9
- require "pry"
10
- Pry.start
data/lib/eclair/cell.rb DELETED
@@ -1,101 +0,0 @@
1
- module Eclair
2
- class Cell
3
- include CommonHelper
4
-
5
- attr_accessor :column
6
- attr_accessor :selected
7
-
8
- def initialize *args
9
- @current = false
10
- @selected = false
11
- end
12
-
13
- def color(*color)
14
- if @current
15
- color = config.current_color
16
- elsif @selected
17
- color = config.selected_color
18
- end
19
-
20
- if Grid.mode == :search && @current
21
- color = config.search_color
22
- end
23
-
24
- Color.fetch(*color)
25
- end
26
-
27
- def render options = 0
28
- drawy = y - column.scroll
29
- return if drawy < 0 || drawy >= Grid.maxy
30
- w = Grid.cell_width
31
- setpos(drawy + Grid::HEADER_ROWS, x * w)
32
- str = format.slice(0, w).ljust(w)
33
- attron(color) do
34
- addstr(str)
35
- end
36
- Grid.render_header
37
- end
38
-
39
- def deselect
40
- @selected = false
41
- Grid.selected.delete self
42
- redraw
43
- end
44
-
45
- def select
46
- @selected = true
47
- Grid.selected << self
48
- redraw
49
- end
50
-
51
- def toggle_select
52
- if respond_to? :each
53
- if all?(&:selected)
54
- each(&:deselect)
55
- else
56
- each(&:select)
57
- end
58
- else
59
- if @selected
60
- deselect
61
- else
62
- select
63
- end
64
- end
65
- end
66
-
67
- def current
68
- @current = true
69
- check_scroll
70
- redraw
71
- end
72
-
73
- def check_scroll
74
- unless column.drawable? y
75
- column.rescroll y
76
- end
77
- end
78
-
79
- def decurrent
80
- @current = false
81
- redraw
82
- end
83
-
84
- def redraw
85
- render
86
- refresh
87
- end
88
-
89
- def select_indicator
90
- if @selected
91
- if Grid.mode == :select
92
- "*"
93
- end
94
- end
95
- end
96
-
97
- def method_missing name, *args, &blk
98
- object.send(name)
99
- end
100
- end
101
- end
data/lib/eclair/column.rb DELETED
@@ -1,52 +0,0 @@
1
- module Eclair
2
- class Column
3
- include CommonHelper
4
- array_accessor :expand
5
- attr_accessor :scroll
6
- attr_accessor :items
7
-
8
- def initialize index
9
- @index = index
10
- @items = []
11
- @scroll = 0
12
- end
13
-
14
- def << item
15
- @items << item
16
- end
17
-
18
- def x
19
- @index
20
- end
21
-
22
- def drawable? y
23
- (@scroll...Grid.maxy+@scroll).include? y
24
- end
25
-
26
- def rescroll y
27
- if y < @scroll
28
- @scroll = y
29
- elsif y >= Grid.maxy
30
- @scroll = y - Grid.maxy + 1
31
- end
32
- expand.each do |i|
33
- i.render
34
- end
35
- end
36
-
37
- def expand
38
- expanded = []
39
- if config.group_by
40
- @items.each do |item|
41
- expanded << item
42
- item.each do |instance|
43
- expanded << instance
44
- end
45
- end
46
- expanded
47
- else
48
- @items
49
- end
50
- end
51
- end
52
- end
@@ -1,56 +0,0 @@
1
- module Eclair
2
- module Console
3
- include CommonHelper
4
- extend self
5
-
6
- def init
7
- config
8
- ENV['ESCDELAY'] = "0"
9
- init_screen
10
- stdscr.keypad = true
11
- start_color
12
- use_default_colors
13
- crmode
14
- noecho
15
- curs_set(0)
16
- Grid.start
17
- trap("INT") { exit }
18
- loop do
19
- case k = stdscr.getch
20
- when KEY_RESIZE
21
- Grid.resize
22
- when KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN
23
- Grid.move k
24
- when " "
25
- if Grid.mode == :search
26
- Grid.end_search
27
- end
28
- Grid.select
29
- when 10
30
- case Grid.mode
31
- when :search
32
- Grid.end_search
33
- else
34
- Grid.ssh
35
- end
36
- when 27
37
- if Grid.mode == :search
38
- Grid.cancel_search
39
- end
40
- when ?!
41
- Grid.debug
42
- when ??
43
- Grid.cursor_inspect
44
- when KEY_BACKSPACE, 127
45
- Grid.search(nil)
46
- when String
47
- Grid.search(k)
48
- else
49
- # Aws.reload_instances
50
- # Grid.render_all
51
- end
52
- end
53
- end
54
- end
55
- end
56
-
data/lib/eclair/group.rb DELETED
@@ -1,55 +0,0 @@
1
- module Eclair
2
- class Group < Cell
3
- array_accessor :items
4
-
5
- def initialize group_name, column = nil
6
- super
7
- @group_name = group_name
8
- @items = []
9
- @column = column
10
- end
11
-
12
- def << instance
13
- @items << instance
14
- end
15
-
16
- def x
17
- column.x
18
- end
19
-
20
- def y
21
- column.index(self)
22
- end
23
-
24
- def color
25
- super(*config.group_color)
26
- end
27
-
28
- def format
29
- " #{@group_name} (#{count(&:connectable?)}) #{select_indicator}"
30
- end
31
-
32
- def header
33
- ["Group #{@group_name}",
34
- "#{count} Instances Total",
35
- "#{count(&:running?)} Instances Running"]
36
- end
37
-
38
- def items
39
- @items
40
- end
41
-
42
- def name
43
- @group_name
44
- end
45
-
46
- def object
47
- @group_name
48
- end
49
-
50
- def info
51
- @items.map(&:info)
52
- end
53
- end
54
- end
55
-
@@ -1,157 +0,0 @@
1
- module Eclair
2
- module Aws
3
- extend self
4
-
5
- def ec2
6
- @ec2 ||= ::Aws::EC2::Client.new
7
- end
8
-
9
- def route53
10
- @route53 ||= ::Aws::Route53::Client.new
11
- end
12
-
13
- def instances
14
- fetch_all unless @instances
15
- @instances
16
- end
17
-
18
- def instance_map
19
- @instance_map
20
- end
21
-
22
- def images **options
23
- if options.delete :force
24
- @images_thread.join
25
- end
26
- @images || []
27
- end
28
-
29
- def images?
30
- !@images_thread.alive?
31
- end
32
-
33
- def dns_records **options
34
- if options.delete :force
35
- @route53_thread.join
36
- end
37
- @dns_records || []
38
- end
39
-
40
- def dns_records?
41
- !@route53_thread.alive?
42
- end
43
-
44
- def security_groups **options
45
- if options.delete :force
46
- @security_groups_thread.join
47
- end
48
- @security_groups || []
49
- end
50
-
51
- def security_groups?
52
- !@security_groups_thread.alive?
53
- end
54
-
55
- def reload_instances
56
- return if @reload_thread && @reload_thread.alive?
57
-
58
- if @reload_thread
59
- @instances = @r_instances
60
- @instance_map = @r_instances_map
61
- @images += @new_images
62
- @dns_records = @r_dns_records
63
- @security_groups = @r_security_groups
64
- Grid.assign
65
- @reload_thread = nil
66
- end
67
-
68
- return if @last_reloaded && Time.now - @last_reloaded < 5
69
-
70
- @reload_thread = Thread.new do
71
- r_instances, r_instances_map = fetch_instances
72
- @new_instances = r_instances.map(&:instance_id) - @instances.map(&:instance_id)
73
- if new_instances.empty?
74
- @new_images = []
75
- else
76
- image_ids = @new_instances.map(&:image_id)
77
- [
78
- Thread.new do
79
- @new_images = fetch_images(image_ids)
80
- end,
81
-
82
- Thread.new do
83
- @r_security_groups = fetch_security_groups
84
- end
85
- ].each(&:join)
86
- end
87
- @last_reloaded = Time.now
88
- end
89
- end
90
-
91
- private
92
-
93
- def fetch_images image_ids
94
- ec2.describe_images(image_ids: image_ids).images.flatten
95
- end
96
-
97
- def fetch_dns_records
98
- hosted_zone_ids = route53.list_hosted_zones.hosted_zones.map(&:id)
99
- hosted_zone_ids.map { |hosted_zone_id|
100
- route53.list_resource_record_sets(hosted_zone_id: hosted_zone_id).map { |resp|
101
- resp.resource_record_sets
102
- }
103
- }.flatten
104
- end
105
-
106
- def fetch_security_groups
107
- ec2.describe_security_groups.map{ |resp|
108
- resp.security_groups
109
- }.flatten
110
- end
111
-
112
- def fetch_instances
113
- instance_map = {}
114
-
115
- instances = ec2.describe_instances.map{ |resp|
116
- resp.data.reservations.map(&:instances)
117
- }.flatten
118
-
119
- instances.each do |i|
120
- instance_map[i.instance_id] = i
121
- end
122
-
123
- [instances, instance_map]
124
- end
125
-
126
-
127
- def fetch_all
128
- @instances, @instance_map = fetch_instances
129
-
130
- image_ids = @instances.map(&:image_id)
131
-
132
- if @threads
133
- @threads.each{ |t| t.kill }
134
- end
135
-
136
- Thread.abort_on_exception = true
137
-
138
- @threads = []
139
-
140
- @threads << @images_thread = Thread.new do
141
- @images = fetch_images(image_ids)
142
- end
143
-
144
- @threads << @route53_thread = Thread.new do
145
- @dns_records = fetch_dns_records
146
- end
147
-
148
- @threads << @security_groups_thread = Thread.new do
149
- @security_groups = fetch_security_groups
150
- end
151
- end
152
-
153
- def find_username image_id
154
- config.ssh_username.call(image_id, @images[image_id].name)
155
- end
156
- end
157
- end
@@ -1,19 +0,0 @@
1
- require "benchmark"
2
-
3
- module Eclair
4
- module BenchmarkHelper
5
- def benchmark(name, &blk)
6
- result = nil
7
- if ENV['BM']
8
- bm = Benchmark.measure do
9
- result = blk.call
10
- end
11
- STDERR.puts "Elasped Time for #{name}:"
12
- STDERR.puts bm
13
- result
14
- else
15
- blk.call
16
- end
17
- end
18
- end
19
- end