scaletuna 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/scaletuna +130 -0
  3. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4deb10295f00cce5b037555d5a31ca59fbd09b7e
4
+ data.tar.gz: eb4a9e67fc929165b2614cb8b343a157800caeb2
5
+ SHA512:
6
+ metadata.gz: 477de52d9991cd4c3f640bd0d24698659499e0a8823c53d355af5640d4e09859e6aa6aa17d898d9b9048c1e4dbab5fb596731c6dede6283b81d2820af01ba33a
7
+ data.tar.gz: a7dd214fbc8bf5bcbee3f66afd4b31584dcb73b62087d851362a7466dfcbc154db26bcb81cb3c69e187581a18f8e8f1983190bf912995bb13b478c510ad159b5
data/bin/scaletuna ADDED
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "curses"
4
+ include Curses
5
+ require "aws-sdk"
6
+ Q = Queue.new
7
+ I = []
8
+ def quit(message = nil, code = 0)
9
+ close_screen
10
+ $stderr.puts message if message
11
+ exit code
12
+ end
13
+ begin
14
+ C = Aws::AutoScaling::Client.new
15
+ F = /#{ARGV[0] || ENV['SCALETUNA_FILTER'] || "."}/
16
+ rescue Exception => ex
17
+ quit("Error: #{ex}", -1)
18
+ end
19
+ P = Thread.new do
20
+ begin
21
+ loop {
22
+ Q << C
23
+ .describe_auto_scaling_groups
24
+ .auto_scaling_groups
25
+ .select { |a| a.auto_scaling_group_name[F] }
26
+ }
27
+ rescue Exception => ex
28
+ quit("Error: #{ex}", -1)
29
+ end
30
+ end
31
+ init_screen
32
+ def message(msg)
33
+ setpos(lines - 1, 0)
34
+ clrtoeol
35
+ addstr msg
36
+ I << msg
37
+ refresh
38
+ end
39
+ begin
40
+ crmode
41
+ selected = [0, 2]
42
+ stdscr.keypad = true
43
+ stdscr.timeout = 100
44
+ asc = Q.pop
45
+ updated = Time.now
46
+ loop {
47
+ unless Q.empty?
48
+ asc = Q.pop
49
+ updated = Time.now
50
+ end
51
+ selection = asc[selected[0]]
52
+ setpos(0, 0)
53
+ clrtoeol
54
+ addstr "min max desired current name updated:#{updated}"
55
+ asc.each_with_index {|e, i|
56
+ clrtoeol
57
+ [e.min_size,
58
+ e.max_size,
59
+ e.desired_capacity,
60
+ e.instances.length,
61
+ e.auto_scaling_group_name].each_with_index {|v, j|
62
+ (i == selected.first && j == selected.last) && attron(A_BOLD) || attroff(A_BOLD)
63
+ (i == selected.first || j == selected.last) && attron(A_REVERSE) || attroff(A_REVERSE)
64
+ setpos(i + 1, j * 8)
65
+ addstr v.to_s[0...cols - j * 8]
66
+ }
67
+ }
68
+ setpos(selected.first + 1, selected.last * 8)
69
+ attroff A_BOLD
70
+ refresh
71
+ change = 0
72
+ begin
73
+ case (ch = getch)
74
+ when KEY_UP
75
+ selected[0] = [selected[0] - 1, 0].max
76
+ when KEY_DOWN
77
+ selected[0] = [selected[0] + 1, asc.length - 1].min
78
+ when KEY_LEFT
79
+ selected[1] = [selected[1] - 1, 0].max
80
+ when KEY_RIGHT
81
+ selected[1] = [selected[1] + 1, 2].min
82
+ when KEY_ENTER, "\n".ord, "\r".ord, "+"
83
+ change = +1
84
+ when KEY_BACKSPACE, "-"
85
+ change = -1
86
+ when "q"
87
+ quit (I << "Exited normally").join("\n")
88
+ else
89
+ message "#{ch} not mapped (+,- to increase or decrease, and move with arrows)" if ch
90
+ end
91
+ if change != 0
92
+ name = selection.auto_scaling_group_name
93
+
94
+ case selected[1]
95
+ when 2 # desired_capacity
96
+ new = selection.desired_capacity + change
97
+ message "Setting desired capacity of #{name} to #{new}"
98
+ C.set_desired_capacity(auto_scaling_group_name:
99
+ selection.auto_scaling_group_name,
100
+ desired_capacity: new,
101
+ honor_cooldown: false)
102
+ selection.desired_capacity = new
103
+ when 0 # min_size
104
+ new = selection.min_size + change
105
+ message "Setting min size of #{name} to #{new}"
106
+ C.update_auto_scaling_group(auto_scaling_group_name:
107
+ selection.auto_scaling_group_name,
108
+ min_size: new
109
+ )
110
+ selection.min_size = new
111
+ when 1 # max_size
112
+ new = selection.max_size + change
113
+ message "Setting max size of #{name} to #{new}"
114
+ C.update_auto_scaling_group(auto_scaling_group_name:
115
+ selection.auto_scaling_group_name,
116
+ max_size: new
117
+ )
118
+ selection.max_size = new
119
+ end
120
+ end
121
+ rescue Aws::AutoScaling::Errors::ValidationError => err
122
+ message "Error: #{err}"
123
+ end
124
+ }
125
+ refresh
126
+ rescue Interrupt
127
+ quit("Ctrl-c", 130)
128
+ ensure
129
+ close_screen
130
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scaletuna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Kleiner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Scaling AWS autoscalers using a curses interface
14
+ email: samuel.kleiner@bambooloans.com
15
+ executables:
16
+ - scaletuna
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/scaletuna
21
+ homepage: http://rubygems.org/gems/scaletuna
22
+ licenses:
23
+ - GPL2
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Curses AWS autoscaling
45
+ test_files: []
46
+ has_rdoc: