geemus-fog 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +94 -0
- data/VERSION +1 -0
- data/benchs/fog_vs.rb +76 -0
- data/benchs/headers_split_vs_match.rb +18 -0
- data/benchs/params.rb +43 -0
- data/benchs/parse_vs_push.rb +60 -0
- data/benchs/stripping.rb +26 -0
- data/lib/fog/aws/ec2.rb +159 -0
- data/lib/fog/aws/parsers/ec2/allocate_address.rb +19 -0
- data/lib/fog/aws/parsers/ec2/attach_volume.rb +22 -0
- data/lib/fog/aws/parsers/ec2/basic.rb +25 -0
- data/lib/fog/aws/parsers/ec2/create_key_pair.rb +20 -0
- data/lib/fog/aws/parsers/ec2/create_snapshot.rb +22 -0
- data/lib/fog/aws/parsers/ec2/create_volume.rb +24 -0
- data/lib/fog/aws/parsers/ec2/describe_addresses.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_availability_zones.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_images.rb +49 -0
- data/lib/fog/aws/parsers/ec2/describe_instances.rb +73 -0
- data/lib/fog/aws/parsers/ec2/describe_key_pairs.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_regions.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_security_groups.rb +75 -0
- data/lib/fog/aws/parsers/ec2/describe_snapshots.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_volumes.rb +57 -0
- data/lib/fog/aws/parsers/ec2/detach_volume.rb +22 -0
- data/lib/fog/aws/parsers/ec2/get_console_output.rb +28 -0
- data/lib/fog/aws/parsers/ec2/run_instances.rb +65 -0
- data/lib/fog/aws/parsers/ec2/terminate_instances.rb +55 -0
- data/lib/fog/aws/parsers/s3/copy_object.rb +22 -0
- data/lib/fog/aws/parsers/s3/get_bucket.rb +46 -0
- data/lib/fog/aws/parsers/s3/get_bucket_location.rb +20 -0
- data/lib/fog/aws/parsers/s3/get_request_payment.rb +20 -0
- data/lib/fog/aws/parsers/s3/get_service.rb +32 -0
- data/lib/fog/aws/parsers/simpledb/basic.rb +31 -0
- data/lib/fog/aws/parsers/simpledb/domain_metadata.rb +30 -0
- data/lib/fog/aws/parsers/simpledb/get_attributes.rb +34 -0
- data/lib/fog/aws/parsers/simpledb/list_domains.rb +28 -0
- data/lib/fog/aws/parsers/simpledb/select.rb +39 -0
- data/lib/fog/aws/requests/ec2/allocate_address.rb +50 -0
- data/lib/fog/aws/requests/ec2/associate_address.rb +26 -0
- data/lib/fog/aws/requests/ec2/attach_volume.rb +32 -0
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +32 -0
- data/lib/fog/aws/requests/ec2/create_key_pair.rb +60 -0
- data/lib/fog/aws/requests/ec2/create_security_group.rb +61 -0
- data/lib/fog/aws/requests/ec2/create_snapshot.rb +28 -0
- data/lib/fog/aws/requests/ec2/create_volume.rb +66 -0
- data/lib/fog/aws/requests/ec2/delete_key_pair.rb +49 -0
- data/lib/fog/aws/requests/ec2/delete_security_group.rb +52 -0
- data/lib/fog/aws/requests/ec2/delete_snapshot.rb +24 -0
- data/lib/fog/aws/requests/ec2/delete_volume.rb +55 -0
- data/lib/fog/aws/requests/ec2/describe_addresses.rb +61 -0
- data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +27 -0
- data/lib/fog/aws/requests/ec2/describe_images.rb +41 -0
- data/lib/fog/aws/requests/ec2/describe_instances.rb +48 -0
- data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +63 -0
- data/lib/fog/aws/requests/ec2/describe_regions.rb +26 -0
- data/lib/fog/aws/requests/ec2/describe_security_groups.rb +71 -0
- data/lib/fog/aws/requests/ec2/describe_snapshots.rb +29 -0
- data/lib/fog/aws/requests/ec2/describe_volumes.rb +85 -0
- data/lib/fog/aws/requests/ec2/detach_volume.rb +32 -0
- data/lib/fog/aws/requests/ec2/disassociate_address.rb +24 -0
- data/lib/fog/aws/requests/ec2/get_console_output.rb +26 -0
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +24 -0
- data/lib/fog/aws/requests/ec2/release_address.rb +50 -0
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +32 -0
- data/lib/fog/aws/requests/ec2/run_instances.rb +74 -0
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +31 -0
- data/lib/fog/aws/requests/s3/copy_object.rb +80 -0
- data/lib/fog/aws/requests/s3/delete_bucket.rb +49 -0
- data/lib/fog/aws/requests/s3/delete_object.rb +52 -0
- data/lib/fog/aws/requests/s3/get_bucket.rb +92 -0
- data/lib/fog/aws/requests/s3/get_bucket_location.rb +53 -0
- data/lib/fog/aws/requests/s3/get_object.rb +81 -0
- data/lib/fog/aws/requests/s3/get_request_payment.rb +53 -0
- data/lib/fog/aws/requests/s3/get_service.rb +58 -0
- data/lib/fog/aws/requests/s3/head_object.rb +61 -0
- data/lib/fog/aws/requests/s3/put_bucket.rb +69 -0
- data/lib/fog/aws/requests/s3/put_object.rb +75 -0
- data/lib/fog/aws/requests/s3/put_request_payment.rb +56 -0
- data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +31 -0
- data/lib/fog/aws/requests/simpledb/create_domain.rb +25 -0
- data/lib/fog/aws/requests/simpledb/delete_attributes.rb +34 -0
- data/lib/fog/aws/requests/simpledb/delete_domain.rb +25 -0
- data/lib/fog/aws/requests/simpledb/domain_metadata.rb +30 -0
- data/lib/fog/aws/requests/simpledb/get_attributes.rb +35 -0
- data/lib/fog/aws/requests/simpledb/list_domains.rb +30 -0
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +29 -0
- data/lib/fog/aws/requests/simpledb/select.rb +29 -0
- data/lib/fog/aws/s3.rb +143 -0
- data/lib/fog/aws/simpledb.rb +157 -0
- data/lib/fog/aws.rb +127 -0
- data/lib/fog/connection.rb +122 -0
- data/lib/fog/errors.rb +131 -0
- data/lib/fog/parser.rb +30 -0
- data/lib/fog/response.rb +12 -0
- data/lib/fog.rb +22 -0
- data/spec/aws/ec2/allocate_address_spec.rb +20 -0
- data/spec/aws/ec2/associate_address_spec.rb +22 -0
- data/spec/aws/ec2/attach_volume_spec.rb +33 -0
- data/spec/aws/ec2/authorize_security_group_ingress_spec.rb +25 -0
- data/spec/aws/ec2/create_key_pair_spec.rb +27 -0
- data/spec/aws/ec2/create_security_group_spec.rb +25 -0
- data/spec/aws/ec2/create_snapshot_spec.rb +27 -0
- data/spec/aws/ec2/create_volume_spec.rb +25 -0
- data/spec/aws/ec2/delete_key_pair_spec.rb +20 -0
- data/spec/aws/ec2/delete_security_group_spec.rb +22 -0
- data/spec/aws/ec2/delete_snapshot_spec.rb +25 -0
- data/spec/aws/ec2/delete_volume_spec.rb +22 -0
- data/spec/aws/ec2/describe_addresses_spec.rb +34 -0
- data/spec/aws/ec2/describe_availability_zones_spec.rb +25 -0
- data/spec/aws/ec2/describe_images_spec.rb +41 -0
- data/spec/aws/ec2/describe_instances_spec.rb +76 -0
- data/spec/aws/ec2/describe_key_pairs_spec.rb +38 -0
- data/spec/aws/ec2/describe_regions_spec.rb +23 -0
- data/spec/aws/ec2/describe_security_groups_spec.rb +47 -0
- data/spec/aws/ec2/describe_snapshot_spec.rb +44 -0
- data/spec/aws/ec2/describe_volumes_spec.rb +46 -0
- data/spec/aws/ec2/detach_volume_spec.rb +33 -0
- data/spec/aws/ec2/disassociate_address_spec.rb +23 -0
- data/spec/aws/ec2/get_console_output_spec.rb +22 -0
- data/spec/aws/ec2/reboot_instances_spec.rb +20 -0
- data/spec/aws/ec2/release_address_spec.rb +22 -0
- data/spec/aws/ec2/revoke_security_group_ingress_spec.rb +31 -0
- data/spec/aws/ec2/run_instances_spec.rb +43 -0
- data/spec/aws/ec2/terminate_instances_spec.rb +25 -0
- data/spec/aws/s3/copy_object_spec.rb +57 -0
- data/spec/aws/s3/delete_bucket_spec.rb +21 -0
- data/spec/aws/s3/delete_object_spec.rb +31 -0
- data/spec/aws/s3/get_bucket_location_spec.rb +30 -0
- data/spec/aws/s3/get_bucket_spec.rb +42 -0
- data/spec/aws/s3/get_object_spec.rb +40 -0
- data/spec/aws/s3/get_request_payment_spec.rb +26 -0
- data/spec/aws/s3/get_service_spec.rb +32 -0
- data/spec/aws/s3/head_object_spec.rb +27 -0
- data/spec/aws/s3/put_bucket_spec.rb +22 -0
- data/spec/aws/s3/put_object_spec.rb +34 -0
- data/spec/aws/s3/put_request_payment_spec.rb +25 -0
- data/spec/aws/simpledb/batch_put_attributes_spec.rb +21 -0
- data/spec/aws/simpledb/create_domain_spec.rb +20 -0
- data/spec/aws/simpledb/delete_attributes_spec.rb +21 -0
- data/spec/aws/simpledb/delete_domain_spec.rb +20 -0
- data/spec/aws/simpledb/domain_metadata_spec.rb +42 -0
- data/spec/aws/simpledb/get_attributes_spec.rb +30 -0
- data/spec/aws/simpledb/list_domains_spec.rb +29 -0
- data/spec/aws/simpledb/put_attributes_spec.rb +21 -0
- data/spec/aws/simpledb/select_spec.rb +7 -0
- data/spec/lorem.txt +1 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +74 -0
- metadata +256 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wesley Beary
|
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
data/Rakefile
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
current_directory = File.dirname(__FILE__)
|
5
|
+
require "#{current_directory}/lib/fog"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "fog"
|
11
|
+
gem.summary = %Q{brings clouds to you}
|
12
|
+
gem.email = "me@geemus.com"
|
13
|
+
gem.homepage = "http://github.com/geemus/fog"
|
14
|
+
gem.authors = ["Wesley Beary"]
|
15
|
+
gem.rubyforge_project = "fog"
|
16
|
+
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_opts = ['-c']
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :specs do
|
37
|
+
|
38
|
+
task :with_mocking do
|
39
|
+
Fog.mocking = true
|
40
|
+
Rake::Task[:spec].invoke
|
41
|
+
end
|
42
|
+
|
43
|
+
task :without_mocking do
|
44
|
+
Fog.mocking = true
|
45
|
+
Rake::Task[:spec].invoke
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Run specs with and without mocking'
|
51
|
+
task :specs => %w[ specs:with_mocking specs:without_mocking ]
|
52
|
+
|
53
|
+
task :default => :specs
|
54
|
+
|
55
|
+
require 'rake/rdoctask'
|
56
|
+
Rake::RDocTask.new do |rdoc|
|
57
|
+
if File.exist?('VERSION.yml')
|
58
|
+
config = YAML.load(File.read('VERSION.yml'))
|
59
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
60
|
+
else
|
61
|
+
version = ""
|
62
|
+
end
|
63
|
+
|
64
|
+
rdoc.rdoc_dir = 'rdoc'
|
65
|
+
rdoc.title = "fog #{version}"
|
66
|
+
rdoc.rdoc_files.include('README*')
|
67
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
require 'rake/contrib/sshpublisher'
|
72
|
+
namespace :rubyforge do
|
73
|
+
|
74
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
75
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
76
|
+
|
77
|
+
namespace :release do
|
78
|
+
desc "Publish RDoc to RubyForge."
|
79
|
+
task :docs => [:rdoc] do
|
80
|
+
config = YAML.load(
|
81
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
82
|
+
)
|
83
|
+
|
84
|
+
host = "#{config['username']}@rubyforge.org"
|
85
|
+
remote_dir = "/var/www/gforge-projects/fog/"
|
86
|
+
local_dir = 'rdoc'
|
87
|
+
|
88
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
rescue LoadError
|
93
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
94
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/benchs/fog_vs.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'right_aws'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
require 'fog/aws'
|
7
|
+
|
8
|
+
data = File.open(File.expand_path('~/.s3conf/s3config.yml')).read
|
9
|
+
config = YAML.load(data)
|
10
|
+
fog = Fog::AWS::S3.new(
|
11
|
+
:aws_access_key_id => config['aws_access_key_id'],
|
12
|
+
:aws_secret_access_key => config['aws_secret_access_key']
|
13
|
+
)
|
14
|
+
raws = RightAws::S3Interface.new(
|
15
|
+
config['aws_access_key_id'],
|
16
|
+
config['aws_secret_access_key']
|
17
|
+
)
|
18
|
+
raws.logger.level = 3 # ERROR
|
19
|
+
|
20
|
+
TIMES = 10
|
21
|
+
|
22
|
+
Benchmark.bmbm(25) do |bench|
|
23
|
+
bench.report('fog.put_bucket') do
|
24
|
+
TIMES.times do |x|
|
25
|
+
fog.put_bucket("fogbench#{x}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
bench.report('raws.create_bucket') do
|
29
|
+
TIMES.times do |x|
|
30
|
+
raws.create_bucket("rawsbench#{x}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
bench.report('fog.put_object') do
|
35
|
+
TIMES.times do |x|
|
36
|
+
TIMES.times do |y|
|
37
|
+
file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
|
38
|
+
fog.put_object("fogbench#{x}", "lorem_#{y}", file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
bench.report('raws.put') do
|
43
|
+
TIMES.times do |x|
|
44
|
+
TIMES.times do |y|
|
45
|
+
file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
|
46
|
+
raws.put("rawsbench#{x}", "lorem_#{y}", file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
bench.report('fog.delete_object') do
|
52
|
+
TIMES.times do |x|
|
53
|
+
TIMES.times do |y|
|
54
|
+
fog.delete_object("fogbench#{x}", "lorem_#{y}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
bench.report('raws.delete') do
|
59
|
+
TIMES.times do |x|
|
60
|
+
TIMES.times do |y|
|
61
|
+
raws.delete("rawsbench#{x}", "lorem_#{y}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
bench.report('fog.delete_bucket') do
|
67
|
+
TIMES.times do |x|
|
68
|
+
fog.delete_bucket("fogbench#{x}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
bench.report('raws.delete_bucket') do
|
72
|
+
TIMES.times do |x|
|
73
|
+
raws.delete_bucket("rawsbench#{x}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
COUNT = 1000
|
4
|
+
data = "Content-Length: 100"
|
5
|
+
Benchmark.bmbm(25) do |bench|
|
6
|
+
bench.report('regex') do
|
7
|
+
COUNT.times do
|
8
|
+
header = data.match(/(.*):\s(.*)/)
|
9
|
+
"#{header[1]}: #{header[2]}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
bench.report('split') do
|
13
|
+
COUNT.times do
|
14
|
+
header = data.split(': ')
|
15
|
+
"#{header[0]}: #{header[1]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/benchs/params.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
def hash(options)
|
4
|
+
result = "#{options.delete(:name)}"
|
5
|
+
for key, value in options
|
6
|
+
result << " #{key} => #{value} "
|
7
|
+
end
|
8
|
+
result
|
9
|
+
end
|
10
|
+
|
11
|
+
def optional(name, a = nil, b = nil, c = nil)
|
12
|
+
result = "#{name}"
|
13
|
+
options = { :a => a, :b => b, :c => c }
|
14
|
+
for key, value in options
|
15
|
+
result << " #{key} => #{value} "
|
16
|
+
end
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
COUNT = 100_000
|
21
|
+
data = "Content-Length: 100"
|
22
|
+
Benchmark.bmbm(25) do |bench|
|
23
|
+
bench.report('hash') do
|
24
|
+
COUNT.times do
|
25
|
+
hash({:name => 'name'})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
bench.report('optional') do
|
29
|
+
COUNT.times do
|
30
|
+
optional('name')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
bench.report('hash_with_option') do
|
34
|
+
COUNT.times do
|
35
|
+
hash({:name => 'name', :a => 'a', :b => 'b', :c => 'c'})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
bench.report('optional_with_option') do
|
39
|
+
COUNT.times do
|
40
|
+
optional('name', :a => 'a', :b => 'b', :c => 'c')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class Parser < Nokogiri::XML::SAX::Document
|
6
|
+
|
7
|
+
attr_reader :response
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset
|
14
|
+
@item = {}
|
15
|
+
@response = { :items => [] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def characters(string)
|
19
|
+
@value << string.strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def start_element(name, attrs = [])
|
23
|
+
@value = ''
|
24
|
+
end
|
25
|
+
|
26
|
+
def end_element(name)
|
27
|
+
case name
|
28
|
+
when 'item'
|
29
|
+
@response[:items] << @item
|
30
|
+
@item = {}
|
31
|
+
when 'key'
|
32
|
+
@item[:key] = @value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
data = <<-DATA
|
39
|
+
<items>
|
40
|
+
<item>
|
41
|
+
<key>value</key>
|
42
|
+
</item>
|
43
|
+
</items>
|
44
|
+
DATA
|
45
|
+
|
46
|
+
COUNT = 100
|
47
|
+
|
48
|
+
Benchmark.bmbm(25) do |bench|
|
49
|
+
bench.report('parse') do
|
50
|
+
parser = Parser.new
|
51
|
+
Nokogiri::XML::SAX::Parser.new(parser).parse(data)
|
52
|
+
parser.response
|
53
|
+
end
|
54
|
+
|
55
|
+
bench.report('push') do
|
56
|
+
parser = Parser.new
|
57
|
+
Nokogiri::XML::SAX::PushParser.new(parser).write(data, true)
|
58
|
+
parser.response
|
59
|
+
end
|
60
|
+
end
|
data/benchs/stripping.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
COUNT = 1_000_000
|
4
|
+
data = "Content-Length: 100\r\n"
|
5
|
+
Benchmark.bmbm(25) do |bench|
|
6
|
+
bench.report('chomp') do
|
7
|
+
COUNT.times do
|
8
|
+
data.chomp
|
9
|
+
end
|
10
|
+
end
|
11
|
+
bench.report('chop') do
|
12
|
+
COUNT.times do
|
13
|
+
data.chop
|
14
|
+
end
|
15
|
+
end
|
16
|
+
bench.report('strip') do
|
17
|
+
COUNT.times do
|
18
|
+
data.strip
|
19
|
+
end
|
20
|
+
end
|
21
|
+
bench.report('index') do
|
22
|
+
COUNT.times do
|
23
|
+
data[0..-3]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/fog/aws/ec2.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class EC2
|
4
|
+
|
5
|
+
def self.reload
|
6
|
+
current_directory = File.dirname(__FILE__)
|
7
|
+
load "#{current_directory}/../connection.rb"
|
8
|
+
load "#{current_directory}/../parser.rb"
|
9
|
+
load "#{current_directory}/../response.rb"
|
10
|
+
|
11
|
+
parsers_directory = "#{current_directory}/parsers/ec2"
|
12
|
+
load "#{parsers_directory}/allocate_address.rb"
|
13
|
+
load "#{parsers_directory}/attach_volume.rb"
|
14
|
+
load "#{parsers_directory}/basic.rb"
|
15
|
+
load "#{parsers_directory}/create_key_pair.rb"
|
16
|
+
load "#{parsers_directory}/create_snapshot.rb"
|
17
|
+
load "#{parsers_directory}/create_volume.rb"
|
18
|
+
load "#{parsers_directory}/describe_addresses.rb"
|
19
|
+
load "#{parsers_directory}/describe_availability_zones.rb"
|
20
|
+
load "#{parsers_directory}/describe_images.rb"
|
21
|
+
load "#{parsers_directory}/describe_instances.rb"
|
22
|
+
load "#{parsers_directory}/describe_key_pairs.rb"
|
23
|
+
load "#{parsers_directory}/describe_regions.rb"
|
24
|
+
load "#{parsers_directory}/describe_security_groups.rb"
|
25
|
+
load "#{parsers_directory}/describe_snapshots.rb"
|
26
|
+
load "#{parsers_directory}/describe_volumes.rb"
|
27
|
+
load "#{parsers_directory}/detach_volume.rb"
|
28
|
+
load "#{parsers_directory}/get_console_output.rb"
|
29
|
+
load "#{parsers_directory}/run_instances.rb"
|
30
|
+
load "#{parsers_directory}/terminate_instances.rb"
|
31
|
+
|
32
|
+
requests_directory = "#{current_directory}/requests/ec2"
|
33
|
+
load "#{requests_directory}/allocate_address.rb"
|
34
|
+
load "#{requests_directory}/associate_address.rb"
|
35
|
+
load "#{requests_directory}/attach_volume.rb"
|
36
|
+
load "#{requests_directory}/authorize_security_group_ingress.rb"
|
37
|
+
# TODO: require "#{requests_directory}/bundle_instance.rb"
|
38
|
+
# TODO: require "#{requests_directory}/cancel_bundle_task.rb"
|
39
|
+
# TODO: require "#{requests_directory}/confirm_product_instance.rb"
|
40
|
+
load "#{requests_directory}/create_key_pair.rb"
|
41
|
+
load "#{requests_directory}/create_security_group.rb"
|
42
|
+
load "#{requests_directory}/create_snapshot.rb"
|
43
|
+
load "#{requests_directory}/create_volume.rb"
|
44
|
+
load "#{requests_directory}/delete_key_pair.rb"
|
45
|
+
load "#{requests_directory}/delete_security_group.rb"
|
46
|
+
load "#{requests_directory}/delete_snapshot.rb"
|
47
|
+
load "#{requests_directory}/delete_volume.rb"
|
48
|
+
# TODO: require "#{requests_directory}/deregister_image.rb"
|
49
|
+
load "#{requests_directory}/describe_addresses.rb"
|
50
|
+
load "#{requests_directory}/describe_availability_zones.rb"
|
51
|
+
# TODO: require "#{requests_directory}/describe_bundle_tasks.rb"
|
52
|
+
# TODO: require "#{requests_directory}/describe_image_attribute.rb"
|
53
|
+
load "#{requests_directory}/describe_images.rb"
|
54
|
+
load "#{requests_directory}/describe_instances.rb"
|
55
|
+
load "#{requests_directory}/describe_key_pairs.rb"
|
56
|
+
load "#{requests_directory}/describe_regions.rb"
|
57
|
+
# TODO: require "#{requests_directory}/describe_reserved_instances.rb"
|
58
|
+
# TODO: require "#{requests_directory}/describe_reserved_instances_offerings.rb"
|
59
|
+
load "#{requests_directory}/describe_security_groups.rb"
|
60
|
+
load "#{requests_directory}/describe_snapshots.rb"
|
61
|
+
load "#{requests_directory}/describe_volumes.rb"
|
62
|
+
load "#{requests_directory}/detach_volume.rb"
|
63
|
+
load "#{requests_directory}/disassociate_address.rb"
|
64
|
+
load "#{requests_directory}/get_console_output.rb"
|
65
|
+
# TODO: require "#{requests_directory}/modify_image_attribute.rb"
|
66
|
+
# TODO: require "#{requests_directory}/monitor_instances.rb"
|
67
|
+
# TODO: require "#{requests_directory}/purchase_reserved_instances_offering.rb"
|
68
|
+
load "#{requests_directory}/reboot_instances.rb"
|
69
|
+
# TODO: require "#{requests_directory}/register_image.rb"
|
70
|
+
load "#{requests_directory}/release_address.rb"
|
71
|
+
load "#{requests_directory}/revoke_security_group_ingress.rb"
|
72
|
+
load "#{requests_directory}/run_instances.rb"
|
73
|
+
load "#{requests_directory}/terminate_instances.rb"
|
74
|
+
# TODO: require "#{requests_directory}/unmonitor_instances.rb"
|
75
|
+
end
|
76
|
+
|
77
|
+
if Fog.mocking?
|
78
|
+
attr_accessor :data
|
79
|
+
end
|
80
|
+
|
81
|
+
# Initialize connection to EC2
|
82
|
+
#
|
83
|
+
# ==== Notes
|
84
|
+
# options parameter must include values for :aws_access_key_id and
|
85
|
+
# :aws_secret_access_key in order to create a connection
|
86
|
+
#
|
87
|
+
# ==== Examples
|
88
|
+
# sdb = SimpleDB.new(
|
89
|
+
# :aws_access_key_id => your_aws_access_key_id,
|
90
|
+
# :aws_secret_access_key => your_aws_secret_access_key
|
91
|
+
# )
|
92
|
+
#
|
93
|
+
# ==== Parameters
|
94
|
+
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
95
|
+
#
|
96
|
+
# ==== Returns
|
97
|
+
# * EC2 object with connection to aws.
|
98
|
+
def initialize(options={})
|
99
|
+
@aws_access_key_id = options[:aws_access_key_id]
|
100
|
+
@aws_secret_access_key = options[:aws_secret_access_key]
|
101
|
+
@hmac = HMAC::SHA256.new(@aws_secret_access_key)
|
102
|
+
@host = options[:host] || 'ec2.amazonaws.com'
|
103
|
+
@port = options[:port] || 443
|
104
|
+
@scheme = options[:scheme] || 'https'
|
105
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
106
|
+
|
107
|
+
if Fog.mocking?
|
108
|
+
@data = { :deleted_at => {}, :addresses => {}, :key_pairs => {}, :security_groups => {}, :volumes => {} }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def indexed_params(name, params)
|
115
|
+
indexed, index = {}, 1
|
116
|
+
for param in [*params]
|
117
|
+
indexed["#{name}.#{index}"] = param
|
118
|
+
index += 1
|
119
|
+
end
|
120
|
+
indexed
|
121
|
+
end
|
122
|
+
|
123
|
+
def request(params, parser)
|
124
|
+
params.merge!({
|
125
|
+
'AWSAccessKeyId' => @aws_access_key_id,
|
126
|
+
'SignatureMethod' => 'HmacSHA256',
|
127
|
+
'SignatureVersion' => '2',
|
128
|
+
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
129
|
+
'Version' => '2009-04-04'
|
130
|
+
})
|
131
|
+
|
132
|
+
body = ''
|
133
|
+
for key in params.keys.sort
|
134
|
+
unless (value = params[key]).nil?
|
135
|
+
body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
string_to_sign = "POST\n#{@host}\n/\n" << body.chop
|
140
|
+
hmac = @hmac.update(string_to_sign)
|
141
|
+
body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
|
142
|
+
|
143
|
+
response = @connection.request({
|
144
|
+
:body => body,
|
145
|
+
:expects => 200,
|
146
|
+
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
147
|
+
:host => @host,
|
148
|
+
:method => 'POST',
|
149
|
+
:parser => parser
|
150
|
+
})
|
151
|
+
|
152
|
+
response
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
Fog::AWS::EC2.reload
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module EC2
|
5
|
+
|
6
|
+
class AllocateAddress < Fog::Parsers::Base
|
7
|
+
|
8
|
+
def end_element(name)
|
9
|
+
case name
|
10
|
+
when 'publicIp', 'requestId'
|
11
|
+
@response[name] = @value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module EC2
|
5
|
+
|
6
|
+
class AttachVolume < Fog::Parsers::Base
|
7
|
+
|
8
|
+
def end_element(name)
|
9
|
+
case name
|
10
|
+
when 'attachTime'
|
11
|
+
@response[name] = Time.parse(@value)
|
12
|
+
when 'device', 'instanceId', 'requestId', 'status', 'volumeId'
|
13
|
+
@response[name] = @value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module EC2
|
5
|
+
|
6
|
+
class Basic < Fog::Parsers::Base
|
7
|
+
|
8
|
+
def end_element(name)
|
9
|
+
case name
|
10
|
+
when 'requestId'
|
11
|
+
@response[name] = @value
|
12
|
+
when 'return'
|
13
|
+
if @value == 'true'
|
14
|
+
@response[name] = true
|
15
|
+
else
|
16
|
+
@response[name] = false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module EC2
|
5
|
+
|
6
|
+
class CreateKeyPair < Fog::Parsers::Base
|
7
|
+
|
8
|
+
def end_element(name)
|
9
|
+
case name
|
10
|
+
when 'keyFingerprint', 'keyMaterial', 'keyName', 'requestId'
|
11
|
+
@response[name] = @value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module EC2
|
5
|
+
|
6
|
+
class CreateSnapshot < Fog::Parsers::Base
|
7
|
+
|
8
|
+
def end_element(name)
|
9
|
+
case name
|
10
|
+
when 'progress', 'snapshotId', 'status', 'volumeId'
|
11
|
+
@response[name] = @value
|
12
|
+
when 'startTime'
|
13
|
+
@response[name] = Time.parse(@value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fog
|
2
|
+
module Parsers
|
3
|
+
module AWS
|
4
|
+
module EC2
|
5
|
+
|
6
|
+
class CreateVolume < Fog::Parsers::Base
|
7
|
+
|
8
|
+
def end_element(name)
|
9
|
+
case name
|
10
|
+
when 'availabilityZone', 'requestId', 'snapshotId', 'status', 'volumeId'
|
11
|
+
@response[name] = @value
|
12
|
+
when 'createTime'
|
13
|
+
@response[name] = Time.parse(@value)
|
14
|
+
when 'size'
|
15
|
+
@response[name] = @value.to_i
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|