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
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ require 'eclair/provider'
3
+ require 'eclair/providers/gce/gce_item'
4
+ require 'eclair/providers/gce/gce_group_item'
5
+ require 'oj'
6
+
7
+ module Eclair
8
+ module GCEProvider
9
+ extend Provider
10
+ extend self
11
+
12
+ def group_class
13
+ GCEGroupItem
14
+ end
15
+
16
+ def item_class
17
+ GCEItem
18
+ end
19
+
20
+ def prepare keyword
21
+ instances = Oj.load(`gcloud compute instances list --format=json`)
22
+ @items = instances.map{|i| GCEItem.new(i)}
23
+ end
24
+
25
+ def items
26
+ @items
27
+ end
28
+
29
+ private
30
+ def config
31
+ Eclair.config
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require "eclair/providers/k8s/k8s_provider"
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require "eclair/group_item"
3
+
4
+ module Eclair
5
+ class K8sGroupItem < GroupItem
6
+ def header
7
+ all = @items.count
8
+
9
+ <<-EOS
10
+ Group #{label}
11
+ #{all} pods Total
12
+ EOS
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+ require 'eclair/item'
3
+ require 'eclair/providers/k8s/k8s_provider'
4
+ require 'time'
5
+
6
+ module Eclair
7
+ class K8sItem < Item
8
+ attr_reader :pod
9
+
10
+ def initialize pod
11
+ super()
12
+ @pod = pod
13
+ end
14
+
15
+ def id
16
+ @pod["metadata"]["uid"]
17
+ end
18
+
19
+ def color
20
+ if @selected
21
+ [Curses::COLOR_YELLOW, -1, Curses::A_BOLD]
22
+ elsif !connectable?
23
+ [Curses::COLOR_BLACK, -1, Curses::A_BOLD]
24
+ else
25
+ [Curses::COLOR_WHITE, -1]
26
+ end
27
+ end
28
+
29
+ def exec_command
30
+ @pod["metadata"]["labels"]["eclair_exec_command"] || "/bin/sh"
31
+ end
32
+
33
+ def command
34
+ "kubectl exec --namespace #{namespace} -ti #{name} #{exec_command}"
35
+ end
36
+
37
+ def header
38
+ <<-EOS
39
+ #{name}
40
+ launched at #{launch_time.to_time}
41
+ EOS
42
+ end
43
+
44
+ def label
45
+ " - #{name} [#{launched_at}]"
46
+ end
47
+
48
+ def namespace
49
+ @pod["metadata"]["namespace"]
50
+ end
51
+
52
+ def name
53
+ @pod["metadata"]["name"]
54
+ end
55
+
56
+ def connectable?
57
+ status == "running"
58
+ end
59
+
60
+ def search_key
61
+ name.downcase
62
+ end
63
+
64
+ private
65
+
66
+ def status
67
+ @pod["status"]["containerStatuses"].first["state"].keys.first rescue nil
68
+ end
69
+
70
+ def launch_time
71
+ Time.parse(@pod["metadata"]["creationTimestamp"])
72
+ end
73
+
74
+ def launched_at
75
+ diff = Time.now - launch_time
76
+ {
77
+ "year" => 31557600,
78
+ "month" => 2592000,
79
+ "day" => 86400,
80
+ "hour" => 3600,
81
+ "minute" => 60,
82
+ "second" => 1
83
+ }.each do |unit,v|
84
+ if diff >= v
85
+ value = (diff/v).to_i
86
+ return "#{value} #{unit}#{value > 1 ? "s" : ""}"
87
+ end
88
+ end
89
+ "now"
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ require 'eclair/provider'
3
+ require 'eclair/providers/k8s/k8s_item'
4
+ require 'eclair/providers/k8s/k8s_group_item'
5
+ require 'oj'
6
+
7
+ module Eclair
8
+ module K8sProvider
9
+ extend Provider
10
+ extend self
11
+
12
+ def group_class
13
+ K8sGroupItem
14
+ end
15
+
16
+ def item_class
17
+ K8sItem
18
+ end
19
+
20
+ def prepare keyword
21
+ pods = Oj.load(`kubectl get pods #{config.get_pods_option} -o json`)["items"].select{|i| i["metadata"]["name"].include? keyword or i["metadata"]["namespace"].include? keyword}
22
+ @items = pods.map{|i| K8sItem.new(i)}
23
+ end
24
+
25
+ def items
26
+ @items
27
+ end
28
+
29
+ private
30
+ def config
31
+ Eclair.config
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Eclair
2
- VERSION = "1.2.1"
3
+ VERSION = "3.0.0-alpha1"
3
4
  end
data/out.gif ADDED
Binary file
@@ -1,34 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ ## Default configuration.
1
4
  Eclair.configure do |config|
