mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
merge
This commit is contained in:
parent
a0d6b018a5
commit
68945be16e
42 changed files with 899 additions and 41 deletions
|
@ -6,7 +6,7 @@ module Fog
|
|||
response = request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'loadbalancers/#{load_balancer_id}/nodes'
|
||||
:path => "loadbalancers/#{load_balancer_id}/nodes"
|
||||
)
|
||||
response
|
||||
end
|
||||
|
@ -55,4 +55,4 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -152,7 +152,7 @@ module Fog
|
|||
|
||||
|
||||
# Get publicly acessible url via http GET.
|
||||
#
|
||||
#
|
||||
# required attributes: directory, key
|
||||
#
|
||||
# @return [String] public url
|
||||
|
|
36
lib/fog/internet_archive/models/storage/version.rb
Normal file
36
lib/fog/internet_archive/models/storage/version.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
|
||||
class Version < Fog::Model
|
||||
|
||||
identity :version, :aliases => 'VersionId'
|
||||
|
||||
attribute :key, :aliases => 'Key'
|
||||
attribute :last_modified, :aliases => ['Last-Modified', 'LastModified']
|
||||
attribute :latest, :aliases => 'IsLatest', :type => :boolean
|
||||
attribute :content_length, :aliases => ['Content-Length', 'Size'], :type => :integer
|
||||
attribute :delete_marker, :type => :boolean
|
||||
|
||||
def file
|
||||
@file ||= if collection.file
|
||||
collection.file.directory.files.get(key, 'versionId' => version)
|
||||
else
|
||||
collection.directory.files.get(key, 'versionId' => version)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if collection.file
|
||||
collection.service.delete_object(collection.file.directory.key, key, 'versionId' => version)
|
||||
else
|
||||
collection.service.delete_object(collection.directory.key, key, 'versionId' => version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/internet_archive/models/storage/versions.rb
Normal file
38
lib/fog/internet_archive/models/storage/versions.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/internet_archive/models/storage/version'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
|
||||
class Versions < Fog::Collection
|
||||
|
||||
attribute :file
|
||||
attribute :directory
|
||||
|
||||
model Fog::Storage::InternetArchive::Version
|
||||
|
||||
def all(options = {})
|
||||
data = if file
|
||||
service.get_bucket_object_versions(file.directory.key, options.merge('prefix' => file.key)).body['Versions']
|
||||
else
|
||||
service.get_bucket_object_versions(directory.key, options).body['Versions']
|
||||
end
|
||||
|
||||
load(data)
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
version_type = attributes.keys.first
|
||||
|
||||
model = super(attributes[version_type])
|
||||
model.delete_marker = version_type == 'DeleteMarker'
|
||||
|
||||
model
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,88 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Storage
|
||||
module InternetArchive
|
||||
|
||||
class GetBucketObjectVersions < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@delete_marker = { 'Owner' => {} }
|
||||
@version = { 'Owner' => {} }
|
||||
|
||||
@in_delete_marke = false
|
||||
@in_version = false
|
||||
|
||||
@response = { 'Versions' => [] }
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
case name
|
||||
when 'DeleteMarker'
|
||||
@in_delete_marker = true
|
||||
when 'Version'
|
||||
@in_version = true
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'DeleteMarker'
|
||||
@response['Versions'] << {'DeleteMarker' => @delete_marker }
|
||||
@delete_marker = { 'Owner' => {} }
|
||||
@in_delete_marker = false
|
||||
when 'Version'
|
||||
@response['Versions'] << {'Version' => @version }
|
||||
@version = { 'Owner' => {} }
|
||||
@in_version = false
|
||||
when 'DisplayName', 'ID'
|
||||
if @in_delete_marker
|
||||
@delete_marker
|
||||
elsif @in_version
|
||||
@version
|
||||
end['Owner'][name] = value
|
||||
when 'ETag'
|
||||
@version[name] = value.gsub('"', '')
|
||||
when 'IsLatest'
|
||||
if @in_delete_marker
|
||||
@delete_marker
|
||||
elsif @in_version
|
||||
@version
|
||||
end['IsLatest'] = if value == 'true'
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
when 'IsTruncated'
|
||||
if value == 'true'
|
||||
@response['IsTruncated'] = true
|
||||
else
|
||||
@response['IsTruncated'] = false
|
||||
end
|
||||
when 'LastModified'
|
||||
if @in_delete_marker
|
||||
@delete_marker
|
||||
elsif @in_version
|
||||
@version
|
||||
end['LastModified'] = Time.parse(value)
|
||||
when 'MaxKeys'
|
||||
@response['MaxKeys'] = value.to_i
|
||||
when 'Size'
|
||||
@version['Size'] = value.to_i
|
||||
when 'Key', 'KeyMarker', 'Name', 'NextKeyMarker', 'NextVersionIdMarker', 'Prefix', 'StorageClass', 'VersionId', 'VersionIdMarker'
|
||||
if @in_delete_marker
|
||||
@delete_marker
|
||||
elsif @in_version
|
||||
@version
|
||||
else
|
||||
@response
|
||||
end[name] = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Storage
|
||||
module InternetArchive
|
||||
|
||||
class GetBucketVersioning < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'VersioningConfiguration' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Status', 'MfaDelete'
|
||||
@response['VersioningConfiguration'][name] = value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,162 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
class Real
|
||||
|
||||
require 'fog/internet_archive/parsers/storage/get_bucket_object_versions'
|
||||
|
||||
# List information about object versions in an S3 bucket
|
||||
#
|
||||
# @param bucket_name [String] name of bucket to list object keys from
|
||||
# @param options [Hash] config arguments for list
|
||||
# @option options delimiter [String] causes keys with the same string between the prefix value and the first occurence of delimiter to be rolled up
|
||||
# @option options key-marker [String] limits object keys to only those that appear lexicographically after its value.
|
||||
# @option options max-keys [Integer] limits number of object keys returned
|
||||
# @option options prefix [String] limits object keys to those beginning with its value.
|
||||
# @option options version-id-marker [String] limits object versions to only those that appear lexicographically after its value
|
||||
#
|
||||
# @return [Excon::Response] response:
|
||||
# * body [Hash]:
|
||||
# * Delimeter [String] - Delimiter specified for query
|
||||
# * KeyMarker [String] - Key marker specified for query
|
||||
# * MaxKeys [Integer] - Maximum number of keys specified for query
|
||||
# * Name [String] - Name of the bucket
|
||||
# * Prefix [String] - Prefix specified for query
|
||||
# * VersionIdMarker [String] - Version id marker specified for query
|
||||
# * IsTruncated [Boolean] - Whether or not this is the totality of the bucket
|
||||
# * Versions [Array]:
|
||||
# * DeleteMarker [Hash]:
|
||||
# * IsLatest [Boolean] - Whether or not this is the latest version
|
||||
# * Key [String] - Name of object
|
||||
# * LastModified [String]: Timestamp of last modification of object
|
||||
# * Owner [Hash]:
|
||||
# * DisplayName [String] - Display name of object owner
|
||||
# * ID [String] - Id of object owner
|
||||
# * VersionId [String] - The id of this version
|
||||
# or
|
||||
# * Version [Hash]:
|
||||
# * ETag [String]: Etag of object
|
||||
# * IsLatest [Boolean] - Whether or not this is the latest version
|
||||
# * Key [String] - Name of object
|
||||
# * LastModified [String]: Timestamp of last modification of object
|
||||
# * Owner [Hash]:
|
||||
# * DisplayName [String] - Display name of object owner
|
||||
# * ID [String] - Id of object owner
|
||||
# * Size [Integer] - Size of object
|
||||
# * StorageClass [String] - Storage class of object
|
||||
# * VersionId [String] - The id of this version
|
||||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETVersion.html
|
||||
|
||||
def get_bucket_object_versions(bucket_name, options = {})
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Storage::InternetArchive::GetBucketObjectVersions.new,
|
||||
:query => {'versions' => nil}.merge!(options) })
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_bucket_object_versions(bucket_name, options = {})
|
||||
delimiter, key_marker, max_keys, prefix, version_id_marker = \
|
||||
options['delimiter'], options['key-marker'], options['max-keys'],options['prefix'],options['version-id-marker']
|
||||
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
# Invalid arguments.
|
||||
if version_id_marker && !key_marker
|
||||
response.status = 400
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'InvalidArgument',
|
||||
'Message' => 'A version-id marker cannot be specified without a key marker.',
|
||||
'ArgumentValue' => version_id_marker,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
# Valid case.
|
||||
# TODO: (nirvdrum 12/15/11) It's not clear to me how to actually use version-id-marker, so I didn't implement it below.
|
||||
elsif bucket = self.data[:buckets][bucket_name]
|
||||
# We need to order results by S3 key, but since our data store is key => [versions], we want to ensure the integrity
|
||||
# of the versions as well. So, sort the keys, then fetch the versions, and then combine them all as a sorted list by
|
||||
# flattening the results.
|
||||
contents = bucket[:objects].keys.sort.collect { |key| bucket[:objects][key] }.flatten.reject do |object|
|
||||
(prefix && object['Key'][0...prefix.length] != prefix) ||
|
||||
(key_marker && object['Key'] <= key_marker) ||
|
||||
(delimiter && object['Key'][(prefix ? prefix.length : 0)..-1].include?(delimiter) \
|
||||
&& common_prefixes << object['Key'].sub(/^(#{prefix}[^#{delimiter}]+.).*/, '\1'))
|
||||
end.map do |object|
|
||||
if object.has_key?(:delete_marker)
|
||||
tag_name = 'DeleteMarker'
|
||||
extracted_attrs = ['Key', 'VersionId']
|
||||
else
|
||||
tag_name = 'Version'
|
||||
extracted_attrs = ['ETag', 'Key', 'StorageClass', 'VersionId']
|
||||
end
|
||||
|
||||
data = {}
|
||||
data[tag_name] = object.reject { |key, value| !extracted_attrs.include?(key) }
|
||||
data[tag_name].merge!({
|
||||
'LastModified' => Time.parse(object['Last-Modified']),
|
||||
'Owner' => bucket['Owner'],
|
||||
'IsLatest' => object == bucket[:objects][object['Key']].first
|
||||
})
|
||||
|
||||
data[tag_name]['Size'] = object['Content-Length'].to_i if tag_name == 'Version'
|
||||
data
|
||||
end
|
||||
|
||||
max_keys = max_keys || 1000
|
||||
size = [max_keys, 1000].min
|
||||
truncated_contents = contents[0...size]
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'Versions' => truncated_contents,
|
||||
'IsTruncated' => truncated_contents.size != contents.size,
|
||||
'KeyMarker' => key_marker,
|
||||
'VersionIdMarker' => version_id_marker,
|
||||
'MaxKeys' => max_keys,
|
||||
'Name' => bucket['Name'],
|
||||
'Prefix' => prefix
|
||||
}
|
||||
if max_keys && max_keys < response.body['Versions'].length
|
||||
response.body['IsTruncated'] = true
|
||||
response.body['Versions'] = response.body['Versions'][0...max_keys]
|
||||
end
|
||||
|
||||
# Missing bucket case.
|
||||
else
|
||||
response.status = 404
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'NoSuchBucket',
|
||||
'Message' => 'The specified bucket does not exist',
|
||||
'BucketName' => bucket_name,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,69 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
class Real
|
||||
|
||||
require 'fog/internet_archive/parsers/storage/get_bucket_versioning'
|
||||
|
||||
# Get versioning status for an S3 bucket
|
||||
#
|
||||
# @param bucket_name [String] name of bucket to get versioning status for
|
||||
#
|
||||
# @return [Excon::Response] response:
|
||||
# * body [Hash]:
|
||||
# * VersioningConfiguration [Hash]:
|
||||
# * Status [String] - Versioning status in ['Enabled', 'Suspended', nil]
|
||||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketGETversioningStatus.html
|
||||
|
||||
def get_bucket_versioning(bucket_name)
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Storage::InternetArchive::GetBucketVersioning.new,
|
||||
:query => {'versioning' => nil}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_bucket_versioning(bucket_name)
|
||||
response = Excon::Response.new
|
||||
bucket = self.data[:buckets][bucket_name]
|
||||
|
||||
if bucket
|
||||
response.status = 200
|
||||
|
||||
if bucket[:versioning]
|
||||
response.body = { 'VersioningConfiguration' => { 'Status' => bucket[:versioning] } }
|
||||
else
|
||||
response.body = { 'VersioningConfiguration' => {} }
|
||||
end
|
||||
|
||||
else
|
||||
response.status = 404
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'NoSuchBucket',
|
||||
'Message' => 'The specified bucket does not exist',
|
||||
'BucketName' => bucket_name,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
# @option options [String] If-None-Match Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
|
||||
# @option options [Time] If-Unmodified-Since Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
|
||||
# @option options [String] Range Range of object to download
|
||||
#
|
||||
#
|
||||
# @return [Excon::Response] response:
|
||||
# * body [String] Contents of object
|
||||
# * headers [Hash]:
|
||||
|
@ -58,4 +58,4 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,75 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class InternetArchive
|
||||
class Real
|
||||
|
||||
# Change versioning status for an S3 bucket
|
||||
#
|
||||
# @param bucket_name [String] name of bucket to modify
|
||||
# @param status [String] Status to change to in ['Enabled', 'Suspended']
|
||||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTVersioningStatus.html
|
||||
|
||||
def put_bucket_versioning(bucket_name, status)
|
||||
data =
|
||||
<<-DATA
|
||||
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Status>#{status}</Status>
|
||||
</VersioningConfiguration>
|
||||
DATA
|
||||
|
||||
request({
|
||||
:body => data,
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'PUT',
|
||||
:query => {'versioning' => nil}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def put_bucket_versioning(bucket_name, status)
|
||||
response = Excon::Response.new
|
||||
bucket = self.data[:buckets][bucket_name]
|
||||
|
||||
if bucket
|
||||
if ['Enabled', 'Suspended'].include?(status)
|
||||
bucket[:versioning] = status
|
||||
|
||||
response.status = 200
|
||||
else
|
||||
response.status = 400
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'MalformedXML',
|
||||
'Message' => 'The XML you provided was not well-formed or did not validate against our published schema',
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
else
|
||||
response.status = 404
|
||||
response.body = {
|
||||
'Error' => {
|
||||
'Code' => 'NoSuchBucket',
|
||||
'Message' => 'The specified bucket does not exist',
|
||||
'BucketName' => bucket_name,
|
||||
'RequestId' => Fog::Mock.random_hex(16),
|
||||
'HostId' => Fog::Mock.random_base64(65)
|
||||
}
|
||||
}
|
||||
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -292,4 +292,4 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -82,7 +82,7 @@ module Fog
|
|||
requires :key
|
||||
self.collection.get_url(self.key)
|
||||
end
|
||||
|
||||
|
||||
|
||||
def save(options = {})
|
||||
requires :body, :directory, :key
|
||||
|
|
|
@ -138,7 +138,7 @@ To view the status of the response:
|
|||
response.status
|
||||
|
||||
**Note**: Fog is aware of valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception.
|
||||
|
||||
|
||||
To view response body:
|
||||
|
||||
response.body
|
||||
|
@ -152,7 +152,7 @@ To learn more about Compute request methods refer to [rdoc](http://rubydoc.info/
|
|||
|
||||
### Model Layer
|
||||
|
||||
Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
|
||||
Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
|
||||
|
||||
Here is a summary of common model methods:
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ To learn more about `Fog::Storage` request methods refer to [rdoc](http://rubydo
|
|||
|
||||
### Model Layer
|
||||
|
||||
Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
|
||||
Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
|
||||
|
||||
Here is a summary of common model methods:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_server(servers)
|
||||
abort "\nThere are not any servers available to image in the Chicago region. Try running create_server.rb\n\n" if servers.empty?
|
||||
|
||||
|
||||
puts "\nSelect Server To Image:\n\n"
|
||||
servers.each_with_index do |server, i|
|
||||
puts "\t #{i}. #{server.name} [#{server.public_ip_address}]"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_image(snapshot_images)
|
||||
abort "\nThere are not any images to delete in the Chicago region. Try running create_image.rb\n\n" if snapshot_images.empty?
|
||||
|
||||
|
||||
puts "\nSelect Image To Delete:\n\n"
|
||||
snapshot_images.each_with_index do |image, i|
|
||||
puts "\t #{i}. #{image.name}"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_server(servers)
|
||||
abort "\nThere are not any servers to delete in the Chicago region. Try running create_server.rb\n\n" if servers.empty?
|
||||
|
||||
|
||||
puts "\nSelect Server To Delete:\n\n"
|
||||
servers.each_with_index do |server, i|
|
||||
puts "\t #{i}. #{server.name} [#{server.public_ip_address}]"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_server(servers)
|
||||
abort "\nThere are not any servers in the Chicago region. Try running create_server.rb\n\n" if servers.empty?
|
||||
|
||||
|
||||
puts "\nSelect Server For Volume Detachment:\n\n"
|
||||
servers.each_with_index do |server, i|
|
||||
puts "\t #{i}. #{server.name} [#{server.public_ip_address}]"
|
||||
|
@ -24,7 +24,7 @@ end
|
|||
|
||||
def select_attachment(attachments)
|
||||
abort "\nThis server does not contain any volumes in the Chicago region. Try running server_attachments.rb\n\n" if attachments.empty?
|
||||
|
||||
|
||||
puts "\nSelect Volume To Detach:\n\n"
|
||||
attachments.each_with_index do |attachment, i|
|
||||
puts "\t #{i}. #{attachment.device}"
|
||||
|
|
|
@ -23,7 +23,7 @@ end
|
|||
|
||||
def select_server(servers)
|
||||
abort "\nThere are not any servers to resize in the Chicago region. Try running create_server.rb\n\n" if servers.empty?
|
||||
|
||||
|
||||
puts "\nSelect Server Resize:\n\n"
|
||||
servers.each_with_index do |server, i|
|
||||
puts "\t #{i}. #{server.name} [#{server.public_ip_address}]"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_server(servers)
|
||||
abort "\nThere are not any servers in the Chicago region. Try running create_server.rb\n\n" if servers.empty?
|
||||
|
||||
|
||||
puts "\nSelect Server For Attachment:\n\n"
|
||||
servers.each_with_index do |server, i|
|
||||
puts "\t #{i}. #{server.name} [#{server.public_ip_address}]"
|
||||
|
|
|
@ -28,7 +28,7 @@ service = Fog::Storage.new({
|
|||
:rackspace_username => rackspace_username,
|
||||
:rackspace_api_key => rackspace_api_key,
|
||||
:rackspace_region => :ord #Use Chicago Region
|
||||
})
|
||||
})
|
||||
|
||||
# prompt for directory name
|
||||
directory_name = get_user_input "\nEnter name of directory to create"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_directory(directories)
|
||||
abort "\nThere are not any directories to delete in the Chicago region. Try running create_directory.rb\n\n" if directories.empty?
|
||||
|
||||
|
||||
puts "\nSelect Directory To Delete:\n\n"
|
||||
directories.each_with_index do |dir, i|
|
||||
puts "\t #{i}. #{dir.key} [#{dir.count} objects]"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_directory(directories)
|
||||
abort "\nThere are not any directories with files to delete in the Chicago region. Try running create_file.rb\n\n" if directories.empty?
|
||||
|
||||
|
||||
puts "\nSelect Directory:\n\n"
|
||||
directories.each_with_index do |dir, i|
|
||||
puts "\t #{i}. #{dir.key} [#{dir.count} objects]"
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
def select_directory(directories)
|
||||
abort "\nThere are not any directories with files in the Chicago region. Try running create_file.rb\n\n" if directories.empty?
|
||||
|
||||
|
||||
puts "\nSelect Directory:\n\n"
|
||||
directories.each_with_index do |dir, i|
|
||||
puts "\t #{i}. #{dir.key} [#{dir.count} objects]"
|
||||
|
|
|
@ -61,7 +61,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Image_Details-d1e4848.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Get_Image_Details-d1e4848.html
|
||||
def get(image_id)
|
||||
data = service.get_image(image_id).body['image']
|
||||
new(data)
|
||||
|
|
|
@ -46,7 +46,7 @@ module Fog
|
|||
# Retrieve specific value for key from Metadata.
|
||||
# * If key is of type String, this method will return the value of the metadatum
|
||||
# * If key is of type Fixnum, this method will return a Fog::Compute::RackspaceV2::Metadatum object (legacy)
|
||||
# @param [#key] key
|
||||
# @param [#key] key
|
||||
# @return [#value]
|
||||
def [](key)
|
||||
return super(key) if key.is_a?(Integer)
|
||||
|
@ -58,7 +58,7 @@ module Fog
|
|||
# Set value for key.
|
||||
# * If key is of type String, this method will set/add the value to Metadata
|
||||
# * If key is of type Fixnum, this method will set a Fog::Compute::RackspaceV2::Metadatum object (legacy)
|
||||
# @param [#key] key
|
||||
# @param [#key] key
|
||||
# @return [String]
|
||||
def []=(key, value)
|
||||
return super(key,value) if key.is_a?(Integer)
|
||||
|
|
|
@ -56,7 +56,7 @@ module Fog
|
|||
# @return [String] server (extended) status.
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html#server_status
|
||||
attribute :state_ext, :aliases => 'OS-EXT-STS:task_state'
|
||||
|
||||
|
||||
# @!attribute [r] progress
|
||||
# @return [Fixnum] The build completion progress, as a percentage. Value is from 0 to 100.
|
||||
attribute :progress
|
||||
|
@ -426,7 +426,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
|
||||
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Confirm_Resized_Server-d1e3868.html
|
||||
# @see #resize
|
||||
#
|
||||
|
|
|
@ -29,7 +29,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @note This method is incompatible with Cloud Servers utlizing RackConnect. RackConnect users
|
||||
# @note This method is incompatible with Cloud Servers utlizing RackConnect. RackConnect users
|
||||
# should use server personalization to install keys. Please see Server#personality for more information.
|
||||
# @example
|
||||
# service.servers.bootstrap :name => 'bootstrap-server',
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Image-d1e4957.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Image-d1e4957.html
|
||||
def delete_image(image_id)
|
||||
request(
|
||||
:expects => 204,
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Metadata-d1e5089.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Metadata-d1e5089.html
|
||||
def list_metadata(collection, obj_id)
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
|
|
|
@ -36,7 +36,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Servers-d1e2078.html
|
||||
def list_servers
|
||||
request(
|
||||
:expects => [200, 203, 300],
|
||||
|
|
|
@ -11,7 +11,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
|
||||
# @note All resizes are automatically confirmed after 24 hours if you do not explicitly confirm or revert the resize.
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Revert_Resized_Server-d1e4024.html
|
||||
#
|
||||
# * Status Transition:
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_or_Replace_Metadata-d1e5358.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_or_Replace_Metadata-d1e5358.html
|
||||
def set_metadata(collection, obj_id, metadata = {})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
|
|
|
@ -15,7 +15,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_or_Update_a_Metadata_Item-d1e5633.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_or_Update_a_Metadata_Item-d1e5633.html
|
||||
def set_metadata_item(collection, obj_id, key, value)
|
||||
request(
|
||||
:expects => 200,
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
||||
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Update_Metadata-d1e5208.html
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Update_Metadata-d1e5208.html
|
||||
def update_metadata(collection, obj_id, metadata = {})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
|
|
52
tests/internet_archive/models/storage/version_tests.rb
Normal file
52
tests/internet_archive/models/storage/version_tests.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
Shindo.tests("Storage[:internet_archive] | version", ["internet_archive"]) do
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_file_tests',
|
||||
:body => lorem_file,
|
||||
:public => true
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
:key => 'fogfilestests'
|
||||
}
|
||||
|
||||
@directory = Fog::Storage[:internetarchive].directories.create(directory_attributes)
|
||||
@directory.versioning = true
|
||||
|
||||
model_tests(@directory.files, file_attributes, Fog.mocking?) do
|
||||
|
||||
@version_instance = @instance.versions.first
|
||||
@directory.connection.put_object(@directory.key, @instance.key, 'second version content')
|
||||
|
||||
tests("#file") do
|
||||
tests("#file should return the object associated with the version").returns(@version_instance.version) do
|
||||
@version_instance.file.version
|
||||
end
|
||||
end
|
||||
|
||||
tests("#delete_marker") do
|
||||
tests("#delete_marker should be false if the version isn't a DeleteMarker'").returns(false) do
|
||||
@version_instance.delete_marker
|
||||
end
|
||||
|
||||
tests("#delete_marker should be true if the version is a DeleteMarker'").returns(true) do
|
||||
@instance.destroy
|
||||
|
||||
@instance.versions.all.first.delete_marker
|
||||
end
|
||||
end
|
||||
|
||||
tests("#destroy") do
|
||||
tests("#destroy removes the specific version").returns(false) do
|
||||
@version_instance.destroy
|
||||
|
||||
@instance.versions.all.collect(&:version).include?(@version_instance.version)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@directory.versions.each(&:destroy)
|
||||
@directory.destroy
|
||||
|
||||
end
|
56
tests/internet_archive/models/storage/versions_tests.rb
Normal file
56
tests/internet_archive/models/storage/versions_tests.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
Shindo.tests("Storage[:internet_archive] | versions", ["internet_archive"]) do
|
||||
|
||||
file_attributes = {
|
||||
:key => 'fog_file_tests',
|
||||
:body => lorem_file,
|
||||
:public => true
|
||||
}
|
||||
|
||||
directory_attributes = {
|
||||
:key => 'fogfilestests'
|
||||
}
|
||||
|
||||
model_tests(Fog::Storage[:internetarchive].directories, directory_attributes, Fog.mocking?) do
|
||||
@instance.versioning = true
|
||||
|
||||
versions = []
|
||||
versions << @instance.connection.put_object(@instance.key, 'one', 'abcde').headers['x-amz-version-id']
|
||||
|
||||
puts versions.first
|
||||
|
||||
versions << @instance.connection.put_object(@instance.key, 'one', '32423').headers['x-amz-version-id']
|
||||
versions << @instance.connection.delete_object(@instance.key, 'one').headers['x-amz-version-id']
|
||||
versions.reverse!
|
||||
|
||||
puts versions.first
|
||||
|
||||
versions << @instance.connection.put_object(@instance.key, 'two', 'aoeu').headers['x-amz-version-id']
|
||||
|
||||
tests('#versions') do
|
||||
tests('#versions.size includes versions (including DeleteMarkers) for all keys').returns(4) do
|
||||
@instance.versions.all.size
|
||||
end
|
||||
|
||||
tests('#versions returns the correct versions').returns(versions) do
|
||||
@instance.versions.all.collect(&:version)
|
||||
end
|
||||
end
|
||||
|
||||
tests("#all") do
|
||||
tests("#all for a directory returns all versions, regardless of key").returns(versions) do
|
||||
@instance.versions.all.collect(&:version)
|
||||
end
|
||||
|
||||
tests("#all for file returns only versions for that file").returns(1) do
|
||||
@instance.files.get('two').versions.all.collect(&:version).size
|
||||
end
|
||||
|
||||
tests("#all for file returns only versions for that file").returns(versions.last) do
|
||||
@instance.files.get('two').versions.all.collect(&:version).first
|
||||
end
|
||||
end
|
||||
|
||||
@instance.versions.each(&:destroy)
|
||||
end
|
||||
|
||||
end
|
258
tests/internet_archive/requests/storage/versioning_tests.rb
Normal file
258
tests/internet_archive/requests/storage/versioning_tests.rb
Normal file
|
@ -0,0 +1,258 @@
|
|||
def clear_bucket
|
||||
Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name).body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, object['Key'], 'versionId' => object['VersionId'])
|
||||
end
|
||||
end
|
||||
|
||||
def create_versioned_bucket
|
||||
@ia_bucket_name = 'fogbuckettests-' + Fog::Mock.random_hex(16)
|
||||
Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Enabled')
|
||||
end
|
||||
|
||||
def delete_bucket
|
||||
Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name).body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, object['Key'], 'versionId' => object['VersionId'])
|
||||
end
|
||||
|
||||
Fog::Storage[:internetarchive].delete_bucket(@ia_bucket_name)
|
||||
end
|
||||
|
||||
Shindo.tests('Fog::Storage[:internetarchive] | versioning', ["internet_archive"]) do
|
||||
tests('success') do
|
||||
tests("#put_bucket_versioning") do
|
||||
@ia_bucket_name = 'fogbuckettests-' + Fog::Mock.random_hex(16)
|
||||
Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
|
||||
|
||||
tests("#put_bucket_versioning('#{@ia_bucket_name}', 'Enabled')").succeeds do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Enabled')
|
||||
end
|
||||
|
||||
tests("#put_bucket_versioning('#{@ia_bucket_name}', 'Suspended')").succeeds do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Suspended')
|
||||
end
|
||||
|
||||
delete_bucket
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}')") do
|
||||
@ia_bucket_name = 'fogbuckettests-' + Fog::Mock.random_hex(16)
|
||||
Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}') without versioning").returns({}) do
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning(@ia_bucket_name).body['VersioningConfiguration']
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}') with versioning enabled").returns('Enabled') do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Enabled')
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning(@ia_bucket_name).body['VersioningConfiguration']['Status']
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('#{@ia_bucket_name}') with versioning suspended").returns('Suspended') do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'Suspended')
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning(@ia_bucket_name).body['VersioningConfiguration']['Status']
|
||||
end
|
||||
|
||||
delete_bucket
|
||||
end
|
||||
|
||||
tests("#get_bucket_object_versions('#{@ia_bucket_name}')") do
|
||||
|
||||
create_versioned_bucket
|
||||
|
||||
before do
|
||||
@versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
end
|
||||
|
||||
v1 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
v2 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'ab', :key => v1.key)
|
||||
v3 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'abc', :key => v1.key)
|
||||
v4 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'abcd', :key => v1.key)
|
||||
|
||||
tests("versions").returns([v4.version, v3.version, v2.version, v1.version]) do
|
||||
@versions.body['Versions'].collect {|v| v['Version']['VersionId']}
|
||||
end
|
||||
|
||||
tests("version sizes").returns([4, 3, 2, 1]) do
|
||||
@versions.body['Versions'].collect {|v| v['Version']['Size']}
|
||||
end
|
||||
|
||||
tests("latest version").returns(v4.version) do
|
||||
latest = @versions.body['Versions'].find {|v| v['Version']['IsLatest']}
|
||||
latest['Version']['VersionId']
|
||||
end
|
||||
end
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', 'file')") do
|
||||
clear_bucket
|
||||
|
||||
v1 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
v2 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'ab', :key => v1.key)
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', '#{v2.key}') returns the latest version").returns(v2.version) do
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, v2.key)
|
||||
res.headers['x-amz-version-id']
|
||||
end
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', '#{v1.key}', 'versionId' => '#{v1.version}') returns the specified version").returns(v1.version) do
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, v1.key, 'versionId' => v1.version)
|
||||
res.headers['x-amz-version-id']
|
||||
end
|
||||
|
||||
v2.destroy
|
||||
|
||||
tests("get_object('#{@ia_bucket_name}', '#{v2.key}') raises exception if delete marker is latest version").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].get_object(@ia_bucket_name, v2.key)
|
||||
end
|
||||
end
|
||||
|
||||
tests("delete_object('#{@ia_bucket_name}', 'file')") do
|
||||
clear_bucket
|
||||
|
||||
file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
|
||||
tests("deleting an object just stores a delete marker").returns(true) do
|
||||
file.destroy
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
versions.body['Versions'].first.has_key?('DeleteMarker')
|
||||
end
|
||||
|
||||
tests("there are two versions: the original and the delete marker").returns(2) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
versions.body['Versions'].size
|
||||
end
|
||||
|
||||
tests("deleting the delete marker makes the object available again").returns(file.version) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(@ia_bucket_name)
|
||||
delete_marker = versions.body['Versions'].find { |v| v.has_key?('DeleteMarker') }
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, file.key, 'versionId' => delete_marker['DeleteMarker']['VersionId'])
|
||||
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, file.key)
|
||||
res.headers['x-amz-version-id']
|
||||
end
|
||||
end
|
||||
|
||||
tests("deleting_multiple_objects('#{@ia_bucket_name}", 'file') do
|
||||
clear_bucket
|
||||
|
||||
bucket = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name)
|
||||
|
||||
file_count = 5
|
||||
file_names = []
|
||||
files = {}
|
||||
file_count.times do |id|
|
||||
file_names << "file_#{id}"
|
||||
files[file_names.last] = bucket.files.create(:body => 'a',
|
||||
:key => file_names.last)
|
||||
end
|
||||
|
||||
tests("deleting an object just stores a delete marker").returns(true) do
|
||||
Fog::Storage[:internetarchive].delete_multiple_objects(@ia_bucket_name,
|
||||
file_names)
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(
|
||||
@ia_bucket_name)
|
||||
all_versions = {}
|
||||
versions.body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
next if file_names.index(object['Key']).nil?
|
||||
if !all_versions.has_key?(object['Key'])
|
||||
all_versions[object['Key']] = version.has_key?('DeleteMarker')
|
||||
else
|
||||
all_versions[object['Key']] |= version.has_key?('DeleteMarker')
|
||||
end
|
||||
end
|
||||
all_true = true
|
||||
all_versions.values.each do |marker|
|
||||
all_true = false if !marker
|
||||
end
|
||||
all_true
|
||||
end
|
||||
|
||||
tests("there are two versions: the original and the delete marker").
|
||||
returns(file_count*2) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(
|
||||
@ia_bucket_name)
|
||||
versions.body['Versions'].size
|
||||
end
|
||||
|
||||
tests("deleting the delete marker makes the object available again").
|
||||
returns(true) do
|
||||
versions = Fog::Storage[:internetarchive].get_bucket_object_versions(
|
||||
@ia_bucket_name)
|
||||
delete_markers = []
|
||||
file_versions = {}
|
||||
versions.body['Versions'].each do |version|
|
||||
object = version[version.keys.first]
|
||||
next if object['VersionId'] == files[object['Key']].version
|
||||
file_versions[object['Key']] = object['VersionId']
|
||||
end
|
||||
|
||||
Fog::Storage[:internetarchive].delete_multiple_objects(@ia_bucket_name,
|
||||
file_names,
|
||||
'versionId' => file_versions)
|
||||
all_true = true
|
||||
file_names.each do |file|
|
||||
res = Fog::Storage[:internetarchive].get_object(@ia_bucket_name, file)
|
||||
all_true = false if res.headers['x-amz-version-id'] !=
|
||||
files[file].version
|
||||
end
|
||||
all_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests("get_bucket('#{@ia_bucket_name}'") do
|
||||
clear_bucket
|
||||
|
||||
file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'file')
|
||||
|
||||
tests("includes a non-DeleteMarker object").returns(1) do
|
||||
Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name).body['Contents'].size
|
||||
end
|
||||
|
||||
file.destroy
|
||||
|
||||
tests("does not include a DeleteMarker object").returns(0) do
|
||||
Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name).body['Contents'].size
|
||||
end
|
||||
end
|
||||
|
||||
delete_bucket
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
create_versioned_bucket
|
||||
|
||||
tests("#put_bucket_versioning('#{@ia_bucket_name}', 'bad_value')").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning(@ia_bucket_name, 'bad_value')
|
||||
end
|
||||
|
||||
tests("#put_bucket_versioning('fognonbucket', 'Enabled')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].put_bucket_versioning('fognonbucket', 'Enabled')
|
||||
end
|
||||
|
||||
tests("#get_bucket_versioning('fognonbucket')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].get_bucket_versioning('fognonbucket')
|
||||
end
|
||||
|
||||
tests("#get_bucket_object_versions('fognonbucket')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:internetarchive].get_bucket_object_versions('fognonbucket')
|
||||
end
|
||||
|
||||
file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'y', :key => 'x')
|
||||
|
||||
tests("#get_object('#{@ia_bucket_name}', '#{file.key}', 'versionId' => 'bad_version'").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:internetarchive].get_object(@ia_bucket_name, file.key, 'versionId' => '-1')
|
||||
end
|
||||
|
||||
tests("#delete_object('#{@ia_bucket_name}', '#{file.key}', 'versionId' => 'bad_version'").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:internetarchive].delete_object(@ia_bucket_name, file.key, 'versionId' => '-1')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# don't keep the bucket around
|
||||
delete_bucket
|
||||
end
|
|
@ -7,7 +7,7 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
|
|||
|
||||
tests('#authentication_method') do
|
||||
@service = Fog::CDN::Rackspace.new
|
||||
|
||||
|
||||
assert_method nil, :authenticate_v2
|
||||
|
||||
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
|
||||
|
|
|
@ -12,7 +12,7 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata', ['rackspace']) do
|
|||
:image_id => rackspace_test_image_id(service))
|
||||
|
||||
@server.wait_for { ready? }
|
||||
|
||||
|
||||
tests('server') do
|
||||
collection_tests(@server.metadata, {:key => 'my_key', :value => 'my_value'}) do
|
||||
@server.wait_for { ready? }
|
||||
|
|
|
@ -101,6 +101,6 @@ Shindo.tests('Fog::Rackspace::ServiceCatalog | users', ['rackspace']) do
|
|||
service_catalog.reload
|
||||
raises(RuntimeError) { service_catalog.get_endpoint :fakeService }
|
||||
raises(RuntimeError) { service.service_catalog.get_endpoint :fakeService }
|
||||
|
||||
|
||||
end
|
||||
end
|
|
@ -41,7 +41,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
|
||||
tests('authentation v2') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
|
||||
tests('variables populated').succeeds do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :connection_options => { :ssl_verify_peer => true }
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
|
@ -65,7 +65,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
@service.head_containers
|
||||
end
|
||||
tests('custom endpoint').succeeds do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
:rackspace_storage_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||
|
@ -86,7 +86,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord\d/ ) != nil }
|
||||
@service.head_containers
|
||||
end
|
||||
end
|
||||
tests('custom endpoint') do
|
||||
@service = Fog::Storage::Rackspace.new :rackspace_storage_url => 'https://my-custom-endpoint.com'
|
||||
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||
|
@ -112,7 +112,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
|
|||
raises(Excon::Errors::Unauthorized) { Fog::Storage::Rackspace.new :rackspace_api_key => 'bad_key' }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
tests('account').succeeds do
|
||||
pending if Fog.mocking?
|
||||
Fog::Storage[:rackspace].account
|
||||
|
|
Loading…
Add table
Reference in a new issue