fog-digitalocean 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.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.document +3 -0
  4. data/.gitignore +30 -0
  5. data/.irbrc +82 -0
  6. data/.rubocop.yml +20 -0
  7. data/.rubocop_todo.yml +606 -0
  8. data/.travis.yml +35 -0
  9. data/CHANGELOG.md +3 -0
  10. data/CONTRIBUTING.md +276 -0
  11. data/CONTRIBUTORS.md +898 -0
  12. data/Gemfile +5 -0
  13. data/LICENSE.md +20 -0
  14. data/README.md +130 -0
  15. data/RELEASE.md +40 -0
  16. data/Rakefile +12 -0
  17. data/benchs/each_provider.sh +6 -0
  18. data/benchs/each_service.sh +6 -0
  19. data/benchs/fog_vs.rb +106 -0
  20. data/benchs/load_times.rb +37 -0
  21. data/benchs/params.rb +43 -0
  22. data/benchs/parse_vs_push.rb +67 -0
  23. data/bin/fog +78 -0
  24. data/fog-digitalocean.gemspec +61 -0
  25. data/gemfiles/Gemfile-edge +14 -0
  26. data/lib/fog/digitalocean.rb +1 -0
  27. data/lib/fog/digitalocean/CHANGELOG.md +6 -0
  28. data/lib/fog/digitalocean/compute.rb +109 -0
  29. data/lib/fog/digitalocean/core.rb +9 -0
  30. data/lib/fog/digitalocean/examples/getting_started.md +123 -0
  31. data/lib/fog/digitalocean/models/compute/flavor.rb +17 -0
  32. data/lib/fog/digitalocean/models/compute/flavors.rb +21 -0
  33. data/lib/fog/digitalocean/models/compute/image.rb +25 -0
  34. data/lib/fog/digitalocean/models/compute/images.rb +42 -0
  35. data/lib/fog/digitalocean/models/compute/region.rb +13 -0
  36. data/lib/fog/digitalocean/models/compute/regions.rb +21 -0
  37. data/lib/fog/digitalocean/models/compute/server.rb +170 -0
  38. data/lib/fog/digitalocean/models/compute/servers.rb +43 -0
  39. data/lib/fog/digitalocean/models/compute/ssh_key.rb +31 -0
  40. data/lib/fog/digitalocean/models/compute/ssh_keys.rb +40 -0
  41. data/lib/fog/digitalocean/models/paging_collection.rb +42 -0
  42. data/lib/fog/digitalocean/requests/compute/change_kernel.rb +44 -0
  43. data/lib/fog/digitalocean/requests/compute/convert_to_snapshot.rb +44 -0
  44. data/lib/fog/digitalocean/requests/compute/create_server.rb +93 -0
  45. data/lib/fog/digitalocean/requests/compute/create_ssh_key.rb +49 -0
  46. data/lib/fog/digitalocean/requests/compute/delete_ssh_key.rb +32 -0
  47. data/lib/fog/digitalocean/requests/compute/destroy_server.rb +35 -0
  48. data/lib/fog/digitalocean/requests/compute/disable_backups.rb +45 -0
  49. data/lib/fog/digitalocean/requests/compute/enable_ipv6.rb +44 -0
  50. data/lib/fog/digitalocean/requests/compute/enable_private_networking.rb +44 -0
  51. data/lib/fog/digitalocean/requests/compute/get_droplet_action.rb +36 -0
  52. data/lib/fog/digitalocean/requests/compute/get_image_details.rb +42 -0
  53. data/lib/fog/digitalocean/requests/compute/get_server_details.rb +84 -0
  54. data/lib/fog/digitalocean/requests/compute/get_ssh_key.rb +34 -0
  55. data/lib/fog/digitalocean/requests/compute/list_droplet_actions.rb +38 -0
  56. data/lib/fog/digitalocean/requests/compute/list_flavors.rb +132 -0
  57. data/lib/fog/digitalocean/requests/compute/list_images.rb +51 -0
  58. data/lib/fog/digitalocean/requests/compute/list_regions.rb +95 -0
  59. data/lib/fog/digitalocean/requests/compute/list_servers.rb +33 -0
  60. data/lib/fog/digitalocean/requests/compute/list_ssh_keys.rb +41 -0
  61. data/lib/fog/digitalocean/requests/compute/password_reset.rb +44 -0
  62. data/lib/fog/digitalocean/requests/compute/power_cycle.rb +44 -0
  63. data/lib/fog/digitalocean/requests/compute/power_off.rb +44 -0
  64. data/lib/fog/digitalocean/requests/compute/power_on.rb +44 -0
  65. data/lib/fog/digitalocean/requests/compute/reboot_server.rb +44 -0
  66. data/lib/fog/digitalocean/requests/compute/rebuild.rb +44 -0
  67. data/lib/fog/digitalocean/requests/compute/rename.rb +44 -0
  68. data/lib/fog/digitalocean/requests/compute/resize.rb +48 -0
  69. data/lib/fog/digitalocean/requests/compute/restore.rb +44 -0
  70. data/lib/fog/digitalocean/requests/compute/shutdown.rb +44 -0
  71. data/lib/fog/digitalocean/requests/compute/snapshot.rb +44 -0
  72. data/lib/fog/digitalocean/requests/compute/transfer_image.rb +44 -0
  73. data/lib/fog/digitalocean/requests/compute/update_ssh_key.rb +46 -0
  74. data/lib/fog/digitalocean/requests/compute/upgrade.rb +44 -0
  75. data/lib/fog/digitalocean/service.rb +51 -0
  76. data/lib/fog/digitalocean/version.rb +5 -0
  77. data/spec/fog/account_spec.rb +14 -0
  78. data/spec/fog/billing_spec.rb +14 -0
  79. data/spec/fog/bin/atmos_spec.rb +33 -0
  80. data/spec/fog/bin/aws_spec.rb +98 -0
  81. data/spec/fog/bin/baremetalcloud_spec.rb +33 -0
  82. data/spec/fog/bin/bluebox_spec.rb +55 -0
  83. data/spec/fog/bin/brightbox_spec.rb +30 -0
  84. data/spec/fog/bin/clodo_spec.rb +9 -0
  85. data/spec/fog/bin/cloudsigma_spec.rb +9 -0
  86. data/spec/fog/bin/cloudstack_spec.rb +9 -0
  87. data/spec/fog/bin/digitalocean_spec.rb +9 -0
  88. data/spec/fog/bin/dnsimple_spec.rb +9 -0
  89. data/spec/fog/bin/dnsmadeeasy_spec.rb +9 -0
  90. data/spec/fog/bin/dreamhost_spec.rb +9 -0
  91. data/spec/fog/bin/dynect_spec.rb +9 -0
  92. data/spec/fog/bin/ecloud_spec.rb +10 -0
  93. data/spec/fog/bin/fogdocker_spec.rb +10 -0
  94. data/spec/fog/bin/glesys_spec.rb +10 -0
  95. data/spec/fog/bin/gogrid_spec.rb +10 -0
  96. data/spec/fog/bin/google_spec.rb +10 -0
  97. data/spec/fog/bin/ibm_spec.rb +10 -0
  98. data/spec/fog/bin/internetarchive_spec.rb +10 -0
  99. data/spec/fog/bin/joyent_spec.rb +10 -0
  100. data/spec/fog/bin/linode_spec.rb +10 -0
  101. data/spec/fog/bin/local_spec.rb +10 -0
  102. data/spec/fog/bin/ninefold_spec.rb +10 -0
  103. data/spec/fog/bin/opennebula_spec.rb +10 -0
  104. data/spec/fog/bin/openstack_spec.rb +10 -0
  105. data/spec/fog/bin/openvz_spec.rb +10 -0
  106. data/spec/fog/bin/ovirt_spec.rb +10 -0
  107. data/spec/fog/bin/powerdns_spec.rb +9 -0
  108. data/spec/fog/bin/profitbricks_spec.rb +10 -0
  109. data/spec/fog/bin/rackspace_spec.rb +10 -0
  110. data/spec/fog/bin/rage4_spec.rb +10 -0
  111. data/spec/fog/bin/riakcs_spec.rb +10 -0
  112. data/spec/fog/bin/sakuracloud_spec.rb +10 -0
  113. data/spec/fog/bin/serverlove_spec.rb +10 -0
  114. data/spec/fog/bin/softlayer_spec.rb +10 -0
  115. data/spec/fog/bin/stormondemand_spec.rb +10 -0
  116. data/spec/fog/bin/vcloud_spec.rb +10 -0
  117. data/spec/fog/bin/vclouddirector_spec.rb +10 -0
  118. data/spec/fog/bin/vmfusion_spec.rb +10 -0
  119. data/spec/fog/bin/voxel_spec.rb +10 -0
  120. data/spec/fog/bin/vsphere_spec.rb +10 -0
  121. data/spec/fog/bin/xenserver_spec.rb +10 -0
  122. data/spec/fog/bin/zerigo_spec.rb +10 -0
  123. data/spec/fog/bin_spec.rb +161 -0
  124. data/spec/fog/cdn_spec.rb +14 -0
  125. data/spec/fog/compute_spec.rb +19 -0
  126. data/spec/fog/dns_spec.rb +19 -0
  127. data/spec/fog/identity_spec.rb +14 -0
  128. data/spec/fog/image_spec.rb +14 -0
  129. data/spec/fog/metering_spec.rb +14 -0
  130. data/spec/fog/monitoring_spec.rb +14 -0
  131. data/spec/fog/network_spec.rb +14 -0
  132. data/spec/fog/orchestration_spec.rb +14 -0
  133. data/spec/fog/storage_spec.rb +14 -0
  134. data/spec/fog/support_spec.rb +14 -0
  135. data/spec/fog/volume_spec.rb +14 -0
  136. data/spec/fog/vpn_spec.rb +14 -0
  137. data/spec/fog/xml/connection_spec.rb +33 -0
  138. data/spec/helpers/bin.rb +34 -0
  139. data/spec/spec_helper.rb +18 -0
  140. data/tests/digitalocean/helper.rb +56 -0
  141. data/tests/digitalocean/requests/compute/list_flavors_tests.rb +25 -0
  142. data/tests/digitalocean/requests/compute/list_images_tests.rb +25 -0
  143. data/tests/digitalocean/requests/compute/list_regions_tests.rb +21 -0
  144. data/tests/digitalocean/requests/compute/server_tests.rb +77 -0
  145. data/tests/digitalocean/requests/compute_v2/list_ssh_keys_tests.rb +20 -0
  146. data/tests/helper.rb +25 -0
  147. data/tests/helpers/format_helper.rb +100 -0
  148. data/tests/helpers/mock_helper.rb +14 -0
  149. data/tests/helpers/succeeds_helper.rb +10 -0
  150. data/tests/lorem.txt +1 -0
  151. data/tests/watchr.rb +22 -0
  152. metadata +428 -0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "coveralls", require: false
