steam_donkey 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ desc 'Manage and view ec2 instances'
2
+ command [:ec2] do |ec2|
3
+
4
+ ec2.desc 'List ec2 instances'
5
+ ec2.command [:list, :ls] do |list|
6
+
7
+ list.switch [:raw, :r], :default_value => false, :negatable => false, :desc => "Output unformatted, useful when piping results to other commands"
8
+ list.switch [:headings, :h], :default_value => false, :desc => "Toggle column headings"
9
+
10
+ list.flag [:filter, :f], :default_value => 'State=running'
11
+ list.flag [:columns, :c], :default_value => 'Name,KeyName,Tags.environment,Tags.Owner,PublicIpAddress'
12
+ list.flag [:sort, :s], :default_value => 'LaunchTime=desc'
13
+
14
+ list.flag [:output, :o], :default_value => 'pretty', :must_match => %w(pretty raw)
15
+
16
+ list.action do |global_options, options, args|
17
+ listing_options = {
18
+ :filters => options[:filters],
19
+ :columns => options[:columns],
20
+ :sort => options[:sort]
21
+ }
22
+
23
+ puts global_options.inspect
24
+
25
+ # instance_listing = SteamDonkey::EC2::InstanceListing.new(ec2_client(global_options), listing_options)
26
+
27
+ # output = SteamDonkey::Cli::Output.new(true, options[:output])
28
+ # output.render instance_listing.column_labels, instance_listing.list
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module SteamDonkey
2
+ class Config
3
+ def self.load(rc_file, global)
4
+ myini = IniFile.load(File.absolute_path('/Users/petercoulton/.donkeyrc'))
5
+ global[:rc] = {}
6
+
7
+ config = { :package => {} }
8
+ myini['cloudformation "package"'].each do |k, v|
9
+ config[:package][k.gsub(/"/, '')] = v
10
+ end
11
+ global[:rc][:cloudformation] = config
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,54 @@
1
+ require 'aws-sdk'
2
+
3
+ module SteamDonkey
4
+ module EC2
5
+ class InstanceListing
6
+ include SteamDonkey::ResourceListing
7
+
8
+ attr_reader :column_labels
9
+
10
+ def initialize(client, options = {})
11
+ @client = client
12
+ init(options[:sort], options[:filters], options[:columns])
13
+ end
14
+
15
+ def aliases
16
+ [
17
+ { test: /^Name$/i, value: 'Tags.Name' },
18
+ { test: /^Id$/i, value: 'InstanceId' },
19
+ { test: /^State(\.Name)?$/i, value: 'State.Name' }
20
+ ]
21
+ end
22
+
23
+ def search
24
+ @client.describe_instances.map do |response|
25
+ response.reservations.map do |reservation|
26
+ reservation.instances.map do |instance|
27
+ instance
28
+ end
29
+ end.flatten
30
+ end.flatten
31
+ end
32
+
33
+ def select_column(column, instance)
34
+ c = column.clone
35
+ begin
36
+ case column[:name]
37
+ when /^Tags\./i
38
+ c[:value] = find_tag(instance, column[:name].split('.').last)
39
+ when /^State(\.Name)?$/i
40
+ c[:value] = instance.state.name
41
+ when /^State\.Code$/i
42
+ c[:value] = instance.state.code
43
+ else
44
+ c[:value] = instance.send(column[:name].underscore)
45
+ end
46
+ rescue
47
+ raise "Unknown column #{column[:name]}"
48
+ end
49
+ c
50
+ end
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,152 @@
1
+ require 'to_regexp'
2
+
3
+ class String
4
+ def underscore
5
+ self.gsub(/::/, '/').
6
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
7
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
8
+ tr('-', '_').
9
+ downcase
10
+ end
11
+ end
12
+
13
+ module ReversedOrder
14
+ def <=>(other)
15
+ - super
16
+ end
17
+ end
18
+
19
+ module SteamDonkey
20
+ module ResourceListing
21
+
22
+ attr_reader :column_labels
23
+
24
+ def init(sort = '', filters = '', columns = '')
25
+ @sort_columns = parse_sort_columns(sort || '', aliases)
26
+ @filter_columns = parse_filters(filters || '', aliases)
27
+ @columns = parse_columns(columns || '', @filter_columns, @sort_columns, aliases)
28
+ @column_labels = split_columns(columns || '')
29
+ end
30
+
31
+ def substitute_aliases(column, aliases=[])
32
+ substitute = aliases.find { |a| a[:test] =~ column }
33
+ substitute.nil? ? column : substitute[:value]
34
+ end
35
+
36
+ def split_columns(columns)
37
+ columns.split(',').map(&:strip)
38
+ end
39
+
40
+ def combine_columns(columns, filter_columns, sort_columns)
41
+ result = []
42
+ columns.each do |column|
43
+ result << column
44
+ end
45
+
46
+ filter_columns.each do |key|
47
+ result << key
48
+ end
49
+
50
+ sort_columns.each do |key|
51
+ result << key
52
+ end
53
+
54
+ result
55
+ end
56
+
57
+ def parse_columns(columns='', filter_columns = [], sort_columns = [], aliases = [])
58
+ label_columns = split_columns(columns).map do |column|
59
+ { :name => substitute_aliases(column, aliases), :label => column }
60
+ end
61
+ combine_columns(label_columns, filter_columns, sort_columns)
62
+ end
63
+
64
+ def parse_filters(filters='', aliases = [])
65
+ split_columns(filters).map do |filter|
66
+ column, test = filter.split('=')
67
+ { :name => substitute_aliases(column, aliases), :test => test }
68
+ end
69
+ end
70
+
71
+ def parse_sort_columns(sort_columns = '', aliases = [])
72
+ split_columns(sort_columns).map do |filter|
73
+ column, sort_direction = filter.split('=')
74
+ sort = (sort_direction || 'asc').downcase
75
+
76
+ raise "Unknown sort modifier #{sort_direction}" unless %w(asc desc).include? sort
77
+
78
+ { :name => substitute_aliases(column, aliases), :direction => sort }
79
+ end
80
+ end
81
+
82
+ def filtered_out?(instance)
83
+ filters = instance.select { |c| c.has_key? :test }
84
+ skip = false
85
+ filters.each do |filter|
86
+ if filter[:test] =~ /^\?.+/
87
+ expected_value_regexp = filter[:test][1..-1].to_regexp
88
+ skip = true unless !!(filter[:value] =~ expected_value_regexp)
89
+ next
90
+ end
91
+
92
+ if filter[:test] =~ /^!.+/
93
+ expected_value_regexp = filter[:test][1..-1].to_regexp
94
+ skip = true if !!(filter[:value] =~ expected_value_regexp)
95
+ next
96
+ end
97
+
98
+ if filter[:value] != filter[:test]
99
+ skip = true
100
+ end
101
+ end
102
+ skip
103
+ end
104
+
105
+ def find_tag(instance, column)
106
+ name = column.downcase
107
+ tag = instance.tags.find { |tag| tag.key.downcase == name }
108
+ if tag != nil
109
+ tag[:value]
110
+ else
111
+ nil
112
+ end
113
+ end
114
+
115
+ def names(columns)
116
+ columns.map do |column|
117
+ column[:name]
118
+ end
119
+ end
120
+
121
+ def remove_sort_and_filter_columns(columns)
122
+ columns.select { |c| c.has_key? :label }
123
+ end
124
+
125
+ def select_columns(instance)
126
+ columns = []
127
+ @columns.each do |column|
128
+ columns << select_column(column, instance)
129
+ end
130
+ columns
131
+ end
132
+
133
+ def sort_instances(instance)
134
+ return [] if instance.nil?
135
+ @sort_columns.map do |sort|
136
+ value = (select_column(sort, instance)[:value] || '').to_s
137
+ if sort[:direction] == 'desc'
138
+ value = value.dup.extend(ReversedOrder)
139
+ end
140
+ value
141
+ end
142
+ end
143
+
144
+ def list
145
+ search
146
+ .sort_by(&self.method(:sort_instances))
147
+ .map(&self.method(:select_columns))
148
+ .reject(&self.method(:filtered_out?))
149
+ .map(&self.method(:remove_sort_and_filter_columns))
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,3 @@
1
+ module SteamDonkey
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,28 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','steam_donkey','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'steam_donkey'
5
+ s.version = SteamDonkey::VERSION
6
+ s.author = 'Peter Coulton'
7
+ s.email = 'petercoulton@gmail.com'
8
+ s.homepage = 'https://github.com/petercoulton/steam_donkey'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'Tools and scripts for building and managing infrastructure on AWS.'
11
+ s.files = `git ls-files`.split("
12
+ ")
13
+ s.require_paths << 'lib'
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = ['README.rdoc','steam_donkey.rdoc']
16
+ s.rdoc_options << '--title' << 'steam_donkey' << '--main' << 'README.rdoc' << '-ri'
17
+ s.bindir = 'bin'
18
+ s.executables << 'donkey'
19
+ s.add_development_dependency('rake')
20
+ s.add_development_dependency('rdoc')
21
+ s.add_development_dependency('aruba')
22
+ s.add_runtime_dependency('gli','2.14.0')
23
+ s.add_runtime_dependency('aws-sdk', '~> 2.6')
24
+ s.add_runtime_dependency('chronic', '~> 0.10')
25
+ s.add_runtime_dependency('to_regexp', '~> 0.2.1')
26
+ s.add_runtime_dependency('command_line_reporter', '~> 3.0')
27
+ s.add_runtime_dependency('inifile', '~> 3.0')
28
+ end
data/steam_donkey.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = steam_donkey
2
+
3
+ Generate this with
4
+ steam_donkey rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # Add test libraries you want to use here, e.g. mocha
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ # Add global extensions to the test case class here
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steam_donkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Coulton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: chronic
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: to_regexp
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: command_line_reporter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: inifile
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description:
140
+ email: petercoulton@gmail.com
141
+ executables:
142
+ - donkey
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - README.rdoc
146
+ - steam_donkey.rdoc
147
+ files:
148
+ - ".gitignore"
149
+ - Gemfile
150
+ - Gemfile.lock
151
+ - README.md
152
+ - README.rdoc
153
+ - Rakefile
154
+ - bin/donkey
155
+ - features/steam_donkey.feature
156
+ - features/step_definitions/steam_donkey_steps.rb
157
+ - features/support/env.rb
158
+ - fixtures/templates/1/child1.template
159
+ - fixtures/templates/child2.template
160
+ - fixtures/templates/parent.template
161
+ - lib/steam_donkey.rb
162
+ - lib/steam_donkey/aws.rb
163
+ - lib/steam_donkey/cli/output.rb
164
+ - lib/steam_donkey/cloudformation/deploy_stack.rb
165
+ - lib/steam_donkey/cloudformation/event_log.rb
166
+ - lib/steam_donkey/cloudformation/exports_listing.rb
167
+ - lib/steam_donkey/cloudformation/package.rb
168
+ - lib/steam_donkey/cloudformation/stack_listing.rb
169
+ - lib/steam_donkey/commands/cf.rb
170
+ - lib/steam_donkey/commands/ec2.rb
171
+ - lib/steam_donkey/config.rb
172
+ - lib/steam_donkey/ec2/instance_listing.rb
173
+ - lib/steam_donkey/resource_listing.rb
174
+ - lib/steam_donkey/version.rb
175
+ - steam_donkey.gemspec
176
+ - steam_donkey.rdoc
177
+ - test/default_test.rb
178
+ - test/test_helper.rb
179
+ homepage: https://github.com/petercoulton/steam_donkey
180
+ licenses: []
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options:
184
+ - "--title"
185
+ - steam_donkey
186
+ - "--main"
187
+ - README.rdoc
188
+ - "-ri"
189
+ require_paths:
190
+ - lib
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.6.8
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: Tools and scripts for building and managing infrastructure on AWS.
208
+ test_files: []