awsquery 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -0
- data/bin/awsquery +47 -0
- data/bin/awsssh +55 -0
- metadata +62 -0
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
awsquery(1) -- query aws metadata for hosts
|
2
|
+
==========================================
|
3
|
+
|
4
|
+
## SYNOPSIS
|
5
|
+
|
6
|
+
Allows the lookup and querying of EC2 hosts via the associated metadata.
|
7
|
+
|
8
|
+
## EXAMPLES
|
9
|
+
|
10
|
+
1. Look up hosts based on tags
|
11
|
+
|
12
|
+
`$ awsquery Name=app1`
|
13
|
+
|
14
|
+
2. Open iTerm with tabs for all appservers
|
15
|
+
|
16
|
+
`$ awsquery Role=app | awsssh iterm`
|
17
|
+
|
18
|
+
## CONTACT
|
19
|
+
|
20
|
+
Author is Lachlan Donald <lachlan@ljd.cc>
|
data/bin/awsquery
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'fog'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {
|
8
|
+
:default_key => 'Name',
|
9
|
+
:state => 'running',
|
10
|
+
:verbose => false,
|
11
|
+
}
|
12
|
+
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: awsquery.rb [options]"
|
15
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
16
|
+
options[:verbose] = v
|
17
|
+
end
|
18
|
+
opts.on("-s", "--state STATE", "Filter by state") do |s|
|
19
|
+
options[:state] = s
|
20
|
+
end
|
21
|
+
end.parse!
|
22
|
+
|
23
|
+
compute = Fog::Compute.new(
|
24
|
+
:provider => 'AWS',
|
25
|
+
:aws_access_key_id => ENV['ACCESS_KEY_ID'],
|
26
|
+
:aws_secret_access_key => ENV['SECRET_ACCESS_KEY']
|
27
|
+
)
|
28
|
+
|
29
|
+
# apply basic filters
|
30
|
+
servers = compute.servers
|
31
|
+
servers.reject! { |s| s.state != options[:state] }
|
32
|
+
|
33
|
+
# process metdata filters, either key=value, or just value
|
34
|
+
ARGV.each do |arg|
|
35
|
+
tokens = arg.split('=')
|
36
|
+
tokens.unshift options[:default_key] if tokens.count == 1
|
37
|
+
key, value = tokens
|
38
|
+
servers.reject! { |s| !s.tags.key? key or s.tags[key] != value }
|
39
|
+
end
|
40
|
+
|
41
|
+
# output
|
42
|
+
servers.each do |server|
|
43
|
+
print server.dns_name
|
44
|
+
print " => %s" % server.tags.inspect if options[:verbose]
|
45
|
+
puts
|
46
|
+
end
|
47
|
+
|
data/bin/awsssh
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {
|
7
|
+
:verbose => false,
|
8
|
+
:user => false
|
9
|
+
}
|
10
|
+
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: awsssh.rb [options]"
|
13
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
14
|
+
options[:verbose] = v
|
15
|
+
end
|
16
|
+
opts.on("-u", "--user USERNAME", "Username to log in with") do |s|
|
17
|
+
options[:user] = s
|
18
|
+
end
|
19
|
+
end.parse!
|
20
|
+
|
21
|
+
# parse stdin hosts
|
22
|
+
servers = []
|
23
|
+
|
24
|
+
STDIN.read.split("\n").each do |a|
|
25
|
+
servers << { :host => a, :user => options[:user] }
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def iterm(servers, options)
|
30
|
+
command = '
|
31
|
+
tell application "iTerm"
|
32
|
+
activate
|
33
|
+
set myterm to (make new terminal)
|
34
|
+
'
|
35
|
+
servers.each_with_index do |server, t|
|
36
|
+
command << %Q|
|
37
|
+
tell myterm
|
38
|
+
launch session "Default"
|
39
|
+
tell last session
|
40
|
+
write text "/usr/bin/ssh #{server[:user] ? server[:user]+'@'+server[:host] : server[:host]}"
|
41
|
+
set name to "#{server[:host]}"
|
42
|
+
end tell
|
43
|
+
end tell\n|
|
44
|
+
end
|
45
|
+
command << '
|
46
|
+
end tell
|
47
|
+
'
|
48
|
+
puts command
|
49
|
+
exec "osascript -e '#{command}' > /dev/null"
|
50
|
+
end
|
51
|
+
|
52
|
+
case ARGV[0]
|
53
|
+
when "iterm"
|
54
|
+
iterm servers, options
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awsquery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lachlan Donald
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fog
|
16
|
+
requirement: &70183867827920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70183867827920
|
25
|
+
description: A collection of tools for querying AWS hosts based on metadata and manipulating
|
26
|
+
them
|
27
|
+
email:
|
28
|
+
- lachlan@ljd.cc
|
29
|
+
executables:
|
30
|
+
- awsquery
|
31
|
+
- awsssh
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/awsquery
|
36
|
+
- bin/awsssh
|
37
|
+
- README.md
|
38
|
+
homepage: http://github.com/lox/awsquery
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.17
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Query AWS hosts based on metadata
|
62
|
+
test_files: []
|