Author: jerry
Date: Mon Mar 22 03:05:22 2010
New Revision: 925944
URL: http://svn.apache.org/viewvc?rev=925944&view=rev
Log:
Updated examples
Modified:
incubator/libcloud/site/getting-started.html
Modified: incubator/libcloud/site/getting-started.html
URL:
http://svn.apache.org/viewvc/incubator/libcloud/site/getting-started.html?rev=925944&r1=925943&r2=925944&view=diff
==============================================================================
--- incubator/libcloud/site/getting-started.html (original)
+++ incubator/libcloud/site/getting-started.html Mon Mar 22 03:05:22 2010
@@ -33,32 +33,67 @@
</div><!--/#sidebar-->
<div id="main" class="span-16 last">
- <h2>example</h2>
- <p>The following example will list servers across Amazon EC2, Slicehost,
and Rackspace Cloud Servers using the same API call. The servers will be
represented in a standard Node object</p>
+ <h2>Example: Connecting with a Driver</h2>
<code class="python">from libcloud.types import Provider
from libcloud.providers import get_driver
-
-EC2 = get_driver(Provider.EC2)
-Slicehost = get_driver(Provider.SLICEHOST)
-Rackspace = get_driver(Provider.RACKSPACE)
-
-drivers = [ EC2('access key id', 'secret key'),
- Slicehost('api key'),
- Rackspace('username', 'api key') ]
-
-nodes = [ driver.list_nodes() for driver in drivers ]
-
+
+EC2_ACCESS_ID = 'your access id'
+EC2_SECRET_KEY = 'your secret key'
+
+Driver = get_driver(Provider.EC2)
+conn = Driver(EC2_ACCESS_ID, EC2_SECRET_KEY)
+
+nodes = conn.list_nodes()
+# [<Node: uuid=..., state=3, public_ip=['1.1.1.1'], provider=EC2 ...>,
...]</code>
+
+ <h2>Example: Creating a Node</h2>
+ <code class="python">from libcloud.types import Provider
+from libcloud.providers import get_driver
+
+RACKSPACE_USER = 'your username'
+RACKSPACE_KEY = 'your key'
+
+Driver = get_driver(Provider.RACKSPACE)
+conn = Driver(RACKSPACE_USER, RACKSPACE_KEY)
+
+# retrieve available images and sizes
+images = conn.list_images()
+# [<NodeImage: id=3, name=Gentoo 2008.0, driver=Rackspace ...>, ...]
+sizes = conn.list_sizes()
+# [<NodeSize: id=1, name=256 server, ram=256 ... driver=Rackspace ...>,
...]
+
+# create node with first image and first size
+node = conn.create_node(name='test', image=images[0], size=size[0])
+# <Node: uuid=..., name=test, state=3, public_ip=['1.1.1.1'],
provider=Rackspace ...></code>
+
+ <h2>Example: List Nodes Across Multiple Providers</h2>
+ <!-- <p>The following example will list servers across Amazon EC2,
Slicehost, and Rackspace Cloud Servers using the same API call. The servers
will be represented in a standard Node object</p> -->
+ <code class="python">from libcloud.types import Provider
+from libcloud.providers import get_driver
+
+EC2_ACCESS_ID = 'your access id'
+EC2_SECRET_KEY = 'your secret key'
+SLICEHOST_API_KEY = 'your api key'
+RACKSPACE_USER = 'your username'
+RACKSPACE_KEY = 'your key'
+
+EC2Driver = get_driver(Provider.EC2)
+SlicehostDriver = get_driver(Provider.SLICEHOST)
+RackspaceDriver = get_driver(Provider.RACKSPACE)
+
+drivers = [ EC2Driver(EC2_ACCESS_ID, EC2_SECRET_KEY),
+ SlicehostDriver(SLICEHOST_API_KEY),
+ RackspaceDriver(RACKSPACE_USER, RACKSPACE_KEY) ]
+
+nodes = []
+for driver in drivers:
+ nodes += driver.list_nodes()
print nodes
# [ <Node: provider=Amazon, status=RUNNING, name=bob, ip=1.2.3.4.5>,
-# <Node: provider=Slicehost, status=REBOOT, name=korine, ip=6.7.8.9.10>,
... ]
+# <Node: provider=Slicehost, status=REBOOT, name=korine, ip=6.7.8.9>,
... ]
-
-# grab the node named "test"
-node = filter(lambda x: x.name == 'test', nodes)[0]
-
-# reboot "test"
-node.reboot()
-</code>
+# Reboot all nodes named 'test'
+[node.reboot() for node in nodes if node.name == 'test']</code>
<h2>installation</h2>
<p>Currently libcloud is only available via SVN. To pull the repository
please run:</p>
<code>svn co https://svn.apache.org/repos/asf/incubator/libcloud/trunk/
libcloud</code>