ec2_tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/ec2_tools/config.rb +30 -0
- data/lib/ec2_tools/ec2.rb +23 -0
- data/lib/ec2_tools.rb +17 -0
- data/spec/ec2_tools/config_spec.rb +66 -0
- data/spec/ec2_tools/ec2_spec.rb +4 -0
- data/spec/ec2_tools_spec.rb +18 -0
- data/spec/spec_helper.rb +12 -0
- metadata +131 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
amazon-ec2 (0.9.17)
|
5
|
+
xml-simple (>= 1.0.12)
|
6
|
+
diff-lcs (1.1.2)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.5.2)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rake (0.8.7)
|
13
|
+
rcov (0.9.9)
|
14
|
+
rspec (2.1.0)
|
15
|
+
rspec-core (~> 2.1.0)
|
16
|
+
rspec-expectations (~> 2.1.0)
|
17
|
+
rspec-mocks (~> 2.1.0)
|
18
|
+
rspec-core (2.1.0)
|
19
|
+
rspec-expectations (2.1.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.1.0)
|
22
|
+
xml-simple (1.0.12)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
amazon-ec2
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
jeweler (~> 1.5.1)
|
31
|
+
rcov
|
32
|
+
rspec (~> 2.1.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Yamada Masaki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= ec2_tools
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to ec2_tools
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Yamada Masaki. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "ec2_tools"
|
16
|
+
gem.homepage = "http://github.com/masarakki/ec2_tools"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{ec2 manage commands}
|
19
|
+
gem.description = %Q{ec2 manage commands}
|
20
|
+
gem.email = "masaki@hisme.net"
|
21
|
+
gem.authors = ["Yamada Masaki"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "ec2_tools #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ec2Tools::Config
|
2
|
+
class FileNotFoundError < StandardError ; end
|
3
|
+
class InvalidConfigError < StandardError ; end
|
4
|
+
require 'yaml'
|
5
|
+
attr_reader :access_key_id, :secret_access_key, :server
|
6
|
+
|
7
|
+
def self.load(file = nil)
|
8
|
+
file = search_config_file if file.nil?
|
9
|
+
raise FileNotFoundError unless File.exists?(file)
|
10
|
+
data = YAML.load_file(file)
|
11
|
+
|
12
|
+
raise InvalidConfigError.new("config file must contain key, secret, server") unless valid_config?(data)
|
13
|
+
|
14
|
+
{ :access_key_id => data['key'],
|
15
|
+
:secret_access_key => data['secret'],
|
16
|
+
:server => data['server'] }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def self.search_config_file
|
21
|
+
["config/amazon_ec2.yml", ".account.yml"].each do |file|
|
22
|
+
return file if File.exists?(file)
|
23
|
+
end
|
24
|
+
raise FileNotFoundError
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.valid_config?(data)
|
28
|
+
data.has_key?('key') && data.has_key?('secret') && data.has_key?('server')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'AWS'
|
2
|
+
|
3
|
+
class Ec2Tools::EC2 < AWS::EC2::Base
|
4
|
+
def initialize(config)
|
5
|
+
@config = config
|
6
|
+
end
|
7
|
+
|
8
|
+
def servers
|
9
|
+
unless @servers
|
10
|
+
@servers = {}
|
11
|
+
describe_instances.reservationSet.item.each do |reservation|
|
12
|
+
reservation.instanceSet.item.each do |instance|
|
13
|
+
if instance.instanceState.name == "running"
|
14
|
+
key = instnacekeyName.to_sym
|
15
|
+
@servers[key] = [] if @servers[key].nil?
|
16
|
+
@servers[key] << instance
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@servers
|
22
|
+
end
|
23
|
+
end
|
data/lib/ec2_tools.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Ec2Tools
|
2
|
+
autoload :EC2, 'ec2_tools/ec2'
|
3
|
+
autoload :Config, 'ec2_tools/config'
|
4
|
+
|
5
|
+
@ec2 = nil
|
6
|
+
|
7
|
+
def initialize(config_file = nil)
|
8
|
+
@ec2 = EC2.new(Config.load(config_file))
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(name, *args)
|
12
|
+
define_method(:name) do |_args|
|
13
|
+
@ec2.send(name, _args)
|
14
|
+
end
|
15
|
+
self.send(name, args)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Ec2Tools::Config do
|
4
|
+
describe ".load" do
|
5
|
+
before do
|
6
|
+
yml =<<YAML
|
7
|
+
key: hage
|
8
|
+
secret: hige
|
9
|
+
server: huga
|
10
|
+
YAML
|
11
|
+
@config = YAML.load(yml)
|
12
|
+
@result = { :access_key_id => 'hage', :secret_access_key => 'hige', :server => 'huga' }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "file not found" do
|
16
|
+
it "raise FileNotFoundError" do
|
17
|
+
lambda{
|
18
|
+
Ec2Tools::Config.load('unkounkounko')
|
19
|
+
}.should raise_error(Ec2Tools::Config::FileNotFoundError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "invalid config" do
|
24
|
+
it "raise InvalidConfigError" do
|
25
|
+
File.stub(:exists?) { true }
|
26
|
+
Ec2Tools::Config.stub(:search_config_file) { 'ec2.yml' }
|
27
|
+
YAML.stub(:load_file) { {'unko' => 'unko'} }
|
28
|
+
lambda{
|
29
|
+
Ec2Tools::Config.load
|
30
|
+
}.should raise_error(Ec2Tools::Config::InvalidConfigError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with filename" do
|
35
|
+
it "load from specified file" do
|
36
|
+
File.stub(:exists?) { true }
|
37
|
+
Ec2Tools::Config.should_not_receive(:search_config_file)
|
38
|
+
YAML.should_receive(:load_file).with('config/hoge.yml') { @config }
|
39
|
+
Ec2Tools::Config.load('config/hoge.yml').should eq(@result)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "without filename" do
|
44
|
+
it "search default config file" do
|
45
|
+
File.stub(:exists?) { true }
|
46
|
+
Ec2Tools::Config.should_receive(:search_config_file) { 'config/amazon_ec2.yml' }
|
47
|
+
YAML.should_receive(:load_file).with('config/amazon_ec2.yml') { @config }
|
48
|
+
Ec2Tools::Config.load.should eq(@result)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".search_config_file" do
|
54
|
+
it "search files by order" do
|
55
|
+
File.should_receive(:exists?).with("config/amazon_ec2.yml").ordered { false }
|
56
|
+
File.should_receive(:exists?).with(".account.yml").ordered { true }
|
57
|
+
Ec2Tools::Config.send(:search_config_file).should eq(".account.yml")
|
58
|
+
end
|
59
|
+
it "raise FileNotFoundError if no file exists" do
|
60
|
+
File.stub(:exists?) { false }
|
61
|
+
lambda{
|
62
|
+
Ec2Tools::Config.send(:search_config_file)
|
63
|
+
}.should raise_error(Ec2Tools::Config::FileNotFoundError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Ec2Tools do
|
4
|
+
describe "#initialize" do
|
5
|
+
before do
|
6
|
+
@conf = { :hoge => 'hage' }
|
7
|
+
end
|
8
|
+
it "load config and create ec2 instance with config" do
|
9
|
+
ec2 = mock(Ec2Tools::EC2)
|
10
|
+
Ec2Tools::Config.should_receive(:load) { @conf }
|
11
|
+
Ec2Tools::EC2.should_receive(:new).with(@conf) { ec2 }
|
12
|
+
Ec2Tools.new.instance_variable_get(:@ec2).should eq(ec2)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# et.keys
|
17
|
+
# et.servers(:key).map(:private_ip)
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'ec2_tools'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ec2_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yamada Masaki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-06 00:00:00 +09:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: amazon-ec2
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.1.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.5.1
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rcov
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
description: ec2 manage commands
|
72
|
+
email: masaki@hisme.net
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files:
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.rdoc
|
80
|
+
files:
|
81
|
+
- .document
|
82
|
+
- .rspec
|
83
|
+
- Gemfile
|
84
|
+
- Gemfile.lock
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.rdoc
|
87
|
+
- Rakefile
|
88
|
+
- VERSION
|
89
|
+
- lib/ec2_tools.rb
|
90
|
+
- lib/ec2_tools/config.rb
|
91
|
+
- lib/ec2_tools/ec2.rb
|
92
|
+
- spec/ec2_tools/config_spec.rb
|
93
|
+
- spec/ec2_tools/ec2_spec.rb
|
94
|
+
- spec/ec2_tools_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
has_rdoc: true
|
97
|
+
homepage: http://github.com/masarakki/ec2_tools
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 848125999
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.5.0
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: ec2 manage commands
|
127
|
+
test_files:
|
128
|
+
- spec/ec2_tools/config_spec.rb
|
129
|
+
- spec/ec2_tools/ec2_spec.rb
|
130
|
+
- spec/ec2_tools_spec.rb
|
131
|
+
- spec/spec_helper.rb
|