okiess-ec2-instance-manager 0.1.0
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/bin/ec2_instance_manager +7 -0
- data/config.yml.sample +24 -0
- data/ec2-instance-manager.gemspec +58 -0
- data/lib/ec2_instance_manager.rb +89 -0
- data/lib/ec2_methods.rb +72 -0
- data/test/ec2-instance-manager_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +76 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Oliver Kiessler
|
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,23 @@
|
|
1
|
+
= ec2-instance-manager
|
2
|
+
|
3
|
+
Simple EC2 Instance Manager that is able to work with multiple AWS accounts (in config.yml). See config.yml.sample.
|
4
|
+
|
5
|
+
Create a "config.yml" in the current directory and run "ec2_instance_manager". You can launch instances, assign public IP's and
|
6
|
+
attach volumes.
|
7
|
+
|
8
|
+
This gem should be considered ALPHA! More features to come...
|
9
|
+
|
10
|
+
== Note on Patches/Pull Requests
|
11
|
+
|
12
|
+
* Fork the project.
|
13
|
+
* Make your feature addition or bug fix.
|
14
|
+
* Add tests for it. This is important so I don't break it in a
|
15
|
+
future version unintentionally.
|
16
|
+
* Commit, do not mess with rakefile, version, or history.
|
17
|
+
(if you want to have your own version, that is fine but
|
18
|
+
bump version in a commit by itself I can ignore when I pull)
|
19
|
+
* Send me a pull request. Bonus points for topic branches.
|
20
|
+
|
21
|
+
== Copyright
|
22
|
+
|
23
|
+
Copyright (c) 2009 Oliver Kiessler. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ec2-instance-manager"
|
8
|
+
gem.summary = %Q{Simple EC2 Instance Manager}
|
9
|
+
gem.description = %Q{Launches EC2 instances for multiple AWS accounts}
|
10
|
+
gem.email = "kiessler@inceedo.com"
|
11
|
+
gem.homepage = "http://github.com/okiess/ec2-instance-manager"
|
12
|
+
gem.authors = ["Oliver Kiessler"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "ec2-instance-manager #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/config.yml.sample
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
default:
|
2
|
+
amazon_access_key_id:
|
3
|
+
amazon_secret_access_key:
|
4
|
+
amazon_account_number:
|
5
|
+
key:
|
6
|
+
availability_zone: eu-west-1a
|
7
|
+
instance_type: m1.small
|
8
|
+
|
9
|
+
customer1:
|
10
|
+
amazon_access_key_id:
|
11
|
+
amazon_secret_access_key:
|
12
|
+
amazon_account_number:
|
13
|
+
key:
|
14
|
+
availability_zone: eu-west-1a
|
15
|
+
instance_type: m1.small
|
16
|
+
|
17
|
+
customer2:
|
18
|
+
amazon_access_key_id:
|
19
|
+
amazon_secret_access_key:
|
20
|
+
amazon_account_number:
|
21
|
+
key:
|
22
|
+
availability_zone: eu-west-1a
|
23
|
+
instance_type: m1.small
|
24
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ec2-instance-manager}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Oliver Kiessler"]
|
12
|
+
s.date = %q{2009-09-11}
|
13
|
+
s.default_executable = %q{ec2_instance_manager}
|
14
|
+
s.description = %q{Launches EC2 instances for multiple AWS accounts}
|
15
|
+
s.email = %q{kiessler@inceedo.com}
|
16
|
+
s.executables = ["ec2_instance_manager"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/ec2_instance_manager",
|
29
|
+
"config.yml.sample",
|
30
|
+
"ec2-instance-manager.gemspec",
|
31
|
+
"lib/ec2_instance_manager.rb",
|
32
|
+
"lib/ec2_methods.rb",
|
33
|
+
"test/ec2-instance-manager_test.rb",
|
34
|
+
"test/test_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/okiess/ec2-instance-manager}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{Simple EC2 Instance Manager}
|
41
|
+
s.test_files = [
|
42
|
+
"test/ec2-instance-manager_test.rb",
|
43
|
+
"test/test_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
gem 'amazon-ec2'
|
5
|
+
require 'AWS'
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/ec2_methods'
|
8
|
+
|
9
|
+
class Ec2InstanceManager
|
10
|
+
include Ec2Methods
|
11
|
+
VERSION = '0.1'
|
12
|
+
|
13
|
+
attr_reader :options, :config, :customer_key
|
14
|
+
|
15
|
+
def initialize(arguments, stdin)
|
16
|
+
@arguments = arguments
|
17
|
+
@stdin = stdin
|
18
|
+
@config = YAML.load(File.read("config.yml"))
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
puts "EC2 Instance Manager"
|
23
|
+
puts
|
24
|
+
puts "Which customer config do you want to use? (#{@config.keys.join(", ")})"
|
25
|
+
@customer_key = gets
|
26
|
+
@customer_key = @customer_key.rstrip.lstrip
|
27
|
+
@customer_key = 'default' if @customer_key.empty?
|
28
|
+
|
29
|
+
@ec2 = AWS::EC2::Base.new(:access_key_id => @config[@customer_key]['amazon_access_key_id'],
|
30
|
+
:secret_access_key => @config[@customer_key]['amazon_secret_access_key'])
|
31
|
+
|
32
|
+
puts "Configuration: #{@customer_key}"
|
33
|
+
puts "AMAZON_ACCESS_KEY_ID: #{@config[@customer_key]['amazon_access_key_id']}"
|
34
|
+
puts "KEY: #{@config[@customer_key]['key']}"
|
35
|
+
puts "ZONE: #{@config[@customer_key]['availability_zone']}"
|
36
|
+
puts
|
37
|
+
|
38
|
+
status_info
|
39
|
+
|
40
|
+
puts
|
41
|
+
puts "Which AMI Id do you want to launch?"
|
42
|
+
ami_id = gets
|
43
|
+
ami_id = ami_id.lstrip.rstrip
|
44
|
+
|
45
|
+
result = @ec2.run_instances(
|
46
|
+
:image_id => ami_id,
|
47
|
+
:instance_type => @config[@customer_key]['instance_type'],
|
48
|
+
:key_name => @config[@customer_key]['key'],
|
49
|
+
:availability_zone => @config[@customer_key]['availability_zone']
|
50
|
+
)
|
51
|
+
|
52
|
+
instance_id = result.instancesSet.item[0].instanceId
|
53
|
+
puts "=> Starting Instance Id: #{instance_id}"
|
54
|
+
puts
|
55
|
+
|
56
|
+
instance_state = nil
|
57
|
+
while(instance_state != 'running')
|
58
|
+
instance_state, dns_name = get_instance_state(instance_id)
|
59
|
+
puts "=> Checking for running state... #{instance_state}"
|
60
|
+
puts "=> Public DNS: #{dns_name}" if instance_state == 'running'
|
61
|
+
sleep 10 unless instance_state == 'running'
|
62
|
+
end
|
63
|
+
|
64
|
+
puts
|
65
|
+
|
66
|
+
puts "Do you want to associate a public IP? (leave empty if not)"
|
67
|
+
public_ip = gets
|
68
|
+
|
69
|
+
if not public_ip.empty? and public_ip.size > 1
|
70
|
+
puts "Associating public IP address... #{public_ip}"
|
71
|
+
result = @ec2.associate_address(:instance_id => instance_id, :public_ip => public_ip.lstrip.rstrip)
|
72
|
+
if result["return"] == "true"
|
73
|
+
puts "=> Success."
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
puts
|
78
|
+
puts "Please enter your volume id (leave empty if you don't want to attach a volume):"
|
79
|
+
volume_id = gets
|
80
|
+
|
81
|
+
if not volume_id.empty? and volume_id.size > 1
|
82
|
+
puts "Attaching volume... #{volume_id}"
|
83
|
+
result = @ec2.attach_volume(:volume_id => volume_id.lstrip.rstrip, :instance_id => instance_id, :device => '/dev/sdf')
|
84
|
+
if result["return"] == "true"
|
85
|
+
puts "=> Success."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/ec2_methods.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Ec2Methods
|
2
|
+
def get_instance_state(instance_id)
|
3
|
+
result = @ec2.describe_instances(:instance_id => instance_id)
|
4
|
+
instance_state = result["reservationSet"]["item"].first["instancesSet"]["item"].first["instanceState"]["name"]
|
5
|
+
dns_name = result["reservationSet"]["item"].first["instancesSet"]["item"].first["dnsName"]
|
6
|
+
return instance_state, dns_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def display_ami_ids(owner_id = nil)
|
10
|
+
result = @ec2.describe_images(:owner_id => owner_id || @config[@customer_key]['amazon_account_number'])
|
11
|
+
if result and result["imagesSet"]
|
12
|
+
result["imagesSet"]["item"].each {|image| puts "#{image["imageId"]} - #{image["imageLocation"]}"}
|
13
|
+
else
|
14
|
+
puts "No images."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def display_instances
|
19
|
+
result = @ec2.describe_instances
|
20
|
+
if result and result["reservationSet"]
|
21
|
+
result["reservationSet"]["item"].each do |item|
|
22
|
+
instance_id = item["instancesSet"]["item"].first["instanceId"]
|
23
|
+
ami_id = item["instancesSet"]["item"].first["imageId"]
|
24
|
+
running_state = item["instancesSet"]["item"].first["instanceState"]["name"]
|
25
|
+
dns_name = item["instancesSet"]["item"].first["dnsName"]
|
26
|
+
puts "Instance Id: #{instance_id} - #{running_state} (AMI Id: #{ami_id}) #{dns_name}"
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "No instances."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def display_addresses
|
34
|
+
result = @ec2.describe_addresses
|
35
|
+
if result and result["addressesSet"]
|
36
|
+
result["addressesSet"]["item"].each do |ip|
|
37
|
+
puts "#{ip["publicIp"]} => #{ip["instanceId"].nil? ? 'unassigned' : ip["instanceId"]}"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts "No addresses."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def display_volumes
|
45
|
+
result = @ec2.describe_volumes
|
46
|
+
if result and result["volumeSet"]
|
47
|
+
result["volumeSet"]["item"].each do |vol|
|
48
|
+
instance_id = nil
|
49
|
+
if vol["attachmentSet"]
|
50
|
+
instance_id = vol["attachmentSet"]["item"].first["instanceId"]
|
51
|
+
end
|
52
|
+
puts "#{vol["volumeId"]} (Size: #{vol["size"]} / Zone: #{vol["availabilityZone"]}) - #{vol["status"]} => #{instance_id.nil? ? 'unassigned' : instance_id}"
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "No volumes."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def status_info
|
60
|
+
puts "Fetching information about your instances..."
|
61
|
+
display_instances
|
62
|
+
puts
|
63
|
+
puts "Fetching your registered private AMI Id's..."
|
64
|
+
display_ami_ids
|
65
|
+
puts
|
66
|
+
puts "Fetching information about your public IP's..."
|
67
|
+
display_addresses
|
68
|
+
puts
|
69
|
+
puts "Fetching information about your volumes..."
|
70
|
+
display_volumes
|
71
|
+
end
|
72
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: okiess-ec2-instance-manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Kiessler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
|
+
default_executable: ec2_instance_manager
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Launches EC2 instances for multiple AWS accounts
|
26
|
+
email: kiessler@inceedo.com
|
27
|
+
executables:
|
28
|
+
- ec2_instance_manager
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bin/ec2_instance_manager
|
42
|
+
- config.yml.sample
|
43
|
+
- ec2-instance-manager.gemspec
|
44
|
+
- lib/ec2_instance_manager.rb
|
45
|
+
- lib/ec2_methods.rb
|
46
|
+
- test/ec2-instance-manager_test.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
has_rdoc: false
|
49
|
+
homepage: http://github.com/okiess/ec2-instance-manager
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Simple EC2 Instance Manager
|
74
|
+
test_files:
|
75
|
+
- test/ec2-instance-manager_test.rb
|
76
|
+
- test/test_helper.rb
|