<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>some thoughts &#187; Cloud Files</title>
	<atom:link href="http://programmerthoughts.com/topics/programming/cloud-files-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmerthoughts.com</link>
	<description></description>
	<lastBuildDate>Sun, 25 Jul 2010 16:58:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Server-side Object Copy in OpenStack storage</title>
		<link>http://programmerthoughts.com/programming/server-side-object-copy-in-openstack-storage/</link>
		<comments>http://programmerthoughts.com/programming/server-side-object-copy-in-openstack-storage/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 03:05:11 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Cloud Files]]></category>
		<category><![CDATA[openstack]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://programmerthoughts.com/?p=433</guid>
		<description><![CDATA[Suppose you upload a file to Cloud Files or another implementation of OpenStack storage with the wrong object name or you needed to move some objects to another container. Without a server-side copy feature, you would need to reupload the same content and delete the existing object. With server-side object copy, you can save the step of re-uploading the content and thus also save the associated bandwidth charges, if any were to apply.]]></description>
			<content:encoded><![CDATA[<p><a href="http://openstack.org">OpenStack storage</a> (codenamed <a href="http://launchpad.net/swift">swift</a>) supports server-side object copy.</p>
<p>Suppose you upload a file with the wrong object name or you needed to move some objects to another container. Without a server-side copy feature, you would need to reupload the same content and delete the existing object. With server-side object copy, you can save the step of re-uploading the content and thus also save the associated bandwidth charges, if any were to apply.</p>
<p>There are two ways to copy an existing object to another object in swift. One, do a PUT to the new object (the target) location, but add the &#8220;X-Copy-From&#8221; header to designate the source of the data. The header value should be the container and object name of the source object in the form of &#8220;/container/object&#8221;.</p>
<p>The second way to do an object copy is similar. This time, do a COPY to the existing object, and include the &#8220;Destination&#8221; header to specify the target of the copy. The header value is the container and new object name in the form or &#8220;/container/object&#8221;.</p>
<p>With both of these methods, the destination container must exist before attempting the copy.</p>
<p>If you were wanting to perform a move of the objects rather than a copy, you would need to send a DELETE request to the old object. A move simply becomes a COPY + DELETE.</p>
]]></content:encoded>
			<wfw:commentRss>http://programmerthoughts.com/programming/server-side-object-copy-in-openstack-storage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cloud Files CDN Stats</title>
		<link>http://programmerthoughts.com/programming/cloud-files-cdn-stats/</link>
		<comments>http://programmerthoughts.com/programming/cloud-files-cdn-stats/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 22:57:14 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Cloud Files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[cloud files]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://programmerthoughts.com/?p=385</guid>
		<description><![CDATA[I wrote a small Python script that loads Cloud Files CDN log files and aggregates the data. The code is available in <a href="http://github.com/notmyname/python_scripts/tree/master/cf_stats/">my github account</a>.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.rackspacecloud.com/cloud_hosting_products/files">Cloud Files</a> offers public content through Limelight&#8217;s CDN network. On public containers, one can opt in to save the logs for all content requested from the CDN. These logs are for the raw usage in an apache log format and are stored compressed in a container named &#8220;.CDN_ACCESS_LOGS&#8221;. One can then parse these logs with any commercial analytics tool or use a custom solution. Being a developer, I wrote a small Python script that loads these log files and aggregates the data.</p>
<p>The code can be found in <a href="http://github.com/notmyname/python_scripts/tree/master/cf_stats/">my github repository</a>.</p>
<p>After updating the code with your own Cloud Files credentials (or using your own cf_auth module), usage is similar to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="shell" style="font-family:monospace;">$ ./cf_stats.py obj_name</pre></td></tr></table></div>

<p>&#8220;obj_name&#8221; is one of the keys the stats can be grouped on. Others include &#8220;date&#8221;, &#8220;container_name&#8221;, and &#8220;user_agent&#8221;. The default is &#8220;obj_name&#8221; and any incorrect parameter will generate a usage message.</p>
<p>Sample output:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="shell" style="font-family:monospace;">Object Name: my_file.pdf
Count: 11
User Agents: &quot;Yandex/1.01.001 (compatible; Win16; I)&quot;
Response: 200 304
Referrers: -
IPs: 1.2.3.4 1.2.3.5 1.2.3.6
Dates: 24/Jan/2010 25/Jan/2010 31/Jan/2010 01/Jan/2010 30/Dec/2009
Container Name: some_container</pre></td></tr></table></div>

<p>Any of the given fields can be used as a group. Even if the code output as-is is not to your liking, the script&#8217;s parsing and grouping functions my be a good starting point for writing your own log parser.</p>
]]></content:encoded>
			<wfw:commentRss>http://programmerthoughts.com/programming/cloud-files-cdn-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nested folders in Cloud Files</title>
		<link>http://programmerthoughts.com/programming/nested-folders-in-cloud-files/</link>
		<comments>http://programmerthoughts.com/programming/nested-folders-in-cloud-files/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 03:03:51 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Cloud Files]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://programmerthoughts.com/?p=363</guid>
		<description><![CDATA[Cloud Files is a storage system, not a file system. Containers are like high-level groupings of objects, but they cannot be nested. In this post, I show how to use delimiters in an object's name to simulate a nested folder hierarchy in Cloud Files, complete with object listings on these virtual nested folders.]]></description>
			<content:encoded><![CDATA[<p>Cloud storages systems like <a href="http://www.rackspacecloud.com/cloud_hosting_products/files">Rackspace&#8217;s Cloud Files</a> and <a href="http://aws.amazon.com/s3/">Amazon&#8217;s S3</a> are great for storing large amounts of information. A common misconception is that these storage systems behave like traditional file systems, complete with byte-level manipulation and nested folders. It is the second of these that I want to talk about: how to simulate a nested directory (or folder) structure in Rackspace&#8217;s Cloud Files.</p>
<p>Cloud Files and S3 are better understood as storage systems, not file systems. Each have three basic parts: accounts, containers (buckets in S3), and objects. In Cloud Files, these three parts can be easily seen in the URL referencing an object. The URL one uses for the ReST API is of the form http://example.clouddrive.com/account/container/object. Containers are large-scale groupings of objects, operating at a higher level, conceptually, than folders. If objects were books, containers may be genres. Containers cannot be nested. That is, one cannot put a container inside of another container.</p>
<p>However, it is fairly easy to simulate a directory structure with objects. These &#8220;virtual directories&#8221; are not directories, per se, but object name prefixes over which one can iterate. An example should make this concept easy to understand. Suppose I wanted to store books in Cloud Files. From my analogy above, I can use the genre of the book as my container name. The object name will be of the form &#8220;author/title&#8221;. This way, I can list all books by a particular author (within a genre).</p>
<p>Let&#8217;s load the following books into Cloud Files:</p>
<ul>
<li>The Pit and the Pendulum, Poe, Horror</li>
<li>The Masque of the Red Death, Poe, Horror</li>
<li>Pride and Prejudice and Zombies, Grahame-Smith, Horror</li>
<li>The Far Side Gallery, Larson, Comics</li>
<li>Something Under the Bed Is Drooling, Watterson, Comics</li>
<li>It&#8217;s A Magical World, Watterson, Comics</li>
</ul>
<p>First, I will create two containers, horror and comics. Next I will name my files according to the pattern I laid out above. I will have the files &#8220;poe/the_pit_and_the_pendulum&#8221;, &#8220;poe/the_masque_of_the_red_death&#8221;, &#8220;larson/the_far_side_gallery&#8221;, etc. Then I will upload these files to their appropriate container. As a final step, I need to upload &#8220;directory marker&#8221; files. These are empty (zero-sized) files with a content-type of &#8220;application/directory&#8221;.</p>
<p>[The following gets technical. For those wishing to use this feature of Cloud Files and not wanting to program, I recommend using a third-party tool like <a href="http://cyberduck.ch/">Cyberduck</a> (if you are using a Mac) or <a href="http://fireuploader.com/">Fireuploader</a> (for Firefox users). The programs handle virtual nested directories completely transparently.]</p>
<p>Now to take advantage of these &#8220;virtual directories&#8221;, I can do container listings and give an appropriate path value. In the Python language bindings, this would look similar to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">container = cf_connection.<span style="color: black;">get_container</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'horror'</span><span style="color: black;">&#41;</span>
books_by_poe = container.<span style="color: black;">get_objects</span><span style="color: black;">&#40;</span>path=<span style="color: #483d8b;">'poe'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>The path parameter on the get_objects call returns all objects in the given value. In this case, it returns the two books in the virtual &#8220;poe&#8221; directory. Similarly, if I had given the value &#8220;grahame-smith&#8221;, I would have found his adaptation of the classic love story.</p>
<p>In my example, I&#8217;ve used two genre containers and virtual directories only one level deep. I could just as easily put everything into one container and nested the authors under a genre virtual directory. An object name would then be like &#8220;comics/larson/the_far_side_gallery&#8221;. The only limitation to using this feature in Cloud Files is keeping the length of the object name (including all virtual directories) under the maximum allowed (1024 characters).</p>
<p>For more detailed information on how to implement virtual directories, see the <a href="http://www.rackspacecloud.com/files/cf-devguide-20090812.pdf">Cloud Files developer guide</a>. The relevant information is found in the &#8220;Pseudo hierarchical folders/directories&#8221; section.</p>
]]></content:encoded>
			<wfw:commentRss>http://programmerthoughts.com/programming/nested-folders-in-cloud-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly uploading data to Cloud Files</title>
		<link>http://programmerthoughts.com/programming/quickly-uploading-data-to-cloud-files/</link>
		<comments>http://programmerthoughts.com/programming/quickly-uploading-data-to-cloud-files/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:24:24 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Cloud Files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[cloud files]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://programmerthoughts.com/?p=335</guid>
		<description><![CDATA[A custom file uploader can be more efficient than the generic language bindings provided by Cloud Files. I show how to efficiently upload many files to Cloud Files. The code is available in <a href="http://github.com/notmyname/python_scripts/tree/master/cf_speed/">my github account</a>.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.rackspacecloud.com/cloud_hosting_products/files">Cloud Files</a> is a great way to store information, either to take advantage of the CDN or to offload the infrastructure requirements of storing large amounts of data. However Cloud Files is used, though, one still must upload the data to the service before being able to use it.</p>
<p>Uploading the data is not problematic if it can be done in small chunks or spread out over time (images on a blog, for example). The <a href="http://github.com/rackspace">Cloud Files language APIs</a> offer a good way to upload data in these cases. Unfortunately, the language bindings can be terribly slow for uploading large numbers of files. While they do make some optimizations (like reusing connections when available), the code is written to be very generic. For example, the bindings make HEAD requests to ensure all proper data is set before allowing you to upload an object. Additionally, at least in the Python language bindings, HEAD requests are issued when an instance of an object is created. While this is good in a general sense, these HEAD requests become superfluous when doing a large batch upload. One can achieve much better results by using the Cloud FIles ReST API directly.</p>
<p>As an example, let&#8217;s look at the following code which uses the Python API:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> cloudfiles
&nbsp;
username = <span style="color: #483d8b;">'xxxx'</span>
apikey = <span style="color: #483d8b;">'xxxx'</span>
&nbsp;
conn = cloudfiles.<span style="color: black;">get_connection</span><span style="color: black;">&#40;</span>username, apikey<span style="color: black;">&#41;</span>
&nbsp;
container = conn.<span style="color: black;">create_container</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'api_speed_test3'</span><span style="color: black;">&#41;</span>
data_list = <span style="color: black;">&#40;</span><span style="color: #483d8b;">'test_data/%s'</span><span style="color: #66cc66;">%</span>x <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">listdir</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'test_data'</span><span style="color: black;">&#41;</span> \
             <span style="color: #ff7700;font-weight:bold;">if</span> x.<span style="color: black;">endswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.dat'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> filename <span style="color: #ff7700;font-weight:bold;">in</span> data_list:
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        obj = container.<span style="color: black;">create_object</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
        obj.<span style="color: black;">load_from_filename</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> cloudfiles.<span style="color: black;">errors</span>.<span style="color: black;">ResponseError</span>, err:
        <span style="color: #ff7700;font-weight:bold;">print</span> err
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>container.<span style="color: black;">list_objects</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>In my tests, using the above code takes about 5.5 minutes to upload 1000 16KB files to Cloud Files.</p>
<p>I wrote the same functionality using the ReST API directly:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">httplib</span>
&nbsp;
username = <span style="color: #483d8b;">'xxxx'</span>
apikey = <span style="color: #483d8b;">'xxxx'</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># auth</span>
conn = <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPSConnection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'api.mosso.com'</span><span style="color: black;">&#41;</span>
headers = <span style="color: black;">&#123;</span><span style="color: #483d8b;">'x-auth-user'</span>: username, <span style="color: #483d8b;">'x-auth-key'</span>: apikey<span style="color: black;">&#125;</span>
conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'GET'</span>, <span style="color: #483d8b;">'/auth'</span>, headers=headers<span style="color: black;">&#41;</span>
resp = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
auth_token = resp.<span style="color: black;">getheader</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'x-auth-token'</span><span style="color: black;">&#41;</span>
url = resp.<span style="color: black;">getheader</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'x-storage-url'</span><span style="color: black;">&#41;</span>
conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;"># send data</span>
send_headers = <span style="color: black;">&#123;</span><span style="color: #483d8b;">'X-Auth-Token'</span>: auth_token, <span style="color: #483d8b;">'Content-Type'</span>: <span style="color: #483d8b;">'text/plain'</span><span style="color: black;">&#125;</span>
container_path = <span style="color: #483d8b;">'/'</span>+<span style="color: #483d8b;">'/'</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>url.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">'/api_speed_test2'</span>
conn = <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPSConnection</span><span style="color: black;">&#40;</span>url.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'PUT'</span>, container_path, headers=send_headers<span style="color: black;">&#41;</span>
conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
data_list = <span style="color: black;">&#40;</span><span style="color: #483d8b;">'test_data/%s'</span><span style="color: #66cc66;">%</span>x <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">listdir</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'test_data'</span><span style="color: black;">&#41;</span> \
             <span style="color: #ff7700;font-weight:bold;">if</span> x.<span style="color: black;">endswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.dat'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> filename <span style="color: #ff7700;font-weight:bold;">in</span> data_list:
    f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
    conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'PUT'</span>, container_path+<span style="color: #483d8b;">'/'</span>+filename, body=f,
                 headers=send_headers<span style="color: black;">&#41;</span>
    f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    resp = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    resp.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> resp.<span style="color: black;">status</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">300</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> resp.<span style="color: black;">status</span>, resp.<span style="color: black;">reason</span>, container_path+<span style="color: #483d8b;">'/'</span>+filename
conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Although slightly longer, the majority of the extra code is for the auth. In my tests, uploading 1000 16KB files took about 4.5 minutes. A whole minute improvement for only 1000 objects is a very good result. I would expect the difference to be even greater as the number of files increases.</p>
<p>All of the code above (plus code to generate the test data) can be found in <a href="http://github.com/notmyname/python_scripts/tree/master/cf_speed/">my github account</a>.</p>
<p>By using the ReST API directly, I can make certain assumptions about my data that are not possible in the generic language bindings. I do not need to do the HEAD requests because I know I have just created the container and I have not uploaded the files yet. I am explicitly setting all the data for each object upload. Further improvements would be to add some error handling and parallelization.</p>
]]></content:encoded>
			<wfw:commentRss>http://programmerthoughts.com/programming/quickly-uploading-data-to-cloud-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cloud Files Object Copy</title>
		<link>http://programmerthoughts.com/programming/cloud-files-object-copy/</link>
		<comments>http://programmerthoughts.com/programming/cloud-files-object-copy/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 15:48:13 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Cloud Files]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[cloud files]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://programmerthoughts.com/?p=302</guid>
		<description><![CDATA[Cloud Files does not currently support object copying. However, a simple workaround is to re-upload the file with the new name.  I have added a copy feature to my fork of the python-cloudfiles API that handles all the details of preserving metadata and ensuring that the entire file is not buffered in memory. The code is available in <a href="http://github.com/notmyname/python-cloudfiles/tree/object_copy">my github account</a>.]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: This post is outdated and the referenced github branches no longer exist. The functionality described herein is now supported server-side in the latest version of Cloud Files (<a href="http://launchpad.net/swift">http://launchpad.net/swift</a>). See my <a href="http://programmerthoughts.com/programming/server-side-object-copy-in-openstack-storage/">newer post</a> for more details.</p>
<p>Cloud Files does not currently support object copying. However, a simple workaround is to re-upload the file with the new name. Implementing this workaround may be inconvenient, and one may miss some things like ensuring that metadata is updated. I have added a copy feature to my fork of the python-cloudfiles API that takes care of these details. This is a convenience function only and is not officially supported by Rackspace. Keep in mind that billable bandwidth will be used (unless the servicenet flag is set in the API). One option for renaming large files is to spin up a small <a href="http://www.rackspacecloud.com/cloud_hosting_products/servers">Cloud server</a>, use the API to copy over servicenet, and spin down the server. At $0.015 per hour, one could run a 256MB instance for 100 hours before equalling the transfer cost for copying one 5GB (Cloud Files max size) file over the billed network.</p>
<p>My python-cloudfiles fork on github: <a href="http://github.com/notmyname/python-cloudfiles/tree/object_copy">python-cloudfiles</a></p>
<p>Example script that copies the last file in a container to another container:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> cloudfiles
conn = cloudfiles.<span style="color: black;">get_connection</span><span style="color: black;">&#40;</span>username=<span style="color: #483d8b;">'myname'</span>, api_key=<span style="color: #483d8b;">'mykey'</span><span style="color: black;">&#41;</span>
container_name = <span style="color: #483d8b;">'example_container'</span>
another_container = <span style="color: #483d8b;">'example_container2'</span>
c = conn.<span style="color: black;">get_container</span><span style="color: black;">&#40;</span>container_name<span style="color: black;">&#41;</span>
l = c.<span style="color: black;">list_objects</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
o = c.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span>l<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
new_path = <span style="color: #483d8b;">'%s/%s'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>another_container, o.<span style="color: black;">name</span><span style="color: black;">&#41;</span>
o.<span style="color: black;">copy_to</span><span style="color: black;">&#40;</span>new_path<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'copied'</span>, l<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'to'</span>, new_path
new_list = conn.<span style="color: black;">get_container</span><span style="color: black;">&#40;</span>another_container<span style="color: black;">&#41;</span>.<span style="color: black;">list_objects</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> new_list
<span style="color: #ff7700;font-weight:bold;">assert</span> o.<span style="color: black;">name</span> <span style="color: #ff7700;font-weight:bold;">in</span> new_list</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://programmerthoughts.com/programming/cloud-files-object-copy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
