• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

Connecting to CloudFiles


Introduction

This page will walk you through connecting to CloudFiles from your CloudServer. CloudServers have a special feature that will allow you to communicate directly with CloudFiles without being charged bandwidth. This is possible because of the internal IP address that your server comes with called a ServiceNet.

If you are not familiar with CloudFiles you might want to take a look at our product information located here: www.rackspace.com/cloud/cloud_hosting_products/files/

API/Developer Documentation

To view or download the API documentation please visit docs.rackspace.com/api/ and go to the Cloud Files section.

You can also access the documentation and some code samples from docs.rackspace.com/sdks/guide/content/intro.html or from within the Classic Cloud Control Panel by navigating to "Support" on the left and then "Developer Resources".  We have code samples available for PHP, Python, and Java.

Connection Information

Cloud Servers can connect to Cloud Files, without bandwidth charges, when the Cloud Server and Cloud Files account are in the same data center. To accomplish this you must use the internal network host name. The host name will be the Cloud Files storage url with "snet-" pre-pended to it. Please keep in mind that you will still be charged for requests and storage.

You can locate your Cloud Server data center two ways:

  • New Control Panel -- Locate your Cloud Files data center under the "Region" column on the Files screen.
  • Through the API --  Your Cloud Files data center can be found in the storage url returned when you authenticate to Cloud Files. 

To demonstrate how this can be accomplished, here's an example with the PHP API.

 <?php
 require("cloudfiles.php");
 
 # Insert valid credentials
 #
 $auth = new CF_Authentication($USERNAME, $API_KEY);
 
 # enable verbose output from curl and authenticate
 #
 $auth->setDebug(1);
 $auth->authenticate();
 
 # print out storage url (storage.clouddrive.com or storage4.clouddrive.com)
 #
 print $auth->storage_url . "\n";
 
 # create the service net version (prepend 'snet-' to FQDN
 #
 $sn_url = "https://snet-" . substr($auth->storage_url, strlen("https://"));
 print $sn_url . "\n";
 
 # set the auth's storage url to the service net version
 #
 $auth->storage_url = $sn_url;
 
 # grab a connection to the storage system via service net
 #
 $conn = new CF_Connection($auth);
 $conn->setDebug(1);
 
 print_r($conn->list_containers());
 
 ?>

Note that the code example is intended to illustrate building a ServiceNet storage URL, but some of the language bindings (including PHP) offer ways to specify ServiceNet connections instead of needing to build a full URL.  So for that code example, it would be possible to remove the sections that create $sn_url and set it as the storage URL by changing the new connection line to:

 $conn = new CF_Connection($auth, $servicenet=TRUE);


© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

5 Comments

Looks like the API documentation is no longer at the bottom of the page in the instructions and has moved to the following link:
http://www.rackspace.com/cloud/cloud_hosting_products/files/api/

Thanks Travis. I'll update the article to point people to the right places for the API docs and code samples.

Hi,

I discovered that we could used this method too:

<code>
$conn = new CF_Connection($auth, TRUE); //the boolean forces connection throughout ServiceNet
</code>

Thanks Pv, that is a simpler approach than building the servicenet URL yourself. We'll look into trimming that section of the sample code.

For reference, the python equivalent is:

conn = cloudfiles.get_connection(username,api_key,servicenet=True)

Add new comment