2
- # aws_region - AWS region to connect.
3
- # This overrides AWS_REGION environment variable, so you can comment out this line if you set this in environment variable.
4
- config.aws_region = "ap-northeast-1"
5
+ ## provider - Cloud provider to connect.
6
+ ## You can use either AWS EC2 (:ec2) or Kubernetes (:k8s) with eclair. AWS
7
+ ## EC2 is used by default.
8
+ # config.provider = :ec2
9
+
10
+ ## aws_region - AWS region to connect.
11
+ ## This overrides AWS_REGION environment variable, so you can comment out this
12
+ ## line if you set this in environment variable.
13
+ # config.aws_region = "ap-northeast-1"
5
14
 
6
- # columns - Max number of columns displayed in eclair.
7
- config.columns = 4
15
+ ## columns - Max number of columns displayed in eclair. (Default: 4)
16
+ # config.columns = 4
8
17
 
9
- # ssh_username - Function to find username from image
10
- # You can use image data from EC2::Client#describe_images API call
11
- # https://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#describe_images-instance_method
18
+ ## ssh_username - Function to find username from image.
19
+ ## You can use image data from EC2::Client#describe_images API call.
20
+ ## https://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#describe_images-instance_method
12
21
  config.ssh_username = lambda do |image|
13
22
  case image.name
14
- when /ubuntu/
15
- "ubuntu"
16
- else
23
+
24
+ ## Add your own configurations here.
25
+ # when /OpenVPN/
26
+ # "openvpnas"
27
+
28
+ when /ubuntu/i
29
+ "ubuntu" ## https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html#AccessingInstancesLinuxSSHClient
30
+ when /centos/i
31
+ "centos" ## https://wiki.centos.org/Cloud/AWS
32
+ when /debian/i
33
+ "admin" ## https://wiki.debian.org/Cloud#FAQ
34
+ when /^bitnami-/
35
+ "bitnami" ## https://docs.bitnami.com/aws/faq/#how-to-connect-to-the-server-through-ssh
36
+ when /CoreOS/
37
+ "core" ## https://coreos.com/os/docs/latest/booting-on-ec2.html#ssh-to-your-instances
38
+ when /redhat/i, /RHEL|rhel/, /fedora/i, /suse/i, /SLES|sles/, /FreeBSD/
17
39
  "ec2-user"
