mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1651 from rackspace/file_docs
[Rackspace|Storage] Getting started Docs for Cloud Files
This commit is contained in:
commit
95d8e9c990
4 changed files with 492 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
|||
#Next Generation Cloud Servers™ (compute_v2)
|
||||
|
||||
This document explains how to get started using Next Gneration Cloud Servers™ with Fog. It assumes you have read the [Getting Started with Fog and the Rackspace Open Cloud](/getting_started.md) document.
|
||||
This document explains how to get started using Next Generation Cloud Servers™ with Fog. It assumes you have read the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
|
||||
|
||||
|
||||
## Starting irb console
|
||||
|
@ -31,7 +31,7 @@ Next, create a connection to the Next Gen Cloud Servers™:
|
|||
:connection_options => {} # Optional
|
||||
})
|
||||
|
||||
To learn more about obtaining cloud credentials visit the [Getting Started with Fog and the Rackspace Open Cloud](/getting_started.md) document.
|
||||
To learn more about obtaining cloud credentials refer to the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
|
||||
|
||||
By default `Fog::Compute` will connect to the DFW region. You can specify alternative regions using the key `:rackspace_endpoint ` with one of the following values:
|
||||
|
||||
|
@ -53,7 +53,7 @@ By default `Fog::Compute` will connect to the DFW region. You can specify altern
|
|||
<td>London Region</tr>
|
||||
</table>
|
||||
|
||||
**Note**: *A`Fog::Compute` instance is needed for desired region.*
|
||||
**Note**: A`Fog::Compute` instance is needed for the desired region.
|
||||
|
||||
### Optional Connection Parameters
|
||||
|
||||
|
@ -106,7 +106,7 @@ To see a list of requests supported by the service:
|
|||
|
||||
This returns:
|
||||
|
||||
:list_servers, :get_server, :create_server, :update_server, :delete_server, :change_server_password, :reboot_server, :rebuild_server, :resize_server, :confirm_resize_server, :revert_resize_server, :list_images, :get_image, :list_flavors, :get_flavor, :attach_volume, :get_attachment, :list_attachments, :delete_attachment]
|
||||
:list_servers, :get_server, :create_server, :update_server, :delete_server, :change_server_password, :reboot_server, :rebuild_server, :resize_server, :confirm_resize_server, :revert_resize_server, :list_images, :get_image, :list_flavors, :get_flavor, :attach_volume, :get_attachment, :list_attachments, :delete_attachment
|
||||
|
||||
|
||||
#### Example Request
|
||||
|
@ -123,18 +123,18 @@ To view the status of the response:
|
|||
|
||||
response.status
|
||||
|
||||
**Note**: *Fog is aware valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception.*
|
||||
**Note**: Fog is aware valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception.
|
||||
|
||||
To view response body:
|
||||
|
||||
request.body
|
||||
response.body
|
||||
|
||||
This will return:
|
||||
|
||||
{"flavors"=>[{"id"=>"2", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/2", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/2", "rel"=>"bookmark"}], "name"=>"512MB Standard Instance"}, {"id"=>"3", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/3", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/3", "rel"=>"bookmark"}], "name"=>"1GB Standard Instance"}, {"id"=>"4", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/4", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/4", "rel"=>"bookmark"}], "name"=>"2GB Standard Instance"}, {"id"=>"5", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/5", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/5", "rel"=>"bookmark"}], "name"=>"4GB Standard Instance"}, {"id"=>"6", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/6", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/6", "rel"=>"bookmark"}], "name"=>"8GB Standard Instance"}, {"id"=>"7", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/7", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/7", "rel"=>"bookmark"}], "name"=>"15GB Standard Instance"}, {"id"=>"8", "links"=>[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/flavors/8", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/flavors/8", "rel"=>"bookmark"}], "name"=>"30GB Standard Instance"}]}
|
||||
|
||||
|
||||
To learn more about Compute request methods refer to [rdoc](http://rubydoc.info/gems/fog/Fog/Compute/Rackspace/Real#reboot_server-instance_method). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon).
|
||||
To learn more about Compute request methods refer to [rdoc](http://rubydoc.info/gems/fog/Fog/Compute/Rackspace/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon).
|
||||
|
||||
### 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.
|
||||
|
@ -235,7 +235,7 @@ This returns a collection of `Fog::Compute::RackspaceV2::Image` models:
|
|||
>,
|
||||
…
|
||||
|
||||
**Note**: *In order to speed up access `service.images` does not retrieve all attribute values. To retrieve additional details you will either need to `reload` each individual image or use the request abstraction.*
|
||||
**Note**: In order to speed up access `service.images` does not retrieve all attribute values. To retrieve additional details you will either need to `reload` each individual image or use the request abstraction.
|
||||
|
||||
## Get Image
|
||||
|
||||
|
@ -261,8 +261,7 @@ This returns an `Fog::Compute::RackspaceV2::Image` instance:
|
|||
links=[{"href"=>"https://ord.servers.api.rackspacecloud.com/v2/772045/images/8a3a9f96-b997-46fd-b7a8-a9e740796ffd", "rel"=>"self"}, {"href"=>"https://ord.servers.api.rackspacecloud.com/772045/images/8a3a9f96-b997-46fd-b7a8-a9e740796ffd", "rel"=>"bookmark"}, {"href"=>"https://ord.images.api.rackspacecloud.com/772045/images/8a3a9f96-b997-46fd-b7a8-a9e740796ffd", "type"=>"application/vnd.openstack.image", "rel"=>"alternate"}]
|
||||
>
|
||||
|
||||
**Note**: *This request populates all Image attributes.*
|
||||
|
||||
**Note**: This request populates all Image attributes.
|
||||
|
||||
## List Flavors
|
||||
|
||||
|
@ -292,7 +291,7 @@ This returns a collection of `Fog::Compute::RackspaceV2::Flavor` models:
|
|||
>,
|
||||
…
|
||||
|
||||
**Note**: *In order to speed up access `service.flavors` does not retrieve all attribute values. To retrieve additional details you will either need to `reload` each individual flavor or use the request abstraction.*
|
||||
**Note**: In order to speed up access `service.flavors` does not retrieve all attribute values. To retrieve additional details you will either need to `reload` each individual flavor or use the request abstraction.
|
||||
|
||||
|
||||
## Get Flavor
|
||||
|
@ -312,7 +311,7 @@ This returns a `Fog::Compute::RackspaceV2::Flavor` instance:
|
|||
links=[{"href"=>"https://dfw.servers.api.rackspacecloud.com/v2/772045/flavors/2", "rel"=>"self"}, {"href"=>"https://dfw.servers.api.rackspacecloud.com/772045/flavors/2", "rel"=>"bookmark"}]
|
||||
>
|
||||
|
||||
**Note**: *This request populates all Flavor attributes.*
|
||||
**Note**: This request populates all Flavor attributes.
|
||||
|
||||
|
||||
## List Servers
|
||||
|
@ -447,9 +446,10 @@ Fog can wait for the server to become ready as follows:
|
|||
|
||||
server.wait_for { ready? }
|
||||
|
||||
**Note**: *The `Fog::Compute::RackspaceV2::Server` instance returned from the create method contains a `password` attribute. The `password` attribute will NOT be present in subsequent retrievals either through `service.servers` or `server.servers.get my_server_id`*.
|
||||
**Note**: The `Fog::Compute::RackspaceV2::Server` instance returned from the create method contains a `password` attribute. The `password` attribute will NOT be present in subsequent retrievals either through `service.servers` or `server.servers.get my_server_id`.
|
||||
|
||||
### Additional Parameters
|
||||
|
||||
The `create` method also supports the following key values:
|
||||
|
||||
<table>
|
||||
|
@ -468,7 +468,7 @@ The `create` method also supports the following key values:
|
|||
<tr>
|
||||
<td>:personality</td>
|
||||
<td>File path and contents. Refer to Next Gen Server API documentation - <a href="http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html">Server Personality</a>. </td>
|
||||
</tr>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Update Server
|
||||
|
@ -484,14 +484,14 @@ To update these attributes:
|
|||
|
||||
Additional information about server access addresses can be found [here](http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Primary_Addresses-d1e2558.html).
|
||||
|
||||
**Note**: *Updating the server name does not change the host name. Names are not guaranteed to be unique.*
|
||||
**Note**: Updating the server name does not change the host name. Names are not guaranteed to be unique.
|
||||
|
||||
## Delete Server
|
||||
To delete a server:
|
||||
|
||||
server.destroy
|
||||
|
||||
**Note**: *The server is not immediately destroyed, but it does occur shortly there after.*
|
||||
**Note**: The server is not immediately destroyed, but it does occur shortly there after.
|
||||
|
||||
## Metadata
|
||||
You can access metadata as an attribute on both `Fog::Compute::RackspaceV2::Server` and `Fog::Compute::RackspaceV2::Metadata::Image`. You can specify metadata during creation of a server or an image. Please refer to [Create Server](#create-server) or [Create Image](#create-image) sections for more information.
|
||||
|
@ -595,7 +595,7 @@ In this case, `wait_for` is waiting for the server to become `VERIFY_READY` and
|
|||
|
||||
Once a server enters the `VERIFY_RESIZE` we will need to call `confirm_resize` to confirm the server was properly resized or `revert_resize` to rollback to the old size/flavor.
|
||||
|
||||
**Note:** *A server will automatically confirm resize after 24 hours.*
|
||||
**Note:** A server will automatically confirm resize after 24 hours.
|
||||
|
||||
To confirm resize:
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@ You should now be able to execute the following command to see a list of service
|
|||
|
||||
These services can be explored in further depth in the following documents:
|
||||
|
||||
* [Next Generation Cloud Servers™ (compute_v2)](/cloud_servers.md)
|
||||
* Cloud Files™ (storage)
|
||||
* [Next Generation Cloud Servers™ (compute_v2)](compute_v2.md)
|
||||
* [Cloud Files™ (storage)](storage.md)
|
||||
* Cloud Block Storage (block_storage)
|
||||
|
||||
**Note**: *The compute service provides an interface to the First Geneneration Cloud Servers™ (compute). This service is deprecated. Users are encouraged to use Next Geneneration Cloud Servers™ (compute_v2).*
|
||||
**Note**: The compute service provides an interface to the First Geneneration Cloud Servers™ (compute). This service is deprecated. Users are encouraged to use Next Geneneration Cloud Servers™ (compute_v2).
|
||||
|
||||
## Additional Resources
|
||||
* [fog.io](http://fog.io)
|
||||
|
|
471
lib/fog/rackspace/docs/storage.md
Normal file
471
lib/fog/rackspace/docs/storage.md
Normal file
|
@ -0,0 +1,471 @@
|
|||
#Cloud Files™ (storage)
|
||||
|
||||
This document explains how to get started using Cloud Files with Fog. It assumes you have read the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
|
||||
|
||||
|
||||
## Starting irb console
|
||||
Start by executing the following command:
|
||||
|
||||
irb
|
||||
|
||||
Once `irb` has launched you need to require the Fog library.
|
||||
|
||||
If using Ruby 1.8.x execute:
|
||||
|
||||
require 'rubygems'
|
||||
require 'fog'
|
||||
|
||||
If using Ruby 1.9.x execute:
|
||||
|
||||
require 'fog'
|
||||
|
||||
## Create Service
|
||||
|
||||
Next, create a connection to Cloud Files.
|
||||
|
||||
Using a US based account:
|
||||
|
||||
service = Fog::Storage.new({
|
||||
:provider => 'Rackspace', # Rackspace Fog provider
|
||||
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
|
||||
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
|
||||
:rackspace_region => :ord # Defaults to :dfw
|
||||
:connection_options => {} # Optional
|
||||
})
|
||||
|
||||
Using a UK based account:
|
||||
|
||||
service = Fog::Storage.new({
|
||||
:provider => 'Rackspace', # Rackspace Fog provider
|
||||
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
|
||||
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
|
||||
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT
|
||||
:rackspace_region => :lon
|
||||
:connection_options => {} # Optional
|
||||
})
|
||||
|
||||
To learn more about obtaining cloud credentials refer to the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
|
||||
|
||||
By default `Fog::Storage` will authenticate against the US authentication endpoint and connect to the DFW region. You can specify alternative authentication endpoints using the key `:rackspace_auth_url`. Please refer to [Alternate Authentication Endpoints](http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/Endpoints-d1e180.html) for a list of alternative Rackspace authentication endpoints.
|
||||
|
||||
Alternative regions are specified using the key `:rackspace_region `. A list of regions available for Cloud Files can be found by executing the following:
|
||||
|
||||
identity_service = Fog::Identity({
|
||||
:provider => 'Rackspace', # Rackspace Fog provider
|
||||
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
|
||||
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
|
||||
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT # Not specified for US Cloud
|
||||
})
|
||||
|
||||
identity_service.service_catalog.display_service_regions :cloudFiles
|
||||
|
||||
|
||||
**Note**: A`Fog::Storage` instance is needed for the desired region.
|
||||
|
||||
### Optional Service Parameters
|
||||
|
||||
The Storage service supports the following additional parameters:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:rackspace_servicenet</td>
|
||||
<td>If set to true, the service will access Cloud Files using the internal Rackspace ServiceNet. This option should only be used for internal network connections.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:rackspace_cdn_ssl</td>
|
||||
<td>If set to true, the public_url method will return the SSL based URLs.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:persistent</td>
|
||||
<td>If set to true, the service will use a persistent connection.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:rackspace_storage_url</td>
|
||||
<td>The endpoint for the Cloud Files service. By default, Fog::Storage will pick the appropriate endpoint for region. This option will typically only be used for Rackspace Private Cloud Access.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:rackspace_cdn_url</td>
|
||||
<td>The endpoint for the CDN service. By default, Fog::Storage pick the appropriate endpoint for region. This option will typically only be used for Rackspace Private Cloud Access.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:chunk_size</td>
|
||||
<td>The chunk size in bytes to use for block transfers. By default, Fog uses 1 MB chunks.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
### Optional Connection Parameters
|
||||
|
||||
Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using `:connection_options`.
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:connect_timeout</td>
|
||||
<td>Connection timeout (default: 60 seconds)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:read_timeout</td>
|
||||
<td>Read timeout for connection (default: 60 seconds)</td> </tr>
|
||||
<tr>
|
||||
<td>:write_timeout</td>
|
||||
<td>Write timeout for connection (default: 60 seconds)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:proxy</td>
|
||||
<td>Proxy for HTTP and HTTPS connections</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:ssl_ca_path</td>
|
||||
<td>Path to SSL certificate authorities</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:ssl_ca_file</td>
|
||||
<td>SSL certificate authority file</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:ssl_verify_peer</td>
|
||||
<td>SSL verify peer (default: true)</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
## Fog Abstractions
|
||||
Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface.
|
||||
|
||||
### Request Layer
|
||||
The request abstraction maps directly to the [Cloud Files API](http://docs.rackspace.com/files/api/v1/cf-devguide/content/Overview-d1e70.html). It provides the most efficient interface to the Rackspace Open Cloud.
|
||||
|
||||
To see a list of requests supported by the storage service:
|
||||
|
||||
service.requests
|
||||
|
||||
This returns:
|
||||
|
||||
:copy_object, :delete_container, :delete_object, :get_container, :get_containers, :get_object, :get_object_https_url, :head_container, :head_containers, :head_object, :put_container, :put_object, :put_object_manifest, :post_set_meta_temp_url_key
|
||||
|
||||
To see a list of requests supported by the CDN service:
|
||||
|
||||
service.cdn.requests
|
||||
|
||||
This returns:
|
||||
|
||||
:get_containers, :head_container, :post_container, :put_container, :delete_object
|
||||
|
||||
|
||||
#### Example Request
|
||||
|
||||
To request a view account details:
|
||||
|
||||
response = service.head_containers
|
||||
|
||||
This returns in the following `Excon::Response`:
|
||||
|
||||
#<Excon::Response:0x10283fc68 @headers={"X-Account-Bytes-Used"=>"2563554", "Date"=>"Thu, 21 Feb 2013 21:57:02 GMT", "X-Account-Meta-Temp-Url-Key"=>"super_secret_key", "X-Timestamp"=>"1354552916.82056", "Content-Length"=>"0", "Content-Type"=>"application/json; charset=utf-8", "X-Trans-Id"=>"txe934924374a744c8a6c40dd8f29ab94a", "Accept-Ranges"=>"bytes", "X-Account-Container-Count"=>"7", "X-Account-Object-Count"=>"5"}, @status=204, @body="">
|
||||
|
||||
To view the status of the response:
|
||||
|
||||
response.status
|
||||
|
||||
**Note**: Fog is aware of the 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.headers
|
||||
|
||||
This will return:
|
||||
|
||||
{"X-Account-Bytes-Used"=>"2563554", "Date"=>"Thu, 21 Feb 2013 21:57:02 GMT", "X-Account-Meta-Temp-Url-Key"=>"super_secret_key", "X-Timestamp"=>"1354552916.82056", "Content-Length"=>"0", "Content-Type"=>"application/json; charset=utf-8", "X-Trans-Id"=>"txe934924374a744c8a6c40dd8f29ab94a", "Accept-Ranges"=>"bytes", "X-Account-Container-Count"=>"7", "X-Account-Object-Count"=>"5"}
|
||||
|
||||
|
||||
To learn more about `Fog::Storage` request methods refer to [rdoc](http://rubydoc.info/gems/fog/Fog/Storage/Rackspace/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon).
|
||||
|
||||
### 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.
|
||||
|
||||
Here is a summary of common model methods:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Method</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>create</td>
|
||||
<td>
|
||||
Accepts hash of attributes and creates object.<br>
|
||||
Note: creation is a non blocking call and you will be required to wait for a valid state before using resulting object.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>save</td>
|
||||
<td>Saves object.<br>
|
||||
Note: not all objects support updating object.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>destroy</td>
|
||||
<td>
|
||||
Destroys object.<br>
|
||||
Note: this is a non blocking call and object deletion might not be instantaneous.
|
||||
</td>
|
||||
<tr>
|
||||
<td>reload</td>
|
||||
<td>Updates object with latest state from service.</td>
|
||||
<tr>
|
||||
<td>attributes</td>
|
||||
<td>Returns a hash containing the list of model attributes and values.</td>
|
||||
</tr>
|
||||
<td>identity</td>
|
||||
<td>
|
||||
Returns the identity of the object.<br>
|
||||
Note: This might not always be equal to object.id.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
The remainder of this document details the model abstraction.
|
||||
|
||||
**Note:** Fog refers to Rackspace Cloud containers as directories.
|
||||
|
||||
## List Directories
|
||||
|
||||
To retrieve a list of directories:
|
||||
|
||||
service.directories
|
||||
|
||||
This returns a collection of `Fog::Storage::Rackspace::Directory` models:
|
||||
|
||||
<Fog::Storage::Rackspace::Directories
|
||||
[
|
||||
<Fog::Storage::Rackspace::Directory
|
||||
key="blue",
|
||||
bytes=434266,
|
||||
count=1,
|
||||
cdn_cname=nil
|
||||
>,
|
||||
<Fog::Storage::Rackspace::Directory
|
||||
key="brown",
|
||||
bytes=761879,
|
||||
count=1,
|
||||
cdn_cname=nil
|
||||
>,
|
||||
...
|
||||
|
||||
## Get Directory
|
||||
|
||||
To retrieve a specific directory:
|
||||
|
||||
service.directories.get "blue"
|
||||
|
||||
This returns a `Fog::Storage::Rackspace::Directory` instance:
|
||||
|
||||
<Fog::Storage::Rackspace::Directory
|
||||
key="blue",
|
||||
bytes=434266,
|
||||
count=1,
|
||||
cdn_cname=nil
|
||||
>
|
||||
|
||||
## Create Drectory
|
||||
|
||||
To create a directory:
|
||||
|
||||
service.directories.create :key => 'backups'
|
||||
|
||||
To create a directory utilizing CDN:
|
||||
|
||||
service.directories.create :key => 'web-assets', :public => true
|
||||
|
||||
### Additional Parameters
|
||||
|
||||
The `create` method also supports the following key values:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:metadata</td>
|
||||
<td>Hash containing directory metadata.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
## Update Directory
|
||||
|
||||
Cloud Files supports updating the `public` attribute to enable/disable CDN.
|
||||
|
||||
To update this attribute:
|
||||
|
||||
directory.public = false
|
||||
directory.save
|
||||
|
||||
## Delete Directory
|
||||
|
||||
To delete a directory:
|
||||
|
||||
directory.destroy
|
||||
|
||||
**Note**: Directory must be empty before it can be deleted.
|
||||
|
||||
## List Files
|
||||
|
||||
To list files in a directory:
|
||||
|
||||
directory.files
|
||||
|
||||
## Upload Files
|
||||
|
||||
To upload a file into a directory:
|
||||
|
||||
file = directory.files.create :key => 'space.jpg', :body => File.open "space.jpg"
|
||||
|
||||
### Additional Parameters
|
||||
|
||||
The `create` method also supports the following key values:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:content_type</td>
|
||||
<td>The content type of the object. Cloud Files will attempt to auto detect this value if omitted.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:access_control_allow_origin</td>
|
||||
<td>URLs can make Cross Origin Requests. Format is http://www.example.com. Separate URLs with a space. An asterisk (*) allows all. Please refer to <a href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/CORS_Container_Header-d1e1300.html">CORS Container Headers</a> for more information.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:origin</td>
|
||||
<td>The origin is the URI of the object's host.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:etag</td>
|
||||
<td>The MD5 checksum of your object's data. If specified, Cloud Files will validate the integrity of the uploaded object.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>:metadata</td>
|
||||
<td>Hash containing file metadata.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Download Files
|
||||
|
||||
The most efficient way to download files from a private or public directory is as follows:
|
||||
|
||||
File.open('downloaded-file.jpg', 'w') do | f |
|
||||
directory.files.get("my_big_file.jpg") do | data, remaining, content_length |
|
||||
f.syswrite data
|
||||
end
|
||||
end
|
||||
|
||||
This will download and save the file in 1 MB chunks. The chunk size can be changed by passing the parameter :chunk_size into the :connection_options hash in the service constructor.
|
||||
|
||||
**Note**: The `body` attribute of file will be empty if a file has been downloaded using this method.
|
||||
|
||||
If a file object has already been loaded into memory, you can save it as follows:
|
||||
|
||||
File.open('germany.jpg', 'w') {|f| f.write(file_object.body) }
|
||||
|
||||
**Note**: This method is more memory intensive as the entire object is loaded into memory before saving the file as in the example above.
|
||||
|
||||
|
||||
## Accessing Files Through CDN
|
||||
|
||||
The CDN service offers several different URLs to access your files.
|
||||
|
||||
The simplest is with the default container URL. This can be accessed as follows:
|
||||
|
||||
file.public_url
|
||||
|
||||
For a more user-friendly URL, you can create a `CNAME` DNS record pointing to the URL generated by the `public_url` method. Then set the`CNAME` on the `Directory` object using the attribute `cdn_cname`. Note, that the `cdn_cname` attribute does not persist and will need to be specified every time a directory object is retrieved.
|
||||
|
||||
To access the file using SSL, you need to specify the option `:rackspace_cdn_ssl => true` when creating `Fog::Storage` service. This will cause the `public_url` method to return the SSL-secured URL.
|
||||
|
||||
To stream content use the following:
|
||||
|
||||
file.streaming_url
|
||||
|
||||
To stream video for iOS devices without needing to convert your video use the following:
|
||||
|
||||
file.ios_url
|
||||
|
||||
|
||||
## Metadata
|
||||
|
||||
You can access metadata as an attribute on both `Fog::Storage::Rackspace::Directory` and `Fog::Storage::Rackspace::File`.
|
||||
|
||||
This example demonstrates how to iterate through a directory's metadata:
|
||||
|
||||
directory.metadata.each_pair {|metadatum| puts "#{metadatum.key}: #{metadatum.value}" }
|
||||
|
||||
You can update and retrieve metadata in a manner similar to a hash:
|
||||
|
||||
directory.metadata[:thumbnails]
|
||||
|
||||
file.metadata[:environment] = "development"
|
||||
|
||||
Directory metadata is saved when the directory is saved and file metadata is set when the file is saved:
|
||||
|
||||
directory.save
|
||||
|
||||
file.save
|
||||
|
||||
Metadata is reloaded when directory or file is reloaded:
|
||||
|
||||
directory.reload
|
||||
|
||||
file.reload
|
||||
|
||||
## Copy File
|
||||
|
||||
Cloud Files supports copying files. To copy files into a container named "trip" with a name of "europe.jpg" do the following:
|
||||
|
||||
file.copy("trip", "europe.jpg")
|
||||
|
||||
To move or rename a file, perform a copy operation and then delete the old file:
|
||||
|
||||
file.copy("trip", "germany.jpg")
|
||||
file.destroy
|
||||
|
||||
## Delete File
|
||||
|
||||
To delete a file:
|
||||
|
||||
file.destroy
|
||||
|
||||
## CDN Purge
|
||||
|
||||
To immediately remove a file from the CDN network use the following:
|
||||
|
||||
file.purge_from_cdn
|
||||
|
||||
You may only purge up to 25 objects per day and thus this should only be used in situations where there could be serious personal, business, or security consequences if the object remained in the CDN. To purge a directory, please contact Rackspace support.
|
||||
|
||||
**Note**: You may only **PURGE** up to 25 objects per day. Any attempt to purge more than this will result in a 498 status code error (Rate Limited).
|
||||
|
||||
## Account Information
|
||||
|
||||
To view Cloud Files usage execute the following:
|
||||
|
||||
service.account
|
||||
|
||||
This returns a response similar to the following:
|
||||
|
||||
<Fog::Storage::Rackspace::Account
|
||||
meta_temp_url_key="lkkl23jl2j3",
|
||||
container_count=13,
|
||||
bytes_used=2563554,
|
||||
object_count=5
|
||||
>
|
||||
|
|
@ -28,7 +28,7 @@ Examples will prompt for Rackspace Open Cloud credentials. Prompts can be skippe
|
|||
rackspace_username: RACKSPACE_USERNAME
|
||||
rackspace_api_key: RACKSPACE_API_KEY
|
||||
|
||||
***Note:* Replace capitalized values with the appropriate credential information.*
|
||||
**Note:** Replace capitalized values with the appropriate credential information.
|
||||
|
||||
## Executing
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue