<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>8.4. Apache Libcloud</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta name="generator" content="publican 2.8" /><meta name="package" content="Apache_CloudStack-Developers_Guide-4.1.0-it-IT-1-" /><script type="text/javascript" src="../../../../../toc.js"></script><script type="text/javascript">
              addID('Apache_CloudStack');
              
	      addID('Apache_CloudStack.4.1.0');
              
              addID('Apache_CloudStack.4.1.0.books');
	      addID('Apache_CloudStack.4.1.0.Developers_Guide');
              </script><link rel="home" href="index.html" title="Manuale dello Sviluppatore CloudStack" /><link rel="up" href="tools.html" title="Capitolo 8. Tools" /><link rel="prev" href="cloudmonkey.html" title="8.3. CloudMonkey" /><link rel="next" href="event-types.html" title="Appendice A. Event Types" /></head><body class="toc_embeded "><div id="tocdiv" class="toc"><iframe id="tocframe" class="toc" src="../../../../toc.html">This is an iframe, to view it upgrade your browser or enable iframe display.</iframe></div><p id="title"><a class="left" href="http://cloudstack.apache.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://cloudstack.apache.org/docs"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="cloudmonkey.html"><strong>Indietro</strong></a></li><li class="next"><a accesskey="n" href="event-types.html"><strong>Avanti</strong></a></li></ul><div xml:lang="it-IT" class="section" id="libcloud-examples" lang="it-IT"><div class="titlepage"><div><div><h2 class="title" id="libcloud-examples">8.4. Apache Libcloud</h2></div></div></div><div class="para">
		There are many tools available to interface with the CloudStack API. Apache Libcloud is one of those. In this section we provide a basic example of how to use Libcloud with CloudStack. It assumes that you have access to a CloudStack endpoint and that you have the API access key and secret key of a user.
	</div><div class="para">
		To install Libcloud refer to the libcloud website. If you are familiar with Pypi simply do:
	</div><pre class="programlisting">pip install apache-libcloud</pre><div class="para">
		You should see the following output:
	</div><pre class="programlisting">
pip install apache-libcloud
Downloading/unpacking apache-libcloud
  Downloading apache-libcloud-0.12.4.tar.bz2 (376kB): 376kB downloaded
  Running setup.py egg_info for package apache-libcloud
    
Installing collected packages: apache-libcloud
  Running setup.py install for apache-libcloud
    
Successfully installed apache-libcloud
Cleaning up...
</pre><div class="para">
		You can then open a Python interactive shell, create an instance of a CloudStack driver and call the available methods via the libcloud API.
	</div><pre class="programlisting">
 
&gt;&gt;&gt; from libcloud.compute.types import Provider
&gt;&gt;&gt; from libcloud.compute.providers import get_driver
&gt;&gt;&gt; Driver = get_driver(Provider.CLOUDSTACK)
&gt;&gt;&gt; apikey='plgWJfZK4gyS3mOMTVmjUVg-X-jlWlnfaUJ9GAbBbf9EdM-kAYMmAiLqzzq1ElZLYq_u38zCm0bewzGUdP66mg'
&gt;&gt;&gt; secretkey='VDaACYb0LV9eNjTetIOElcVQkvJck_J_QljX_FcHRj87ZKiy0z0ty0ZsYBkoXkY9b7eq1EhwJaw7FF3akA3KBQ'
&gt;&gt;&gt; host='http://localhost:8080'
&gt;&gt;&gt; path='/client/api'
&gt;&gt;&gt; conn=Driver(apikey,secretkey,secure='False',host='localhost:8080',path=path)
&gt;&gt;&gt; conn=Driver(key=apikey,secret=secretkey,secure=False,host='localhost',port='8080',path=path)
&gt;&gt;&gt; conn.list_images()
[&lt;NodeImage: id=13ccff62-132b-4caf-b456-e8ef20cbff0e, name=tiny Linux, driver=CloudStack  ...&gt;]
&gt;&gt;&gt; conn.list_sizes()
[&lt;NodeSize: id=ef2537ad-c70f-11e1-821b-0800277e749c, name=tinyOffering, ram=100 disk=0 bandwidth=0 price=0 driver=CloudStack ...&gt;, &lt;NodeSize: id=c66c2557-12a7-4b32-94f4-48837da3fa84, name=Small Instance, ram=512 disk=0 bandwidth=0 price=0 driver=CloudStack ...&gt;, &lt;NodeSize: id=3d8b82e5-d8e7-48d5-a554-cf853111bc50, name=Medium Instance, ram=1024 disk=0 bandwidth=0 price=0 driver=CloudStack ...&gt;]
&gt;&gt;&gt; images=conn.list_images()
&gt;&gt;&gt; offerings=conn.list_sizes()
&gt;&gt;&gt; node=conn.create_node(name='toto',image=images[0],size=offerings[0])
&gt;&gt;&gt; help(node)
&gt;&gt;&gt; node.get_uuid()
'b1aa381ba1de7f2d5048e248848993d5a900984f'
&gt;&gt;&gt; node.name
u'toto'

</pre><div class="para">
		One of the interesting use cases of Libcloud is that you can use multiple Cloud Providers, such as AWS, Rackspace, OpenNebula, vCloud and so on. You can then create Driver instances to each of these clouds and create your own multi cloud application.
	</div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="cloudmonkey.html"><strong>Indietro</strong>8.3. CloudMonkey</a></li><li class="up"><a accesskey="u" href="#"><strong>Risali</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Partenza</strong></a></li><li class="next"><a accesskey="n" href="event-types.html"><strong>Avanti</strong>Appendice A. Event Types</a></li></ul></body></html>
