moneypools-right_wrapper 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/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/right_wrapper.rb +146 -0
- data/moneypools-right_wrapper.gemspec +47 -0
- metadata +72 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Zachary Belzer
|
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,21 @@
|
|
1
|
+
= right_wrapper
|
2
|
+
|
3
|
+
A simple wrapper over the right_aws gem to give verbose status output. This is most useful
|
4
|
+
for logging automated tasks at Amazon since it can help track down where something went wrong.
|
5
|
+
|
6
|
+
It also will wait for attachments/detachments and snapshots so you can have a synchronous
|
7
|
+
experience.
|
8
|
+
|
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 future version unintentionally.
|
15
|
+
* Commit, do not mess with rakefile, version, or history.
|
16
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
17
|
+
* Send me a pull request. Bonus points for topic branches.
|
18
|
+
|
19
|
+
== Copyright
|
20
|
+
|
21
|
+
Copyright (c) 2009 Business Logic Corporation. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "moneypools-right_wrapper"
|
8
|
+
gem.summary = %Q{Simple wrapper over the right_aws utility providing verbose output and synchronization}
|
9
|
+
gem.description = %Q{Simple wrapper over the right_aws utility providing verbose output and synchronization}
|
10
|
+
gem.email = "zbelzer@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/moneypools/right_wrapper"
|
12
|
+
gem.authors = ["Zachary Belzer"]
|
13
|
+
gem.add_development_dependency "right_aws"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/*_test.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/*_test.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
if File.exist?('VERSION')
|
48
|
+
version = File.read('VERSION')
|
49
|
+
else
|
50
|
+
version = ""
|
51
|
+
end
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "right_wrapper #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,146 @@
|
|
1
|
+
begin
|
2
|
+
require 'right_aws'
|
3
|
+
rescue LoadError
|
4
|
+
$stderr.puts "This gem requires the right_aws gem. Please verify it is installed"
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
class RightWrapper
|
9
|
+
SNAP_WAIT_TIME = 5
|
10
|
+
AVAILABLE_DEVICES = ("j".."p").map {|x| "/dev/sd#{x}"}.freeze
|
11
|
+
|
12
|
+
attr_accessor :ec2
|
13
|
+
|
14
|
+
def initialize(aws_access_key_id, aws_secret_access_key)
|
15
|
+
@ec2 = RightAws::Ec2.new(aws_access_key_id, aws_secret_access_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_instance(target_instance_id)
|
19
|
+
instances = @ec2.describe_instances([target_instance_id])
|
20
|
+
unless target_instance = instances.first
|
21
|
+
$stderr.puts "Target instance #{target_instance_id} is not up. Cannot complete operation."
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
target_instance
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_instance_by_eip(eip)
|
28
|
+
unless address = @ec2.describe_addresses.detect {|x| x[:public_ip] == eip}
|
29
|
+
puts "No address information found for #{eip}"
|
30
|
+
end
|
31
|
+
|
32
|
+
if instance_id = address[:instance_id]
|
33
|
+
find_instance(instance_id)
|
34
|
+
else
|
35
|
+
puts "No instance currently associated with #{eip}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_volume(target_volume_id)
|
40
|
+
volumes = @ec2.describe_volumes([target_volume_id])
|
41
|
+
unless target_volume = volumes.first
|
42
|
+
$stderr.puts "Target volume #{target_volume_id} is not up. Cannot complete operation."
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
target_volume
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_volumes_by(options)
|
49
|
+
@ec2.describe_volumes.select do |volume|
|
50
|
+
options.to_a.all? { |k, v| volume[k] == v}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def find_snapshots_by(options)
|
55
|
+
@ec2.describe_snapshots.select do |snap|
|
56
|
+
options.to_a.all? { |k, v| snap[k] == v}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_attached_volumes(target_instance)
|
61
|
+
target_instance_id = target_instance[:aws_instance_id] or raise "Can't find instance id of nil"
|
62
|
+
|
63
|
+
all_volumes = @ec2.describe_volumes
|
64
|
+
current_volumes = all_volumes.select {|vol| vol[:aws_instance_id] == target_instance_id && vol[:aws_attachment_status] == "attached"}
|
65
|
+
if current_volumes.size > 0
|
66
|
+
puts "Found the following volumes attached to #{target_instance_id}:"
|
67
|
+
current_volumes.each do |vol|
|
68
|
+
puts "-- #{vol[:aws_id]} attached to #{vol[:aws_device]} on #{vol[:aws_attached_at]}"
|
69
|
+
end
|
70
|
+
else
|
71
|
+
puts "No volumes currently attached to #{target_instance_id}."
|
72
|
+
end
|
73
|
+
|
74
|
+
current_volumes
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_snapshot(target_volume)
|
78
|
+
target_volume_id = target_volume[:aws_id]
|
79
|
+
|
80
|
+
puts "Creating snapshot of #{target_volume_id}"
|
81
|
+
snap_id = @ec2.create_snapshot(target_volume_id)[:aws_id]
|
82
|
+
|
83
|
+
while true
|
84
|
+
snap_data = @ec2.describe_snapshots.detect {|snap| snap[:aws_id] == snap_id}
|
85
|
+
|
86
|
+
puts "-- Progress of snapshot #{snap_id} is #{snap_data[:aws_progress]}."
|
87
|
+
break if snap_data[:aws_status] == "completed"
|
88
|
+
|
89
|
+
sleep SNAP_WAIT_TIME
|
90
|
+
end
|
91
|
+
|
92
|
+
snap_id
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_snapshot(target_snapshot_id)
|
96
|
+
puts "Deleting snapshot #{target_snapshot_id}"
|
97
|
+
@ec2.delete_snapshot(target_snapshot_id)
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_volume(snap_id, volume_size, zone)
|
101
|
+
puts "Creating volume for snapshot #{snap_id}"
|
102
|
+
puts "-- Source volume is #{volume_size}GB"
|
103
|
+
puts "-- Target instance is in the '#{zone}' zone"
|
104
|
+
|
105
|
+
vol_id = @ec2.create_volume(snap_id, volume_size, zone)[:aws_id]
|
106
|
+
wait_for_volume(vol_id, "available")
|
107
|
+
vol_id
|
108
|
+
end
|
109
|
+
|
110
|
+
def attach_volume(volume_id, target_instance, device)
|
111
|
+
puts "Attaching volume #{volume_id} to instance #{target_instance[:aws_instance_id]} on #{device}"
|
112
|
+
@ec2.attach_volume(volume_id, target_instance[:aws_instance_id], device)
|
113
|
+
wait_for_volume(volume_id, "attached")
|
114
|
+
end
|
115
|
+
|
116
|
+
def detach_volume(volume)
|
117
|
+
puts "Detatching volume #{volume[:aws_id]} from #{volume[:device]} on instance #{volume[:aws_instance_id]}"
|
118
|
+
@ec2.detach_volume(volume[:aws_id], volume[:aws_instance_id], volume[:device])
|
119
|
+
wait_for_volume(volume[:aws_id], "available")
|
120
|
+
end
|
121
|
+
|
122
|
+
def delete_volume(volume)
|
123
|
+
puts "Deleting the volume #{volume[:aws_id]}"
|
124
|
+
@ec2.delete_volume(volume[:aws_id])
|
125
|
+
end
|
126
|
+
|
127
|
+
def wait_for_volume(vol_id, status)
|
128
|
+
while true
|
129
|
+
vol_data = @ec2.describe_volumes.detect {|vol| vol[:aws_id] == vol_id}
|
130
|
+
puts "-- Attachment status of volume #{vol_id} is #{vol_data[:aws_attachment_status]}." unless vol_data[:aws_attachment_status].nil?
|
131
|
+
puts "-- AWS Status of volume #{vol_id} is #{vol_data[:aws_status]}"
|
132
|
+
puts "-- Progress of volume #{vol_id} is #{vol_data[:aws_progress]}." unless vol_data[:aws_progress].nil?
|
133
|
+
break if vol_data[:aws_status] == status || vol_data[:aws_attachment_status] == status
|
134
|
+
|
135
|
+
sleep SNAP_WAIT_TIME
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class << self
|
140
|
+
def freeze_xfs(device, &block)
|
141
|
+
system("xfs_freeze -f #{device}")
|
142
|
+
yield
|
143
|
+
system("xfs_freeze -u #{device}")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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{moneypools-right_wrapper}
|
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 = ["Zachary Belzer"]
|
12
|
+
s.date = %q{2009-11-12}
|
13
|
+
s.description = %q{Simple wrapper over the right_aws utility providing verbose output and synchronization}
|
14
|
+
s.email = %q{zbelzer@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/right_wrapper.rb",
|
27
|
+
"moneypools-right_wrapper.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/moneypools/right_wrapper}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Simple wrapper over the right_aws utility providing verbose output and synchronization}
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_development_dependency(%q<right_aws>, [">= 0"])
|
41
|
+
else
|
42
|
+
s.add_dependency(%q<right_aws>, [">= 0"])
|
43
|
+
end
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<right_aws>, [">= 0"])
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moneypools-right_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zachary Belzer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-12 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: right_aws
|
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: Simple wrapper over the right_aws utility providing verbose output and synchronization
|
26
|
+
email: zbelzer@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
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
|
+
- lib/right_wrapper.rb
|
42
|
+
- moneypools-right_wrapper.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/moneypools/right_wrapper
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Simple wrapper over the right_aws utility providing verbose output and synchronization
|
71
|
+
test_files: []
|
72
|
+
|