| Class | OpenStack::Swift::Container |
| In: |
lib/openstack/swift/container.rb
|
| Parent: | Object |
| metadata | [R] | |
| name | [R] | |
| swift | [R] |
Creates a new OpenStack::Swift::StorageObject in the current container. If an object with the specified name exists in the current container, that object will be overwritten
optional headers: {
:metadata=>{key=>value, key1=>value1, ...}
:content_type=>content type of created object
:etag=>MD5 checksum of object data to be compared to that on server side
:manifest=>set manifest header for segmented large object
}
The optional data can be a File or a String - see StorageObject.create and .write methods
Removes an OpenStack::Swift::StorageObject from a container. True is returned if the removal is successful. Throws OpenStack::Exception::ItemNotFound if the object doesn‘t exist.
container.delete_object('new.txt')
=> true
container.delete_object('Foo')
=>OpenStack::Exception::ItemNotFound: The object: "Foo" does not exist in container "another_containerfoo". The resource could not be found
Returns true if a container is empty and returns false otherwise.
new_container.empty? => true full_container.empty? => false
Returns the OpenStack::Swift::StorageObject for the named object. Refer to the OpenStack::Swift::StorageObject class for available methods. If the object exists, it will be returned. If the object does not exist, a OpenStack::Exception::ItemNotFound will be thrown.
object = container.object('test.txt')
object.data
=> "This is test data"
object = container.object('newfile.txt')
=> OpenStack::Exception::ItemNotFound: No Object "newfile.txt" found in Container "another_container_foo"
Returns true if object exists and returns false otherwise.
container.object_exists?('goodfile.txt')
=> true
container.object_exists?('badfile.txt')
=> false
Gathers a list of all available objects in the current container and returns an array of object names.
container = cf.container("My Container")
container.objects
=> [ "cat", "dog", "donkey", "monkeydir", "monkeydir/capuchin"]
Pass a limit argument to limit the list to a number of objects:
container.objects(:limit => 1) #=> [ "cat" ]
Pass an marker with or without a limit to start the list at a certain object:
container.objects(:limit => 1, :marker => 'dog') #=> [ "donkey" ]
Pass a prefix to search for objects that start with a certain string:
container.objects(:prefix => "do") #=> [ "dog", "donkey" ]
Only search within a certain pseudo-filesystem path:
container.objects(:path => 'monkeydir') #=> ["monkeydir/capuchin"]
Only grab "virtual directories", based on a single-character delimiter (no "directory" objects required):
container.objects(:delimiter => '/') #=> ["monkeydir"]
All arguments to this method are optional.
Returns an empty array if no object exist in the container. if the request fails.
Retrieves a list of all objects in the current container along with their size in bytes, hash, and content_type. If no objects exist, an empty hash is returned.
Accepts the same options as ‘objects’ method to limit the returned set.
container.objects_detail
=> {"test.txt"=>{:content_type=>"application/octet-stream",
:hash=>"e2a6fcb4771aa3509f6b27b6a97da55b",
:last_modified=>Mon Jan 19 10:43:36 -0600 2009,
:bytes=>"16"},
"new.txt"=>{:content_type=>"application/octet-stream",
:hash=>"0aa820d91aed05d2ef291d324e47bc96",
:last_modified=>Wed Jan 28 10:16:26 -0600 2009,
:bytes=>"22"}
}
Sets the metadata for a container. By passing a hash as an argument, you can set the metadata for an object. New calls to set metadata are additive. To remove metadata, set the value of the key to nil. Including the X-Container-Meta- prefix for each metadata key is optional:
container = os.container("foo") container.set_metadata({"X-Container-Meta-Author"=> "msa", "version"=>"1.2", :date=>"today"})
container.metadata
Returns true if operation is successful; Throws OpenStack::Exception::ItemNotFound if the container doesn‘t exist.