Created
September 5, 2012 15:23
-
-
Save pctj101/3638336 to your computer and use it in GitHub Desktop.
Fog Glacier Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "bundler/setup" | |
# require your gems as usual | |
require "fog" | |
require 'fog/aws/glacier' | |
aws_access_key_id = "??" | |
aws_secret_access_key = "??" | |
region = '??' | |
target_vault = "??" | |
test_file = '??' | |
attributes = { :aws_access_key_id => aws_access_key_id, | |
:aws_secret_access_key => aws_secret_access_key, | |
:region => region | |
} | |
glacier = Fog::AWS::Glacier.new(attributes) | |
#glacier.create_vault("Test_Vault_Creation") | |
vaults = glacier.list_vaults | |
#glacier.delete_vault("Test_Vault_Creation") | |
# look for vault | |
thevault = nil | |
vaults.body["VaultList"].each do |vaultinfo| | |
print "Checking #{vaultinfo['VaultName']}" | |
if vaultinfo["VaultName"] == target_vault | |
print "Found #{vaultinfo}" | |
thevault = vaultinfo | |
end | |
end | |
jobs = glacier.list_jobs(thevault["VaultName"]) | |
vault_notification_configuration = glacier.get_vault_notification_configuration(thevault["VaultName"]) | |
summary = Time.now.strftime("Test%Y%m%d%H%M%S") | |
body = summary | |
description = "Test Archive - #{summary}" | |
result = glacier.create_archive(thevault["VaultName"], body) | |
summary = Time.now.strftime("Test%Y%m%d%H%M%S") | |
body = test1dat_file = File.open(test_file) | |
description = "Test Archive - #{summary}" | |
result = glacier.create_archive(thevault["VaultName"], body) | |
#fails: NoMethodError: undefined method `bytesize' for #<File:/test/test1.dat> | |
# Request Job - Retrieve Inventory | |
job_specification = { | |
"Type" => "inventory-retrieval", | |
"Description" => "Inventory Retrieval Job", | |
"Format" => "JSON" #or CSV | |
} | |
bad_response = nil | |
begin | |
inventory_job_result = glacier.initiate_job(thevault["VaultName"], job_specification) | |
rescue Exception => e | |
bad_response = e | |
print bad_response.response.body | |
end | |
# Request Job - Retrieve Archive | |
archive_id = 'compute this somehow' | |
job_specification = { | |
"Type" => "archive-retrieval", | |
"Description" => "Inventory Retrieval Job", | |
"ArchiveId" => archive_id | |
} | |
bad_response = nil | |
job_id = nil | |
begin | |
retrieve_job_result = glacier.initiate_job(thevault["VaultName"], job_specification) | |
job_id = retrieve_job_result.headers["x-amz-job-id"] | |
rescue Exception => e | |
bad_response = e | |
print bad_response.response.body | |
end | |
# Get the output from a job | |
# * options<~Hash> | |
# * Range<~Range> The range to retrieve | |
# * response_block<~Proc> Proc to use for streaming the response | |
bad_response = nil | |
job_output = nil | |
begin | |
job_output = glacier.get_job_output(thevault["VaultName"], job_id) | |
rescue Exception => e | |
bad_response = e | |
print bad_response.response.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment