<?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.3. CloudMonkey</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="marvin.html" title="8.2. Marvin" /><link rel="next" href="libcloud-examples.html" title="8.4. Apache Libcloud" /></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="marvin.html"><strong>Indietro</strong></a></li><li class="next"><a accesskey="n" href="libcloud-examples.html"><strong>Avanti</strong></a></li></ul><div xml:lang="it-IT" class="section" id="cloudmonkey" lang="it-IT"><div class="titlepage"><div><div><h2 class="title" id="cloudmonkey">8.3. CloudMonkey</h2></div></div></div><div class="para">
		CloudMonkey is the CloudStack Command Line Interface (CLI). It is written in Python. CloudMonkey can be used both as an interactive shell and as a command line tool which simplifies CloudStack configuration and management. It can be used with CloudStack releases since the 4.0.x branch.
	</div><div class="warning"><div class="admonition_header"><h2>Avvertimento</h2></div><div class="admonition"><div class="para">
			CloudMonkey is still under development and should be considered a Work In Progress (WIP), the wiki is the most up to date documentation:
		</div><div class="para">
			<a href="https://cwiki.apache.org/CLOUDSTACK/cloudstack-cloudmonkey-cli.html">https://cwiki.apache.org/CLOUDSTACK/cloudstack-cloudmonkey-cli.html</a>
		</div></div></div><div class="section" id="gettingcloudmonkey"><div class="titlepage"><div><div><h3 class="title" id="gettingcloudmonkey">8.3.1. Installing CloudMonkey</h3></div></div></div><div class="para">
			CloudMonkey is dependent on <span class="emphasis"><em>readline, pygments, prettytable</em></span>, when installing from source you will need to resolve those dependencies. Using the cheese shop, the dependencies will be automatically installed.
		</div><div class="para">
			There are three ways to get CloudMonkey. Via the official CloudStack source releases or via a community maintained distribution at <a href="http://pypi.python.org/pypi/cloudmonkey/">the cheese shop</a>. Developers can also get it directly from the git repository in <span class="emphasis"><em>tools/cli/</em></span>.
		</div><div class="para">
			<div class="itemizedlist"><ul><li class="listitem"><div class="para">
						Via the official Apache CloudStack releases as well as the git repository.
					</div><pre class="programlisting">
    
$ git clone https://git-wip-us.apache.org/repos/asf/cloudstack.git # (optional if using a release download)
$ mvn clean install -P developer
$ cd tools/cli # cloudmonkey-x.x.x.tar.gz will be built in dist
$ python setup.py build
$ python setup.py install
    
</pre></li><li class="listitem"><div class="para">
						Via a community maintained package on Cheese Shop
					</div><div class="para">
						
<pre class="programlisting">pip install cloudmonkey</pre>
					</div></li></ul></div>

		</div></div><div class="section" id="configuringcloudmonkey"><div class="titlepage"><div><div><h3 class="title" id="configuringcloudmonkey">8.3.2. Configurazione</h3></div></div></div><div class="para">
			To configure CloudMonkey you can edit the ~/.cloudmonkey/config file in the user's home directory as shown below. The values can also be set interactively at the cloudmonkey prompt. Logs are kept in ~/.cloudmonkey/log, and history is stored in ~/.cloudmonkey/history. Discovered apis are listed in ~/.cloudmonkey/cache. Only the log and history files can be custom paths and can be configured by setting appropriate file paths in ~/.cloudmonkey/config
		</div><pre class="programlisting">
$ cat ~/.cloudmonkey/config 
[core]
log_file = /Users/sebastiengoasguen/.cloudmonkey/log
asyncblock = true
paramcompletion = false
history_file = /Users/sebastiengoasguen/.cloudmonkey/history

[ui]
color = true
prompt = &gt; 
tabularize = false

[user]
secretkey =VDaACYb0LV9eNjTetIOElcVQkvJck_J_QljX_FcHRj87ZKiy0z0ty0ZsYBkoXkY9b7eq1EhwJaw7FF3akA3KBQ 
apikey = plgWJfZK4gyS3mOMTVmjUVg-X-jlWlnfaUJ9GAbBbf9EdMkAYMmAiLqzzq1ElZLYq_u38zCm0bewzGUdP66mg

[server]
path = /client/api
host = localhost
protocol = http
port = 8080
timeout = 3600
</pre><div class="para">
			The values can also be set at the CloudMonkey prompt. The API and secret keys are obtained via the CloudStack UI or via a raw api call.
		</div><pre class="programlisting">

$ cloudmonkey
☁ Apache CloudStack cloudmonkey 4.1.0-snapshot. Type help or ? to list commands.

&gt; set prompt myprompt&gt;
myprompt&gt; set host localhost
myprompt&gt; set port 8080
myprompt&gt; set apikey &lt;your api key&gt;
myprompt&gt; set secretkey &lt;your secret key&gt;

</pre><div class="para">
			You can use CloudMonkey to interact with a local cloud, and even with a remote public cloud. You just need to set the host value properly and obtain the keys from the cloud administrator.
		</div></div><div class="section" id="cliapidiscovery"><div class="titlepage"><div><div><h3 class="title" id="cliapidiscovery">8.3.3. API Discovery</h3></div></div></div><div class="note"><div class="admonition_header"><h2>Nota</h2></div><div class="admonition"><div class="para">
				In CloudStack 4.0.* releases, the list of api calls available will be pre-cached, while starting with CloudStack 4.1 releases and above an API discovery service is enabled. CloudMonkey will discover automatically the api calls available on the management server. The sync command in CloudMonkey pulls a list of apis which are accessible to your user role, along with help docs etc. and stores them in ~/.cloudmonkey/cache. This allows cloudmonkey to be adaptable to changes in mgmt server, so in case the sysadmin enables a plugin such as Nicira NVP for that user role, the users can get those changes. New verbs and grammar (DSL) rules are created on the fly.
			</div></div></div><div class="para">
			To discover the APIs available do:
		</div><pre class="programlisting">
 &gt; sync
324 APIs discovered and cached
</pre></div><div class="section" id="clitabularoutput"><div class="titlepage"><div><div><h3 class="title" id="clitabularoutput">8.3.4. Tabular Output</h3></div></div></div><div class="para">
			The number of key/value pairs returned by the api calls can be large resulting in a very long output. To enable easier viewing of the output, a tabular formatting can be setup. You may enable tabular listing and even choose set of column fields, this allows you to create your own field using the filter param which takes in comma separated argument. If argument has a space, put them under double quotes. The create table will have the same sequence of field filters provided
		</div><div class="para">
			To enable it, use the <span class="emphasis"><em>set</em></span> function and create filters like so:
		</div><pre class="programlisting">
&gt; set tabularize true
&gt; list users filter=id,domain,account
count = 1
user:
+--------------------------------------+--------+---------+
|                  id                  | domain | account |
+--------------------------------------+--------+---------+
| 7ed6d5da-93b2-4545-a502-23d20b48ef2a |  ROOT  |  admin  |
+--------------------------------------+--------+---------+
</pre></div><div class="section" id="interactivecli"><div class="titlepage"><div><div><h3 class="title" id="interactivecli">8.3.5. Interactive Shell Usage</h3></div></div></div><div class="para">
			To start learning CloudMonkey, the best is to use the interactive shell. Simply type CloudMonkey at the prompt and you should get the interactive shell.
		</div><div class="para">
			At the CloudMonkey prompt press the tab key twice, you will see all potential verbs available. Pick on, enter a space and then press tab twice. You will see all actions available for that verb
		</div><pre class="programlisting">

cloudmonkey&gt;
EOF        assign     cancel     create     detach     extract    ldap       prepare    reconnect  restart    shell      update     
activate   associate  change     delete     disable    generate   list       query      register   restore    start      upload     
add        attach     configure  deploy     enable     get        mark       quit       remove     revoke     stop       
api        authorize  copy       destroy    exit       help       migrate    reboot     reset      set        suspend    
cloudmonkey&gt;create 
account                diskoffering           loadbalancerrule       portforwardingrule     snapshot               tags                   vpc
autoscalepolicy        domain                 network                privategateway         snapshotpolicy         template               vpcoffering
autoscalevmgroup       firewallrule           networkacl             project                sshkeypair             user                   vpnconnection
autoscalevmprofile     instancegroup          networkoffering        remoteaccessvpn        staticroute            virtualrouterelement   vpncustomergateway
condition              ipforwardingrule       physicalnetwork        securitygroup          storagenetworkiprange  vlaniprange            vpngateway
counter                lbstickinesspolicy     pod                    serviceoffering        storagepool            volume                 zone

</pre><div class="para">
			Picking one action and entering a space plus the tab key, you will obtain the list of parameters for that specific api call.
		</div><pre class="programlisting">

cloudmonkey&gt;create network 
account=            domainid=           isAsync=            networkdomain=      projectid=          vlan=               
acltype=            endip=              name=               networkofferingid=  startip=            vpcid=              
displaytext=        gateway=            netmask=            physicalnetworkid=  subdomainaccess=    zoneid=             

</pre><div class="para">
			To get additional help on that specific api call you can use the following:
		</div><pre class="programlisting">

cloudmonkey&gt;create network -h
Creates a network
Required args: displaytext name networkofferingid zoneid
Args: account acltype displaytext domainid endip gateway isAsync name netmask networkdomain networkofferingid physicalnetworkid projectid startip subdomainaccess vlan vpcid zoneid

cloudmonkey&gt;create network -help
Creates a network
Required args: displaytext name networkofferingid zoneid
Args: account acltype displaytext domainid endip gateway isAsync name netmask networkdomain networkofferingid physicalnetworkid projectid startip subdomainaccess vlan vpcid zoneid

cloudmonkey&gt;create network --help
Creates a network
Required args: displaytext name networkofferingid zoneid
Args: account acltype displaytext domainid endip gateway isAsync name netmask networkdomain networkofferingid physicalnetworkid projectid startip subdomainaccess vlan vpcid zoneid
cloudmonkey&gt;    

