ec2l 0.0.1
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.
- data/.gitignore +23 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/bin/ec2l +5 -0
- data/ec2l.gemspec +27 -0
- data/lib/ec2l.rb +72 -0
- data/lib/ec2l/version.rb +3 -0
- data/test/test_ec2l.rb +20 -0
- metadata +145 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
.*.swp
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 yazgoo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Ec2l
|
2
|
+
|
3
|
+
[](https://travis-ci.org/yazgoo/ec2l)
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'ec2l'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ec2l
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/ec2l/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/ec2l
ADDED
data/ec2l.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ec2l/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ec2l"
|
8
|
+
spec.version = Ec2l::VERSION
|
9
|
+
spec.authors = ["yazgoo"]
|
10
|
+
spec.email = ["yazgoo@github.com"]
|
11
|
+
spec.summary = "a convenience wrapper for EC2 apis"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "amazon-ec2"
|
25
|
+
spec.add_runtime_dependency "awesome_print"
|
26
|
+
spec.add_runtime_dependency "pry"
|
27
|
+
end
|
data/lib/ec2l.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "ec2l/version"
|
2
|
+
require 'base64'
|
3
|
+
require 'awesome_print'
|
4
|
+
require 'pry'
|
5
|
+
module Ec2l
|
6
|
+
class Client
|
7
|
+
def instances keep = ["instanceId", "ipAddress", "groups",
|
8
|
+
"launchType", "instanceType", "tagSet"]
|
9
|
+
@ec2.describe_instances.reservationSet.item.collect do |item|
|
10
|
+
group = item.groupSet if keep.include? "groups"
|
11
|
+
item = item.instancesSet.item[0].reject{|k, v| not keep.include? k}
|
12
|
+
item["groups"] = group.item.map{|x| x.groupId } if not group.nil?
|
13
|
+
item["tagSet"] = to_hash(item["tagSet"].item) if item["tagSet"]
|
14
|
+
Hash[item.map { |k, v| [k.to_sym, v] }]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def instance(id) @ec2.describe_instances(instance_id: id) end
|
18
|
+
def sgs
|
19
|
+
@ec2.describe_security_groups.securityGroupInfo.item.collect do |item|
|
20
|
+
item.reject { |k, v| not ["groupName", "ownerId"].include? k }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def i() instances ["instanceId", "ipAddress", "tagSet", "instanceState"] end
|
24
|
+
def log id
|
25
|
+
puts Base64.decode64 @ec2.get_console_output(instance_id: id)["output"]
|
26
|
+
end
|
27
|
+
def terminate(id) @ec2.terminate_instances(instance_id: id) end
|
28
|
+
def shell() binding.pry end
|
29
|
+
def update_configuration creds = nil
|
30
|
+
puts "Will try and update configuration in #{@conf}"
|
31
|
+
creds = read_credentials if creds.nil?
|
32
|
+
File.open(@conf, "w") do |f|
|
33
|
+
["access key", "secret access key",
|
34
|
+
"entry point (default being https://aws.amazon.com if blank)"
|
35
|
+
].each_with_index do |prompt, i|
|
36
|
+
printf "#{prompt} (#{creds.size > i ? creds[i]:""}): "
|
37
|
+
line = $stdin.gets.chomp
|
38
|
+
line = creds[i] if line.empty? and creds.size > i
|
39
|
+
f.puts line if not line.empty?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
def read_credentials
|
44
|
+
creds = []
|
45
|
+
File.open(@conf) { |f| f.each_line { |l| creds << l.chomp } } if File.exists?(@conf)
|
46
|
+
creds
|
47
|
+
end
|
48
|
+
private
|
49
|
+
def to_hash array
|
50
|
+
Hash[array.collect { |i| [i["key"].to_sym, i["value"]] }]
|
51
|
+
end
|
52
|
+
def load_credentials
|
53
|
+
credentials = read_credentials
|
54
|
+
return credentials if credentials.size >= 2
|
55
|
+
update_configuration credentials
|
56
|
+
read_credentials
|
57
|
+
end
|
58
|
+
def initialize
|
59
|
+
@conf = ENV['awssecret'] || "#{ENV['HOME']}/.awssecret"
|
60
|
+
credentials = load_credentials
|
61
|
+
ENV['EC2_URL'] = credentials[2] if credentials.size >= 3
|
62
|
+
require 'AWS' # *must* load AWS after setting EC2_URL
|
63
|
+
@ec2 = AWS::EC2::Base.new access_key_id: credentials[0],
|
64
|
+
secret_access_key: credentials[1]
|
65
|
+
end
|
66
|
+
def method_missing method, *args, &block
|
67
|
+
puts "Usage: action parameters...", "available actions:"
|
68
|
+
awesome_print (public_methods - "".public_methods)
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/ec2l/version.rb
ADDED
data/test/test_ec2l.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'ec2l'
|
4
|
+
class EC2lTest < Test::Unit::TestCase
|
5
|
+
def test_initialize
|
6
|
+
conf = Tempfile.new "a"
|
7
|
+
conf.write "a\nb\n"
|
8
|
+
conf.close
|
9
|
+
ENV['awssecret'] = conf.path
|
10
|
+
client = Ec2l::Client.new
|
11
|
+
end
|
12
|
+
def test_configuration
|
13
|
+
client = test_initialize
|
14
|
+
def $stdin.gets() 'same_old' end
|
15
|
+
client.update_configuration
|
16
|
+
creds = client.read_credentials
|
17
|
+
assert creds.size == 3
|
18
|
+
creds.each { |cred| assert cred == 'same_old' }
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ec2l
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- yazgoo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: amazon-ec2
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: awesome_print
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: a convenience wrapper for EC2 apis
|
95
|
+
email:
|
96
|
+
- yazgoo@github.com
|
97
|
+
executables:
|
98
|
+
- ec2l
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- bin/ec2l
|
109
|
+
- ec2l.gemspec
|
110
|
+
- lib/ec2l.rb
|
111
|
+
- lib/ec2l/version.rb
|
112
|
+
- test/test_ec2l.rb
|
113
|
+
homepage: ''
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: 3534822186710217201
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: 3534822186710217201
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.23
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: a convenience wrapper for EC2 apis
|
144
|
+
test_files:
|
145
|
+
- test/test_ec2l.rb
|