4
+
5
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2009-2015 [CONTRIBUTORS.md](https://github.com/fog/fog/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,130 @@
1
+ # Fog::DigitalOcean
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fog-digitalocean.svg)](http://badge.fury.io/rb/fog-digitalocean) [![Build Status](https://travis-ci.org/fog/fog-digitalocean.svg?branch=master)](https://travis-ci.org/fog/fog-digitalocean) [![Dependency Status](https://gemnasium.com/fog/fog-digitalocean.svg)](https://gemnasium.com/fog/fog-digitalocean) [![Coverage Status](https://coveralls.io/repos/github/fog/fog-digitalocean/badge.svg?branch=master)](https://coveralls.io/github/fog/fog-digitalocean?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-digitalocean/badges/gpa.svg)](https://codeclimate.com/github/fog/fog-digitalocean) [![Join the chat at https://gitter.im/fog/fog-digitalocean](https://badges.gitter.im/fog/fog-digitalocean.svg)](https://gitter.im/fog/fog-digitalocean?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
5
+ This is the plugin Gem to talk to [Digitalocean](http://digitalocean.org) clouds via fog.
6
+
7
+ The main maintainers for the Digitalocean sections are @jjasghar and @h0lyalg0rithm. Please send CC them on pull requests.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'fog-digitalocean'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install fog-digitalocean
24
+
25
+ ## Usage
26
+
27
+ ### Initial Setup
28
+
29
+
30
+ # Getting started: the compute service
31
+
32
+ You'll need a DigitalOcean account and an API token to use this provider.
33
+
34
+ Get one from https://cloud.digitalocean.com/settings/tokens/new
35
+
36
+ Write down the Access Token.
37
+
38
+ ## Connecting, retrieving and managing server objects
39
+
40
+ Before we start, I guess it will be useful to the reader to know
41
+ that Fog servers are 'droplets' in DigitalOcean's parlance.
42
+ 'Server' is the Fog way to name VMs, and we have
43
+ respected that in the DigitalOcean's Fog provider.
44
+
45
+ First, create a connection to the host:
46
+
47
+ ```ruby
48
+ require 'fog'
49
+
50
+ docean = Fog::Compute.new({
51
+ :provider => 'DigitalOcean',
52
+ :version => 'V2',
53
+ :digitalocean_token => 'poiuweoruwoeiuroiwuer', # your Access Token here
54
+ })
55
+ ```
56
+
57
+ ## SSH Key Management
58
+
59
+ Access to DigitalOcean servers can be managed with SSH keys. These can be assigned to servers at creation time so you can access them without having to use a password.
60
+
61
+ Creating a key:
62
+
63
+ ```ruby
64
+ docean.ssh_keys.create(
65
+ :name => 'Default SSH Key',
66
+ :ssh_pub_key => File.read('~/.ssh/id_rsa.pub'))
67
+ )
68
+ ```
69
+
70
+ Listing all keys:
71
+
72
+ ```ruby
73
+ docean.ssh_keys.each do | key |
74
+ puts key.name
75
+ puts key.public_key
76
+ puts key.id
77
+ end
78
+ ```
79
+
80
+ Destroying a key:
81
+
82
+ ```ruby
83
+ docean.ssh_keys.destroy(:id => '27100')
84
+ ```
85
+ ## Listing servers
86
+
87
+ Listing servers and attributes:
88
+
89
+ ```ruby
90
+ docean.servers.each do |server|
91
+ # remember, servers are droplets
92
+ puts server.id
93
+ puts server.name
94
+ puts server.status
95
+ puts (server.image['slug'] || server.image['name']) # slug is only for public images, private images use name
96
+ puts server.size['slug']
97
+ puts server.region['slug']
98
+ end
99
+ ```
100
+
101
+ ## Server creation and life-cycle management
102
+
103
+ Creating a new server (droplet):
104
+
105
+ ```ruby
106
+ server = docean.servers.create :name => 'foobar',
107
+ # use the last image listed
108
+ :image => docean.images.last.id,
109
+ # use the first flavor (aka size) listed
110
+ :size => docean.flavors.first.slug,
111
+ # use the first region listed
112
+ :region => docean.regions.first.slug
113
+ ```
114
+
115
+ The server is automatically started after that.
116
+
117
+ ## Development
118
+
119
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
120
+
121
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
122
+
123
+ ## Contributing
124
+
125
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fog-digitalocean. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
126
+
127
+
128
+ ## License
129
+
130
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,40 @@
1
+ # Release process
2
+
3
+ This is fog's current release process, documented so people know what is
4
+ currently done.
5
+
6
+ ## Versioning
7
+
8
+ fog uses semantic versioning (http://semver.org/)
9
+
10
+ ## When we release
11
+
12
+ Releases occur monthly and are manually handled by fog's Benevolent
13
+ Dictator Wes (@geemus).
14
+
15
+ To request a new release please raise an issue.
16
+
17
+ ## Prepare the release
18
+
19
+ * Ensure the code is passing on the CI server [![Build Status](https://secure.travis-ci.org/fog/fog.png?branch=master)](http://travis-ci.org/fog/fog)
20
+ * Ensure the code is passing for live tests (Requires Credentials for all
21
+ services)
22
+ * Ensure working on **master**
23
+ * Update the version number (`lib/fog/version.rb`)
24
+ * Run `rake changelog` to update `CHANGELOG.md`
25
+ * Run `rake release` to prepare the release which does:
26
+ * Prepares the release (`rake release:prepare`)
27
+ * Builds the gem
28
+ * Tags the commit
29
+ * Creates commits for version
30
+ * Publishes the release (`rake release:publish`)
31
+ * Pushes commit and tag to Github (Requires Credentials)
32
+ * Pushes gem to Rubygems (Requires Credentials)
33
+ * Run `rake github_release` to add release to [github release feed](https://github.com/fog/fog/releases.atom) (Requires Credentials)
34
+
35
+ ## Announce the release
36
+
37
+ Once the release is prepared and uploaded it needs to be announced.
38
+
39
+ * Send an email to https://groups.google.com/forum/?fromgroups#!forum/ruby-fog
40
+ * Tweet as @fog on Twitter (Requires Credentials)
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
5
+
6
+ task :default => :test
7
+
8
+ desc 'Run fog-digitalocean unit tests'
9
+ mock = ENV['FOG_MOCK'] || 'true'
10
+ task :test do
11
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
12
+ end
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ # for each provider
4
+ grep -lr "< Fog::Service$" lib/fog | xargs -L1 dirname | sort | uniq | sed -e 's/lib\///' |
5
+ # trigger rubygem cost then benchmark the load time
6
+ xargs -I{} ruby -Ilib -rbenchmark -e 'Gem::Specification._all; puts "{}: #{Benchmark.realtime{require "{}" }}"'
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ # for each service
4
+ grep -lr "< Fog::Service$" lib/fog | sed -e 's/lib\///' -e 's/.rb$//' |
5
+ # trigger rubygem cost then benchmark the load time
6
+ xargs -I{} ruby -Ilib -rbenchmark -e 'Gem::Specification._all; puts "{}: #{Benchmark.realtime{ require "{}" }}"'
@@ -0,0 +1,106 @@
1
+ require 'rubygems'
2
+ require 'aws/s3'
3
+ require 'benchmark'
4
+ require 'right_aws'
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
7
+
8
+ data = File.open(File.expand_path('~/.fog')).read
9
+ config = YAML.load(data)[:default]
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
+ awss3 = AWS::S3::Base.establish_connection!(
20
+ :access_key_id => config[:aws_access_key_id],
21
+ :secret_access_key => config[:aws_secret_access_key],
22
+ :persistent => true
23
+ )
24
+
25
+ TIMES = 10
26
+
27
+ Benchmark.bmbm(25) do |bench|
28
+ bench.report('fog.put_bucket') do
29
+ TIMES.times do |x|
30
+ fog.put_bucket("fogbench#{x}")
31
+ end
32
+ end
33
+ bench.report('raws.create_bucket') do
34
+ TIMES.times do |x|
35
+ raws.create_bucket("rawsbench#{x}")
36
+ end
37
+ end
38
+ bench.report('awss3::Bucket.create') do
39
+ TIMES.times do |x|
40
+ AWS::S3::Bucket.create("awss3bench#{x}")
41
+ end
42
+ end
43
+
44
+ bench.report('fog.put_object') do
45
+ TIMES.times do |x|
46
+ TIMES.times do |y|
47
+ file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
48
+ fog.put_object("fogbench#{x}", "lorem_#{y}", file)
49
+ end
50
+ end
51
+ end
52
+ bench.report('raws.put') do
53
+ TIMES.times do |x|
54
+ TIMES.times do |y|
55
+ file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
56
+ raws.put("rawsbench#{x}", "lorem_#{y}", file)
57
+ end
58
+ end
59
+ end
60
+ bench.report('awss3::S3Object.create') do
61
+ TIMES.times do |x|
62
+ TIMES.times do |y|
63
+ file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
64
+ AWS::S3::S3Object.create("lorem_#{y}", file, "awss3bench#{x}")
65
+ end
66
+ end
67
+ end
68
+
69
+ bench.report('fog.delete_object') do
70
+ TIMES.times do |x|
71
+ TIMES.times do |y|
72
+ fog.delete_object("fogbench#{x}", "lorem_#{y}")
73
+ end
74
+ end
75
+ end
76
+ bench.report('raws.delete') do
77
+ TIMES.times do |x|
78
+ TIMES.times do |y|
79
+ raws.delete("rawsbench#{x}", "lorem_#{y}")
80
+ end
81
+ end
82
+ end
83
+ bench.report('awss3::S3Object.delete') do
84
+ TIMES.times do |x|
85
+ TIMES.times do |y|
86
+ AWS::S3::S3Object.delete("lorem_#{y}", "awss3bench#{x}")
87
+ end
88
+ end
89
+ end
90
+
91
+ bench.report('fog.delete_bucket') do
92
+ TIMES.times do |x|
93
+ fog.delete_bucket("fogbench#{x}")
94
+ end
95
+ end
96
+ bench.report('raws.delete_bucket') do
97
+ TIMES.times do |x|
98
+ raws.delete_bucket("rawsbench#{x}")
99
+ end
100
+ end
101
+ bench.report('awss3::Bucket.delete') do
102
+ TIMES.times do |x|
103
+ AWS::S3::Bucket.delete("awss3bench#{x}")
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,37 @@
1
+ require 'benchmark'
2
+ $LOAD_PATH << File.dirname(__FILE__) + '/../lib'
3
+
4
+ def time_in_fork(&block)
5
+ read, write = IO.pipe
6
+ Process.fork do
7
+ write.puts Benchmark.realtime{ block.call }
8
+ end
9
+ Process.wait
10
+ write.close
11
+ read.read.tap do
12
+ read.close
13
+ end
14
+ end
15
+
16
+ class Array
17
+ def avg
18
+ map(&:to_f).inject(:+) / size
19
+ end
20
+ end
21
+
22
+ def report(label, n = 10, &block)
23
+ puts label
24
+ puts "%.4f" % n.times.map{ time_in_fork &block }.avg
25
+ puts
26
+ end
27
+
28
+ # make rubygems load specifications now so the
29
+ # time is not included below.
30
+ Gem::Specification._all
31
+
32
+ N = 10
33
+
34
+ report("require fog:", N) { require 'fog' }
35
+ report("require fog/aws:", N) { require 'fog/aws' }
36
+ report("require fog/aws/compute:", N) { require 'fog/aws/compute' }
37
+ report("require fog/aws/core:", N) { require 'fog/aws/core'}
@@ -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,67 @@
1
+ require 'benchmark'
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+
5
+ class Parser < Nokogiri::XML::SAX::Document
6
+ attr_reader :response
7
+
8
+ def initialize
9
+ reset
10
+ end
11
+
12
+ def reset
13
+ @item = {}
14
+ @response = { :items => [] }
15
+ end
16
+
17
+ def characters(string)
18
+ @value ||= ''
19
+ @value << string.strip
20
+ end
21
+
22
+ def start_element(name, attrs = [])
23
+ @value = nil
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
+ def value
37
+ @value.dup
38
+ end
39
+ end
40
+
41
+ data = <<-DATA
42
+ <items>
43
+ <item>
44
+ <key>value</key>
45
+ </item>
46
+ </items>
47
+ DATA
48
+
49
+ COUNT = 10_000
50
+
51
+ Benchmark.bmbm(25) do |bench|
52
+ bench.report('parse') do
53
+ COUNT.times do
54
+ parser = Parser.new
55
+ Nokogiri::XML::SAX::Parser.new(parser).parse(data)
56
+ parser.response
57
+ end
58
+ end
59
+
60
+ bench.report('push') do
61
+ COUNT.times do
62
+ parser = Parser.new
63
+ Nokogiri::XML::SAX::PushParser.new(parser).write(data, true)
64
+ parser.response
65
+ end
66
+ end
67
+ end