</pre><div class="para">
			Note the required arguments necessary for the calls.
		</div><div class="note"><div class="admonition_header"><h2>Nota</h2></div><div class="admonition"><div class="para">
				To find out the required parameters value, using a debugger console on the CloudStack UI might be very useful. For instance using Firebug on Firefox, you can navigate the UI and check the parameters values for each call you are making as you navigate the UI.
			</div></div></div></div><div class="section" id="startingavmexample"><div class="titlepage"><div><div><h3 class="title" id="startingavmexample">8.3.6. Starting a Virtual Machine instance with CloudMonkey</h3></div></div></div><div class="para">
			To start a virtual machine instance we will use the <span class="emphasis"><em>deploy virtualmachine</em></span> call.
		</div><pre class="programlisting">

cloudmonkey&gt;deploy virtualmachine -h
Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.
Required args: serviceofferingid templateid zoneid
Args: account diskofferingid displayname domainid group hostid hypervisor ipaddress iptonetworklist isAsync keyboard keypair name networkids projectid securitygroupids securitygroupnames serviceofferingid size startvm templateid userdata zoneid

</pre><div class="para">
			The required arguments are <span class="emphasis"><em>serviceofferingid, templateid and zoneid</em></span>
		</div><div class="para">
			In order to specify the template that we want to use, we can list all available templates with the following call:
		</div><pre class="programlisting">

cloudmonkey&gt;list templates templatefilter=all
count = 2
template:
========
domain = ROOT
domainid = 8a111e58-e155-4482-93ce-84efff3c7c77
zoneid = e1bfdfaf-3d9b-43d4-9aea-2c9f173a1ae7
displaytext = SystemVM Template (XenServer)
ostypeid = 849d7d0a-9fbe-452a-85aa-70e0a0cbc688
passwordenabled = False
id = 6d360f79-4de9-468c-82f8-a348135d298e
size = 2101252608
isready = True
templatetype = SYSTEM
zonename = devcloud
...&lt;snipped&gt;

</pre><div class="para">
			In this snippet, I used DevCloud and only showed the beginning output of the first template, the SystemVM template
		</div><div class="para">
			Similarly to get the <span class="emphasis"><em>serviceofferingid</em></span> you would do:
		</div><pre class="programlisting">

cloudmonkey&gt;list serviceofferings | grep id
id = ef2537ad-c70f-11e1-821b-0800277e749c
id = c66c2557-12a7-4b32-94f4-48837da3fa84
id = 3d8b82e5-d8e7-48d5-a554-cf853111bc50

</pre><div class="para">
			Note that we can use the linux pipe as well as standard linux commands within the interactive shell. Finally we would start an instance with the following call:
		</div><pre class="programlisting">

cloudmonkey&gt;deploy virtualmachine templateid=13ccff62-132b-4caf-b456-e8ef20cbff0e zoneid=e1bfdfaf-3d9b-43d4-9aea-2c9f173a1ae7 serviceofferingid=ef2537ad-c70f-11e1-821b-0800277e749c
jobprocstatus = 0
created = 2013-03-05T13:04:51-0800
cmd = com.cloud.api.commands.DeployVMCmd
userid = 7ed6d5da-93b2-4545-a502-23d20b48ef2a
jobstatus = 1
jobid = c441d894-e116-402d-aa36-fdb45adb16b7
jobresultcode = 0
jobresulttype = object
jobresult:
=========
virtualmachine:
==============
domain = ROOT
domainid = 8a111e58-e155-4482-93ce-84efff3c7c77
haenable = False
templatename = tiny Linux
...&lt;snipped&gt;

</pre><div class="para">
			The instance would be stopped with:
		</div><pre class="programlisting">
cloudmonkey&gt;stop virtualmachine id=7efe0377-4102-4193-bff8-c706909cc2d2
</pre><div class="note"><div class="admonition_header"><h2>Nota</h2></div><div class="admonition"><div class="para">
				The <span class="emphasis"><em>ids</em></span> that you will use will differ from this example. Make sure you use the ones that corresponds to your CloudStack cloud.
			</div></div></div></div><div class="section" id="scriptingcli"><div class="titlepage"><div><div><h3 class="title" id="scriptingcli">8.3.7. Scripting with CloudMonkey</h3></div></div></div><div class="para">
			All previous examples use CloudMonkey via the interactive shell, however it can be used as a straightfoward CLI, passing the commands to the <span class="emphasis"><em>cloudmonkey</em></span> command like shown below.
		</div><div class="para">
			
<pre class="programlisting">$cloudmonkey list users</pre>
		</div><div class="para">
			As such it can be used in shell scripts, it can received commands via stdin and its output can be parsed like any other unix commands as mentioned before.
		</div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="marvin.html"><strong>Indietro</strong>8.2. Marvin</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="libcloud-examples.html"><strong>Avanti</strong>8.4. Apache Libcloud</a></li></ul></body></html>
