From 18473c1db680512d09033181dab2c966c2542d68 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Wed, 3 Apr 2013 10:47:31 -0500 Subject: [PATCH 1/2] [digitalocean] Check to see if we have a digital ocean api key before attempting to delete servers --- tests/digitalocean/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/digitalocean/helper.rb b/tests/digitalocean/helper.rb index be231c71c..05c0c7297 100644 --- a/tests/digitalocean/helper.rb +++ b/tests/digitalocean/helper.rb @@ -32,7 +32,7 @@ def fog_test_server_destroy end at_exit do - unless Fog.mocking? + unless Fog.mocking? || Fog.credentials[:digitalocean_api_key].nil? server = service.servers.find { |s| s.name == 'fog-test-server' } if server server.wait_for(120) do From d96365c6fd71aafb03869581bff0779b8a7005f1 Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Wed, 3 Apr 2013 18:27:28 +0200 Subject: [PATCH 2/2] [openstack|storage] Added storage example to set the account quota See also #1632 --- .../examples/storage/set-account-quota.rb | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/fog/openstack/examples/storage/set-account-quota.rb diff --git a/lib/fog/openstack/examples/storage/set-account-quota.rb b/lib/fog/openstack/examples/storage/set-account-quota.rb new file mode 100644 index 000000000..65aee59ce --- /dev/null +++ b/lib/fog/openstack/examples/storage/set-account-quota.rb @@ -0,0 +1,66 @@ +require 'fog' +require 'pp' + +# +# This example sets the account quota (in bytes) for the tenant demo@test.lan +# using an admin account (admin has the reseller user role). +# +# Uses the account impersonation feature recently added to the +# OpenStack Storage service in Fog (See https://github.com/fog/fog/pull/1632). +# +# Should be available in Fog 1.10.0+1. +# +# Setting account quotas is only supported in Swift 1.8.0+ +# using the brand new account_quota middleware introduced in +# OpenStack Grizzly (currently unreleased as of 2013/04/03). +# +# https://github.com/openstack/swift/blob/master/swift/common/middleware/account_quotas.py +# + +auth_url = 'https://identity.test.lan/v2.0/tokens' +user = 'admin@test.lan' +password = 'secret' + +Excon.defaults[:ssl_verify_peer] = false + +# +# We are going to use the Identity (Keystone) service +# to retrieve the list of tenants available and find +# the tenant we want to set the quotas for. +# +id = Fog::Identity.new :provider => 'OpenStack', + :openstack_auth_url => auth_url, + :openstack_username => user, + :openstack_api_key => password + +# +# Storage service (Swift) +# +st = Fog::Storage.new :provider => 'OpenStack', + :openstack_auth_url => auth_url, + :openstack_username => user, + :openstack_api_key => password + +id.tenants.each do |t| + # We want to set the account quota for tenant demo@test.lan + next unless t.name == 'demo@test.lan' + + # We've found the tenant, impersonate the account + # (the account prefix AUTH_ may be different for you, double check it). + puts "Changing account to #{t.name}" + st.change_account "AUTH_#{t.id}" + + # Now we're adding the required header to the demo@test.lan + # tenant account, limiting the account bytes to 1048576 (1MB) + # + # Uploading more than 1MB will return 413: Request Entity Too Large + st.request :method => 'POST', + :headers => { 'X-Account-Meta-Quota-Bytes' => '1048576' } + + # We can list the account details to verify the new + # header has been added + pp st.request :method => 'HEAD' +end + +# Restore the account we were using initially (admin@test.lan) +st.reset_account_name