Skip to content

How To: Use Rackspace ServiceNet (snet) to transfer from CloudServer to CloudFiles

mathieugagne edited this page Feb 21, 2013 · 2 revisions

When your app is running on an instance in the Rackspace cloud, you will want to use their ServiceNet (snet) when storing files to CloudFiles. This will result in the transfer from your instance to CloudFiles being free of charge, and is also supposedly faster. This involves having Fog talk over your private IP address to the CloudFiles API, rather than your public IP address. Luckily, Fog already takes care of this, and CarrierWave already supports plumbing through the correct option.

Where you configure your rackspace_api_key in CarrierWave (e.g. in a yml file, an initializer, or the uploader class itself), all you need to do is to add another setting. Set rackspace_servicenet to true. For example:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider             => 'Rackspace',
    :rackspace_username   => 'xxxxxxxxx',
    :rackspace_api_key    => 'yyyyyyyyy',
    :rackspace_servicenet => true
  }
  config.fog_directory = 'name_of_container'
  config.asset_host = "c000000.cdn.rackspacecloud.com"
end

Note, that this will break your uploader if you are running from outside the Rackspace Cloud, so don't try this on your development machine. One simple way to do this is to conditionally set this flag, e.g.:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider             => 'Rackspace',
    :rackspace_username   => 'xxxxxxxxx',
    :rackspace_api_key    => 'yyyyyyyyy',
    :rackspace_servicenet => Rails.env.production?
  }
  config.fog_directory = 'name_of_container'
  config.asset_host = "c000000.cdn.rackspacecloud.com"
end
Clone this wiki locally