40
+ else
41
+ fallback = "ec2-user"
42
+ msg = "Cannot infer ssh username of image \e[33m#{image.name}\e[0m. Fallback to \e[33m#{fallback}\e[0m"
43
+ STDERR.puts STDERR.isatty ? msg : msg.gsub(/\e\[([;\d]+)?m/, '')
44
+ fallback
18
45
  end
19
46
  end
20
47
 
21
- # ssh_keys - Hash of key_name => key_path in local.
22
- # If your key has been already registered in ssh-agent, you don't have to configure this.
23
- config.ssh_keys = {
24
- }
48
+ ## ssh_keys - Hash of key_name => key_path in local.
49
+ ## If your key has been already registered in ssh-agent, you don't have to
50
+ ## configure this. (Default: {})
51
+ # config.ssh_keys = {
52
+ # }
25
53
 
26
- # group_by - Function to find group name from instance.
27
- # Make a function that returns group name from instance data
28
- # You can access response data extracted from EC2::Client#describe_instances API call
29
- # https://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#describe_instances-instance_method
54
+ ## group_by - Function to find group name from instance.
55
+ ## Make a function that returns group name from instance data.
56
+ ## You can access response data extracted from EC2::Client#describe_instances
57
+ ## API call.
58
+ ##
59
+ ## https://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#describe_instances-instance_method
30
60
 
31
- # If you want to group instances by security group, uncomment example below. (default option)
61
+ ## If you want to group instances by security group, uncomment the example below. (Default behavior)
32
62
  # config.group_by = lambda do |instance|
33
63
  # if instance.security_groups.first
34
64
  # instance.security_groups.first.group_name
@@ -37,11 +67,9 @@ Eclair.configure do |config|
37
67
  # end
38
68
  # end
39
69
 
40
- # If you want to group instances by name, uncomment and edit example below.
70
+ ## If you want to group instances by name, uncomment and edit the example below.
41
71
  # config.group_by = lambda do |instance|
42
- # nametag = instance.tags.find{|t| t.key == "Name"}
43
- # return "Noname" unless nametag
44
- # case nametag.value
72
+ # case instance.name
45
73
  # when /^production/
46
74
  # "production servers"
47
75
  # when /^test/
@@ -49,18 +77,36 @@ Eclair.configure do |config|
49
77
  # end
50
78
  # end
51
79
 
52
- # If you do not want to group instances, uncomment below line.
53
- # config.group_by = nil
80
+ ## If you do not want to group instances, uncomment the line below.
81
+ # config.group_by = nil
82
+
83
+ ## ssh_ports - Port numbers to try ssh.
84
+ ## Eclair will try to ssh specified ports in order with ConnectTimeout below.
85
+ # config.ssh_ports = [22]
54
86
 
55
- # ssh_ports - Port numbers to try ssh.
56
- # Eclair will try to ssh specified ports in order with ConnectTimeout below.
57
- config.ssh_ports = [22]
87
+ ## ssh_options - Extra options passed to ssh.
88
+ ## ConnectTimeout should exist when you want to connect to multiple ports.
89
+ # config.ssh_options = "-o ConnectTimeout=1 -o StrictHostKeyChecking=no"
58
90
 
59
- # ssh_options - Extra options passed to ssh.
60
- # ConnectTimeout should exist when you want to connect to multiple ports.
61
- config.ssh_options = "-o ConnectTimeout=1 -o StrictHostKeyChecking=no"
91
+ ## ssh_command - Name of the binary which will be used to establish ssh
92
+ ## connection. (Default: "ssh")
93
+ # config.ssh_command = "/usr/bin/ssh"
62
94
 
63
- # ssh_hostname - Hostname to use for ssh.
64
- # You can choose from :public_dns_name, :public_ip_address, :private_dns_name, :private_ip_address
65
- config.ssh_hostname = :public_ip_address
95
+ ## exec_format - Format of the shell command which will be executed in the
96
+ ## shell. (Default: "{ssh_command} {ssh_options} -p{port} {ssh_key} {username}@{host}")
97
+ # config.exec_format = "echo 'hi' && {ssh_command} {ssh_options} -p{port} {ssh_key} {username}@{host}"
98
+ end
99
+
100
+ ## Alternative configuration.
101
+ ##
102
+ ## You can easily switch between multiple configurations with 'ECL_PROFILE'
103
+ ## environment variable. To use 'k8s' configuration, execute eclair like below:
104
+ ##
105
+ ## ECL_PROFILE=k8s ecl
106
+ Eclair.configure "k8s" do |config|
107
+ config.provider = :k8s
108
+ config.get_pods_option = "--all-namespaces"
109
+ config.group_by = lambda do |item|
110
+ item.namespace
111
+ end
66
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 3.0.0.pre.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devsisters
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-30 00:00:00.000000000 Z
11
+ date: 2019-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: aws-sdk
42
+ name: aws-sdk-ec2
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2'
47
+ version: '1.18'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2'
54
+ version: '1.18'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: curses
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-string-match-scorer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -81,19 +95,33 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.10'
83
97
  - !ruby/object:Gem::Dependency
84
- name: ruby-string-match-scorer
98
+ name: json
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.1'
103
+ version: '2.1'
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.1'
110
+ version: '2.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: oj
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.3'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.3'
97
125
  description: Simple ssh helper for Amazon EC2
98
126
  email:
99
127
  - se@devsisters.com
@@ -104,28 +132,35 @@ extra_rdoc_files: []
104
132
  files:
105
133
  - ".gitignore"
106
134
  - Gemfile
135
+ - Gemfile.lock
107
136
  - LICENSE.txt
108
137
  - README.md
109
138
  - Rakefile
110
- - bin/console
111
139
  - bin/setup
112
140
  - eclair.gemspec
113
141
  - exe/ecl
114
142
  - lib/eclair.rb
115
- - lib/eclair/cell.rb
116
143
  - lib/eclair/color.rb
117
- - lib/eclair/column.rb
118
144
  - lib/eclair/config.rb
119
- - lib/eclair/console.rb
120
145
  - lib/eclair/grid.rb
121
- - lib/eclair/group.rb
122
- - lib/eclair/helpers/aws_helper.rb
123
- - lib/eclair/helpers/benchmark_helper.rb
124
- - lib/eclair/helpers/common_helper.rb
125
- - lib/eclair/instance.rb
146
+ - lib/eclair/group_item.rb
147
+ - lib/eclair/item.rb
126
148
  - lib/eclair/less_viewer.rb
127
- - lib/eclair/matcher.rb
149
+ - lib/eclair/provider.rb
150
+ - lib/eclair/providers/ec2.rb
151
+ - lib/eclair/providers/ec2/ec2_group_item.rb
152
+ - lib/eclair/providers/ec2/ec2_item.rb
153
+ - lib/eclair/providers/ec2/ec2_provider.rb
154
+ - lib/eclair/providers/gce.rb
155
+ - lib/eclair/providers/gce/gce_group_item.rb
156
+ - lib/eclair/providers/gce/gce_item.rb
157
+ - lib/eclair/providers/gce/gce_provider.rb
158
+ - lib/eclair/providers/k8s.rb
159
+ - lib/eclair/providers/k8s/k8s_group_item.rb
160
+ - lib/eclair/providers/k8s/k8s_item.rb
161
+ - lib/eclair/providers/k8s/k8s_provider.rb
128
162
  - lib/eclair/version.rb
163
+ - out.gif
129
164
  - templates/eclrc.template
130
165
  homepage: https://github.com/devsisters/eclair
131
166
  licenses:
@@ -142,14 +177,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
177
  version: '0'
143
178
  required_rubygems_version: !ruby/object:Gem::Requirement
144
179
  requirements:
145
- - - ">="
180
+ - - ">"
146
181
  - !ruby/object:Gem::Version
147
- version: '0'
182
+ version: 1.3.1
148
183
  requirements: []
149
- rubyforge_project:
150
- rubygems_version: 2.5.0
184
+ rubygems_version: 3.0.3
151
185
  signing_key:
152
186
  specification_version: 4
153
187
  summary: EC2 ssh helper
154
188
  test_files: []
155
- has_rdoc: