Spell-check current documentation
[kamaki] / docs / usage.rst
1 Usage
2 =====
3
4 Kamaki offers command line interfaces that implement specific command specifications. A detailed list of the command specifications can be found in `Commands <commands.html>`_ section. This guide covers the generic usage of both interfaces.
5
6 What's more, kamaki offers a clients API that allows the development of external applications for synnefo. The clients API is listed in the `Clients lib <clients.html>`_ section. The recommended method of utilizing this API is explained in the present.
7
8 Setup
9 -----
10
11 Kamaki interfaces rely on a list of configuration options. In the initial state, kamaki is configured to communicate with the Okeanos IaaS. A detailed guide for setting up kamaki can be found in the `Setup <setup.html>`_ section.
12
13 Quick guide
14 ^^^^^^^^^^^
15
16 It is essential for users to get a configuration token (to get in Okeanos.grnet.gr log `here <https://accounts.okeanos.grnet.gr/im/>`_) and provide it to kamaki:
17
18 .. code-block:: console
19     :emphasize-lines: 1
20
21     Example 1.1.1: Set user token to myt0k3n==
22
23     $ kamaki set token myt0k3n==
24
25 To use the storage service, a user should also provide the corresponding user-name:
26
27 .. code-block:: console
28     :emphasize-lines: 1
29
30     Example 1.1.2: Set user name to user@domain.com
31
32     $ kamaki set account user@domain.com
33
34 Shell vs one-command
35 --------------------
36 Kamaki users can access synnefo services through either the interactive shell or the one-command behaviors. In practice, both systems rely on the same command set implementations and API clients, with identical responses and error messages. Still, there are some differences.
37
38 In favor of interactive shell behavior:
39
40 * tab completion for commands
41 * session history with "up" / "down" keys
42 * shorter commands with command context switching
43
44 In favor of one-command behavior:
45
46 * can be used along with advanced shell features (pipelines, redirection, etc.)
47 * can be used in shell scripts
48 * prints debug and verbose messages if needed
49
50 Run as shell
51 ^^^^^^^^^^^^
52 To use kamaki as a shell, run:
53
54 * without any parameters or arguments
55
56 .. code-block:: console
57     :emphasize-lines: 1
58
59     Example 2.2.1: Run kamaki shell
60
61     $ kamaki
62
63 * with any kind of '-' prefixed arguments, except '-h', '--help'.
64
65 .. code-block:: console
66     :emphasize-lines: 1
67
68     Example 2.2.2: Run kamaki shell with custom configuration file
69
70     $ kamaki --config myconfig.file
71
72
73 Run as one-command
74 ^^^^^^^^^^^^^^^^^^
75 To use kamaki as an one-command tool, run:
76
77 * with the '-h' or '--help' arguments (help for kamaki one-command)
78
79 .. code-block:: console
80     :emphasize-lines: 1
81
82     Example 2.3.1: Kamaki help
83
84     $kamaki -h
85
86 * with one or more command parameters:
87
88 .. code-block:: console
89     :emphasize-lines: 1
90
91     Example 2.3.2: List VMs managed by user
92
93     $ kamaki server list
94
95 Commands
96 --------
97
98 Client commands are grouped by service (see example 3.1.1 on how to list available groups). Commands behavior is as uniform as possible, but there are still differences between groups due to the special nature of each service and server-side implementation.
99
100 Typically, commands consist of a group name (e.g. store for storage commands) one or more terms (e.g. list for listing) and the command specific parameters (e.g. the name of the container), if any.
101
102 .. code-block:: console
103     :emphasize-lines: 1
104
105     Example 3.1.1: List stored files in container mycontainer.
106
107     $ kamaki store list mycontainer
108
109 Example 2.3.2 showcases a command without parameters (the group is "server", the command is "list").
110
111 The "server" command group is also referred in the following example.
112
113 .. code-block:: console
114     :emphasize-lines: 1
115
116     Example 3.1.2 Show information about a user-managed VM with id 42
117
118     $ kamaki server info 42
119
120 Client commands can feature an arbitrary number of terms:
121
122 .. code-block:: text
123
124     kamaki <group> <cmd term 1> <cmd term 2> ... <cmd term N> [arguments]
125
126 Although there are no multi-termed client commands until version 0.6.1 , the feature is supported and might be used in feature extensions.
127
128 The following pattern applies to all client commands up to version 0.6.1:
129
130 .. code-block:: text
131
132     kamaki <group> <command> [arguments]
133
134 The commands supported in version 0.6.1 are described bellow, grouped by service. The examples showcase a sample set of group commands. The kamaki interactive shell has been chosen as the execution environment:
135
136 astakos (Identity Manager)
137 ^^^^^^^^^^^^^^^^^^^^^^^^^^
138
139 .. code-block:: text
140
141     authenticate:  Authenticate a user
142
143 Showcase: get user information, provided the token was set
144
145 .. code-block:: console
146     :emphasize-lines: 1,4
147
148     * Enter astakos context *
149     [kamaki]:astakos
150
151     * Authenticate user *
152     [astakos]:authenticate
153     auth_token        :  s0m3t0k3nth@t1sr3m0v3d==
154     auth_token_created:  2012-11-13T14:12:40.917034
155     auth_token_expires:  2012-12-13T14:12:40.917035
156     groups            : 
157                       default
158     has_credits       :  False
159     has_signed_terms  :  True
160     uniq              :  myaccount@grnet.gr
161     username          :  4215th3b357num9323v32
162
163 flavor (Compute/Cyclades)
164 ^^^^^^^^^^^^^^^^^^^^^^^^^
165
166 .. code-block:: text
167
168     info:  Get flavor details
169     list:  List flavors
170
171 Showcase: show details for flavor with id 43
172
173 .. code-block:: console
174     :emphasize-lines: 1,4
175
176     * Enter flavor context *
177     [kamaki]: flavor
178
179     * Get details about flavor with id 43 *
180     [flavor]: info 43
181     SNF:disk_template:  drbd
182     cpu              :  4
183     disk             :  10
184     id               :  43
185     name             :  C4R2048D10
186     ram              :  2048
187
188 image (Compute/Cyclades + Glance)
189 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
190
191 .. code-block:: text
192
193     addmember  :  Add a member to an image
194     addproperty:  Add an image property
195     delete     :  Delete image
196     delmember  :  Remove a member from an image
197     delproperty:  Delete an image property
198     info       :  Get image details
199     list       :  List images
200     members    :  Get image members
201     meta       :  Get image metadata
202     properties :  Get image properties
203     public     :  List public images
204     register   :  (Re)Register an image
205     setmembers :  Set the members of an image
206     setproperty:  Update an image property
207     shared     :  List shared images
208
209 Showcase: Pick an image and list the properties
210
211 .. code-block:: console
212     :emphasize-lines: 1,4,18
213
214     * Enter image context *
215     [kamaki]:image
216
217     * list all available images *
218     [image]:list
219     1395fdfb-51b4-419f-bb02-f7d632860611 (Ubuntu Desktop LTS)
220     1580deb4-edb3-4496-a27f-7a246c4c0528 (Ubuntu Desktop)
221     18a82962-43eb-4b32-8e28-8f8880af89d7 (Kubuntu LTS)
222     6aa6eafd-dccb-422d-a904-67fe2bdde87e (Debian Desktop)
223     6b5681e4-7502-46ae-b1e9-9fd837932095 (maelstrom)
224     78262ee7-949e-4d70-af3a-85360c3de57a (Windows Server 2012)
225     86bc2414-0fb3-4898-a637-240292243302 (Fedora)
226     926ab1c5-2d85-49d4-aebe-0fce712789b9 (Windows Server 2008)
227     b2dffe52-64a4-48c3-8a4c-8214cc3165cf (Debian Base)
228     baf2321c-57a0-4a69-825d-49f49cea163a (CentOS)
229     c1d27b46-d875-4f5c-b7f1-f39b5af62905 (Kubuntu)
230
231     * Get properties of image with id b2dffe52-64a4-48c3-8a4c-8214cc3165cf *
232     [image]:properties b2dffe52-64a4-48c3-8a4c-8214cc3165cf
233     description   :  Debian 6.0.6 (Squeeze) Base System
234     gui           :  No GUI
235     kernel        :  2.6.32
236     os            :  debian
237     osfamily      :  linux
238     root_partition:  1
239     sortorder     :  1
240     users         :  root
241
242 server (Compute/Cyclades)
243 ^^^^^^^^^^^^^^^^^^^^^^^^^
244
245 .. code-block:: text
246
247     addmeta :  Add server metadata
248     addr    :  List a server's nic address
249     console :  Get a VNC console
250     create  :  Create a server
251     delete  :  Delete a server
252     delmeta :  Delete server metadata
253     firewall:  Set the server's firewall profile
254     info    :  Get server details
255     list    :  List servers
256     meta    :  Get a server's metadata
257     reboot  :  Reboot a server
258     rename  :  Update a server's name
259     setmeta :  Update server's metadata
260     shutdown:  Shutdown a server
261     start   :  Start a server
262     stats   :  Get server statistics
263     wait    :  Wait for server to finish
264
265 Showcase: Create a server.
266
267 .. code-block:: console
268     :emphasize-lines: 1,4,21,35,44,62
269
270     * Enter server context *
271     [kamaki]:server
272
273     * See server-create help *
274     [server]:create -h
275     usage: create <name> <flavor id> <image id>
276             [--personality PERSONALITY] [-h] [--config CONFIG]
277
278     Create a server
279
280     optional arguments:
281       -v, --verbose         More info at response
282       --personality PERSONALITY
283                             add a personality file
284       -d, --debug           Include debug output
285       -h, --help            Show help message
286       -i, --include         Include protocol headers in the output
287       --config CONFIG       Path to configuration file
288       -s, --silent          Do not output anything
289
290     * List all available images *
291     [server]:/image list
292     1395fdfb-51b4-419f-bb02-f7d632860611 (Ubuntu Desktop LTS)
293     1580deb4-edb3-4496-a27f-7a246c4c0528 (Ubuntu Desktop)
294     18a82962-43eb-4b32-8e28-8f8880af89d7 (Kubuntu LTS)
295     6aa6eafd-dccb-422d-a904-67fe2bdde87e (Debian Desktop)
296     6b5681e4-7502-46ae-b1e9-9fd837932095 (maelstrom)
297     78262ee7-949e-4d70-af3a-85360c3de57a (Windows Server 2012)
298     86bc2414-0fb3-4898-a637-240292243302 (Fedora)
299     926ab1c5-2d85-49d4-aebe-0fce712789b9 (Windows Server 2008)
300     b2dffe52-64a4-48c3-8a4c-8214cc3165cf (Debian Base)
301     baf2321c-57a0-4a69-825d-49f49cea163a (CentOS)
302     c1d27b46-d875-4f5c-b7f1-f39b5af62905 (Kubuntu)
303
304     * See details of flavor with id 1 *
305     [server]:/flavor info 1
306     SNF:disk_template:  drbd
307     cpu              :  1
308     disk             :  20
309     id               :  1
310     name             :  C1R1024D20
311     ram              :  1024
312
313     * Create a debian server named 'My Small Debian Server'
314     [server]:create 'My Small Debian Server' 1 b2dffe52-64a4-48c3-8a4c-8214cc3165cf
315     adminPass:  L8gu2wbZ94
316     created  :  2012-11-23T16:56:04.190813+00:00
317     flavorRef:  1
318     hostId   :  
319     id       :  11687
320     imageRef :  b2dffe52-64a4-48c3-8a4c-8214cc3165cf
321     metadata : 
322              values: 
323                    os   :  debian
324                    users:  root
325     name     :  My Small Debian Server
326     progress :  0
327     status   :  BUILD
328     suspended:  False
329     updated  :  2012-11-23T16:56:04.761962+00:00
330
331     * wait for server to build (optional) *
332     [server]:wait 11687
333     Server 11687 still in BUILD mode |||||||||||||||||    | 80% - 3s
334     Server 11687 is now in ACTIVE mode
335
336 .. Note:: In kamaki shell, / is used to access top-level command groups while working in command group contexts
337
338 network (Compute/Cyclades)
339 ^^^^^^^^^^^^^^^^^^^^^^^^^^
340
341 .. code-block:: text
342
343     connect   :  Connect a server to a network
344     create    :  Create a network
345     delete    :  Delete a network
346     disconnect:  Disconnect a nic of a server to a network
347     info      :  Get network details
348     list      :  List networks
349     rename    :  Update network name
350
351 Showcase: Connect a network to a VM
352
353 .. code-block:: console
354     :emphasize-lines: 1,4,9,24,27,44
355
356     * Enter network context *
357     [kamaki]:network
358
359     * List user-owned VMs *
360     [network]:/server list
361     11687 (My Small Debian Server)
362     11688 (An Ubuntu server)
363
364     * Try network-connect (to get help) *
365     [network]:connect 
366     Syntax error
367     usage: connect <server id> <network id> [-s] [-h] [-i] [--config CONFIG]
368
369     Connect a server to a network
370
371     Syntax: connect  <server id> <network id>
372       --config    :  Path to configuration file
373       -d,--debug  :  Include debug output
374       -h,--help   :  Show help message
375       -i,--include:  Include protocol headers in the output
376       -s,--silent :  Do not output anything
377       -v,--verbose:  More info at response
378
379     * Connect VM with id 11687 to network with id 1409
380     [network]: connect 11687 1409
381
382     * Get details on network with id 1409
383     [network]:info 1409
384       attachments: 
385                  nic-11687-1
386       cidr       :  192.168.1.0/24
387       cidr6      :  None
388       created    :  2012-11-23T17:17:20.560098+00:00
389       dhcp       :  True
390       gateway    :  None
391       gateway6   :  None
392       id         :  1409
393       name       :  my network
394       public     :  False
395       status     :  ACTIVE
396       type       :  PRIVATE_MAC_FILTERED
397       updated    :  2012-11-23T17:18:25.095225+00:00
398
399     * Get connectivity details on VM with id 11687 *
400     [network]:/server addr 11687
401     id:  nic-11687-1
402         ipv4       :  192.168.1.1
403         ipv6       :  None
404         mac_address:  aa:0f:c2:0b:0e:85
405         network_id :  1409
406         firewallProfile:  DISABLED
407     id:  nic-11687-0
408         ipv4           :  83.212.106.111
409         ipv6           :  2001:648:2ffc:1116:a80c:f2ff:fe12:a9e
410         mac_address    :  aa:0c:f2:12:0a:9e
411         network_id     :  1369
412
413 .. Note:: In kamaki shell, / is used to access top-level command groups while working in command group contexts
414
415 store (Storage/Pithos+)
416 ^^^^^^^^^^^^^^^^^^^^^^^
417
418 .. code-block:: text
419
420     append        :  Append local file to remote
421     cat           :  Print a file to console
422     copy          :  Copy an object
423     create        :  Create a container or a directory object
424     delete        :  Delete a container [or an object]
425     delgroup      :  Delete a user group on an account
426     delmeta       :  Delete an existing metadatum of account [, container [or object]]
427     delpermissions:  Delete all sharing permissions
428     download      :  Download a file
429     group         :  Get user groups details for account
430     hashmap       :  Get the hashmap of an object
431     info          :  Get information for account [, container [or object]]
432     list          :  List containers, object trees or objects in a directory
433     manifest      :  Create a remote file with uploaded parts by manifestation
434     meta          :  Get custom meta-content for account [, container [or object]]
435     mkdir         :  Create a directory
436     move          :  Copy an object
437     overwrite     :  Overwrite part (from start to end) of a remote file
438     permissions   :  Get object read/write permissions
439     publish       :  Publish an object
440     purge         :  Purge a container
441     quota         :  Get  quota for account [or container]
442     setgroup      :  Create/update a new user group on account
443     setmeta       :  Set a new metadatum for account [, container [or object]]
444     setpermissions:  Set sharing permissions
445     setquota      :  Set new quota (in KB) for account [or container]
446     setversioning :  Set new versioning (auto, none) for account [or container]
447     sharers       :  List the accounts that share objects with default account
448     truncate      :  Truncate remote file up to a size
449     unpublish     :  Unpublish an object
450     upload        :  Upload a file
451     versioning    :  Get  versioning for account [or container ]
452     versions      :  Get the version list of an object
453
454 Showcase: Upload and download a file.
455
456 .. code-block:: console
457     :emphasize-lines: 1,7,11,16,21,29,33,37,41,44,51,55,60,64
458
459     * Create a random binarry file at current OS path *
460     [kamaki]:!dd bs=4M if=/dev/zero of=rndm_local.file count=5
461     5+0 records in
462     5+0 records out
463     20971520 bytes (21 MB) copied, 0.016162 s, 1.3 GB/s
464
465     * Enter store context *
466     [kamaki]:store
467
468
469     * Check local file *
470     [store]:!ls -lh rndm_local.file
471     -rw-rw-r-- 1 ******** ******** 20M Nov 26 15:36 rndm_local.file
472
473
474     * Create two containers *
475     [store]:create mycont1
476     [store]:create mycont2
477
478
479     * List accessible containers *    
480     [store]:list
481     1. mycont1 (0B, 0 objects)
482     2. mycont2 (0B, 0 objects)
483     3. pithos (0B, 0 objects)
484     4. trash (0B, 0 objects)
485
486
487     * Upload local file to 1st container *
488     [store]:upload rndm_local.file mycont1
489
490
491     * Check if file has been uploaded *
492     [store]:list mycont1
493     1.    20M rndm_local.file
494
495     * Create director mydir on second container *
496     [store]:mkdir mycont2:mydir
497
498
499     * Move file from 1st to 2nd container (and in the directory) *
500     [store]:move mycont1:rndm_local.file mycont2:mydir/rndm_local.file
501
502     * Check the container of both containers *
503     [store]:list mycont1
504     [store]:list mycont2
505     1.      D mydir/
506     2.    20M mydir/rndm_local.file
507
508
509     * Copy file from 2nd to 1st container, with a new name *
510     [store]:copy mycont2:mydir/rndm_local.file mycont1:rndm_remote.file
511
512
513     * Check pasted file *
514     [store]:list mycont1
515     1.    20M rndm_remote.file
516
517
518     * Download pasted file to local file system *
519     [store]:download mycont1:rndm_remote.file rndm_remote.file
520
521
522     * Check if file is downloaded and if it is the same to original *
523     [store]:!ls -lh *.file
524     -rw-rw-r-- 1 ******** ******** 20M Nov 26 15:36 rndm_local.file
525     -rw-rw-r-- 1 ******** ******** 20M Nov 26 15:42 rndm_remote.file
526     [store]:!diff rndm_local.file rndm_remote.file
527
528 .. Note:: In kamaki shell, ! is used to execute OS shell commands (bash in the above)
529
530 One-command interface
531 ---------------------
532
533 Kamaki usage as a one-command tool is detailed in this section
534
535 Using help
536 ^^^^^^^^^^
537
538 Kamaki help is used to see available commands, with description, syntax and their corresponding optional arguments.
539
540 To see the command groups, users should use -h or --help like in example 1.3.1. In the same way, help information for command groups and commands is printed. In the following examples, the help messages of kamaki, of a command group (server) and of a command in that group (list) are shown.
541
542 .. code-block:: console
543     :emphasize-lines: 1
544
545     Example 4.1.1: kamaki help shows available parameters and command groups
546
547
548     $ kamaki -h
549     usage: kamaki <cmd_group> [<cmd_subbroup> ...] <cmd>
550         [-s] [-V] [-i] [--config CONFIG] [-o OPTIONS] [-h]
551
552     optional arguments:
553       -v, --verbose         More info at response
554       -s, --silent          Do not output anything
555       -V, --version         Print current version
556       -d, --debug           Include debug output
557       -i, --include         Include protocol headers in the output
558       --config CONFIG       Path to configuration file
559       -o OPTIONS, --options OPTIONS
560                             Override a config value
561       -h, --help            Show help message
562
563     Options:
564      - - - -
565     astakos:  Astakos API commands
566     config :  Configuration commands
567     flavor :  Compute/Cyclades API flavor commands
568     history:  Command history
569     image  :  Compute/Cyclades or Glance API image commands
570     network:  Compute/Cyclades API network commands
571     server :  Compute/Cyclades API server commands
572     store  :  Pithos+ storage commands
573
574 .. code-block:: console
575     :emphasize-lines: 1
576
577     Example 4.1.2: Cyclades help contains all first-level commands of Cyclades command group
578
579
580     $ kamaki cyclades -h
581     usage: kamaki server <...> [-v] [-s] [-V] [-d] [-i] [--config CONFIG]
582                                [-o OPTIONS] [-h]
583
584     optional arguments:
585       -v, --verbose         More info at response
586       -s, --silent          Do not output anything
587       -V, --version         Print current version
588       -d, --debug           Include debug output
589       -i, --include         Include protocol headers in the output
590       --config CONFIG       Path to configuration file
591       -o OPTIONS, --options OPTIONS
592                             Override a config value
593       -h, --help            Show help message
594
595     Options:
596      - - - -
597     addmeta :  Add server metadata
598     addr    :  List a server's nic address
599     console :  Get a VNC console
600     create  :  Create a server
601     delete  :  Delete a server
602     delmeta :  Delete server metadata
603     firewall:  Set the server's firewall profile
604     info    :  Get server details
605     list    :  List servers
606     meta    :  Get a server's metadata
607     reboot  :  Reboot a server
608     rename  :  Update a server's name
609     setmeta :  Update server's metadata
610     shutdown:  Shutdown a server
611     start   :  Start a server
612     stats   :  Get server statistics
613     wait    :  Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
614
615 .. code-block:: console
616     :emphasize-lines: 1
617
618     Example 4.1.3: Help for command "server list" with syntax, description and available user options
619
620
621     $ kamaki server list -h
622     usage: kamaki server list [-V] [-i] [--config CONFIG] [-h] [-l]
623
624     List servers
625
626     optional arguments:
627       -v, --verbose         More info at response
628       -s, --silent          Do not output anything
629       -V, --version         Print current version
630       -d, --debug           Include debug output
631       -i, --include         Include protocol headers in the output
632       --config CONFIG       Path to configuration file
633       -o OPTIONS, --options OPTIONS
634                             Override a config value
635       -h, --help            Show help message
636       -l                    show detailed output
637
638 .. _using-history-ref:
639
640 Using history
641 ^^^^^^^^^^^^^
642
643 Kamaki command history is stored in a file at user home (".kamaki.history" by default). To set a custom history file path users must set the history.file config option (see `available config options <setup.html#editing-options>`_).
644
645 Every syntactically correct command is appended at the end of that file. In order to see how to use history, use the kamaki help system:
646
647 .. code-block:: console
648     :emphasize-lines: 1
649
650     Example 4.2.1: Available history options
651
652
653     $ kamaki history -h
654     ...
655     clean:  Clean up history
656     show :  Show history
657
658 The following example showcases how to use history in kamaki
659
660 .. code-block:: console
661     :emphasize-lines: 1
662
663     Example 4.2.2: Clean up everything, run a kamaki command, show full and filtered history
664     
665
666     $ kamaki history clean
667     $ kamaki server list
668     ...
669     $ kamaki history show
670     1.  kamaki server list
671     2.  kamaki history show
672     $ kamaki history show --match server
673     1. kamaki server list
674     3. kamaki history show --match server
675
676 Debug
677 ^^^^^
678
679 In case of errors, kamaki in debug mode shows useful debug information, like the stack trace, instead of a user-friendly error message. Kamaki also suppresses various warning messages that are also allowed in debug mode.
680
681 To run kamaki in debug mode use the -d or --debug option
682
683 Verbose
684 """""""
685
686 Most kamaki commands are translated into http requests. Kamaki clients API translated the semantics to REST and handles the response. Users who need to have access to these commands can use the verbose mode that presents the HTTP Request details as well as the full server response.
687
688 To run kamaki in verbose mode use the -v or --verbose option
689
690 One-command features
691 ^^^^^^^^^^^^^^^^^^^^
692
693 Kamaki commands can be used along with advanced shell features.
694
695 .. code-block:: console
696     :emphasize-lines: 1
697
698     Example 4.4.1: Print username for token us3rt0k3n== using grep
699     
700
701     $ kamaki astakos authenticate -o token=us3rt0k3n== | grep uniq
702     uniq        : user@synnefo.org
703
704 The -o argument can be used to override temporarily various (set or unset) options. In one command, all -o options are forgotten just after the command had been completed, and the previous settings are restored (the configuration file is not modified).
705
706 The astakos-authenticate command in example 4.4.1 run against an explicitly provided token, which temporarily overrode the token provided in the configuration file.
707
708 Interactive shell
709 -----------------
710
711 Kamaki interactive shell is details in this section
712
713 Command Contexts
714 ^^^^^^^^^^^^^^^^
715
716 The kamaki interactive shell implements the notion of command contexts. Each command group is also a context where the users can **enter** by typing the group name. If the context switch is successful, the kamaki shell prompt changes to present the new context ("store" in example 5.1.1).
717
718 .. code-block:: console
719     :emphasize-lines: 1
720
721     Example 5.1.1: Enter store commands context / group
722
723
724     $ kamaki
725     [kamaki]:store
726     [store]:
727
728 Type **exit** or **ctrl-D** to exit a context and return to the context of origin. If already at the top context (kamaki), an exit is equivalent to exiting the program.
729
730 .. code-block:: console
731     :emphasize-lines: 1
732
733     Example 5.1.2: Exit store context and then exit kamaki
734
735     [store]: exit
736     [kamaki]: exit
737     $
738
739 A user might **browse** through different contexts during one session.
740
741 .. code-block:: console
742     :emphasize-lines: 1
743
744     Example 5.1.3: Execute list command in different contexts
745
746     $ kamaki
747     [kamaki]:config
748     [config]:list
749     ... (configuration options listing) ...
750     [config]:exit
751     [kamaki]:store
752     [store]:list
753     ... (storage containers listing) ...
754     [store]:exit
755     [kamaki]:server
756     [server]:list
757     ... (VMs listing) ...
758     [server]: exit
759     [kamaki]:
760
761 Users have the option to avoid switching between contexts: all commands can run from the **top context**. As a result, examples 5.1.3 and 5.1.4 are equivalent.
762
763 .. code-block:: console
764     :emphasize-lines: 1
765
766     Example 5.1.4: Execute different "list" commands from top context
767
768
769     [kamaki]:config list
770     ... (configuration options listing) ...
771     [kamaki]:store list
772     ... (storage container listing) ...
773     [kamaki]:server list
774     ... (VMs listing) ...
775     [kamaki]:
776
777 Using Help
778 ^^^^^^^^^^
779
780 There are two help mechanisms: a context-level and a command-level.
781
782 **Context-level help** lists the available commands in a context and can also offer a short description for each command.
783
784 Context-level help syntax::
785
786     * Show available commands in current context *
787     [context]:help
788     [context]:?
789
790     * Show help for command cmd *
791     [context]:help cmd
792     [context]:?cmd
793
794 The context-level help results change from context to context
795
796 .. code-block:: console
797     :emphasize-lines: 1
798
799     Example 5.2.1: Get available commands, pick a context and get help there as well
800
801
802     [kamaki]:help
803
804     kamaki commands:
805     ================
806     astakos  config  flavor  history  image  network  server  store
807
808     interactive shell commands:
809     ===========================
810     exit  help  shell
811
812     [kamaki]:?config
813     Configuration commands (config -h for more options)
814
815     [kamaki]:config
816
817     [config]:?
818
819     config commands:
820     ================
821     delete  get  list  set
822
823     interactive shell commands:
824     ===========================
825     exit  help  shell
826
827     [config]:help set
828     Set a configuration option (set -h for more options)
829
830 In context-level, there is a distinction between kamaki-commands and interactive shell commands. The former are available in one-command mode and are related to the cloud client setup and use, while the later are context-shell functions.
831
832 **Command-level help** prints the syntax, arguments and description of a specific (terminal) command
833
834 Command-level help syntax::
835
836     * Get help for command cmd1 cmd2 ... cmdN *
837     [context]:cmd1 cmd2 ... cmdN -h
838     <syntax>
839
840     <description>
841
842     <arguments and possible extensions>
843
844 Command-level help mechanism is exactly the same as the one used in one-command mode. For example, it is invoked by using the -h or --help parameter at any point.
845
846 .. code-block:: console
847     :emphasize-lines: 1
848
849     Example 5.2.2: Get command-level help for config and config-set
850
851
852     [kamaki]:config --help
853     config: Configuration commands
854     delete:  Delete a configuration option (and use the default value)
855     get   :  Show a configuration option
856     list  :  List configuration options
857     set   :  Set a configuration option
858
859     [kamaki]:config
860
861     [config]:set -h
862     usage: set <option> <value> [-v] [-d] [-h] [-i] [--config CONFIG] [-s]
863
864     Set a configuration option
865
866     optional arguments:
867       -v, --verbose    More info at response
868       -d, --debug      Include debug output
869       -h, --help       Show help message
870       -i, --include    Include protocol headers in the output
871       --config CONFIG  Path to configuration file
872       -s, --silent     Do not output anything
873
874 There are many ways of producing a help message, as shown in example 5.2.3
875
876 .. code-block:: console
877     :emphasize-lines: 1
878
879     Example 5.2.3: Equivalent calls of command-level help for config-set
880
881
882     [config]:set -h
883     [config]:set -help
884     [kamaki]:config set -h
885     [kamaki]:config set --help
886     [store]:/config set -h
887     [server]:/config set --help
888
889 .. _accessing-top-level-commands-ref:
890
891 Accessing top-level commands
892 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
893
894 When working in a context, it is often useful to access other contexts or top-level commands. Kamaki offers access to top-level commands by using the / prefix, as shown bellow::
895
896     * access a command "anothercontext cmd1 cmd2 ... cmdN"
897     [context]:/anothercontext cmd1 cmd2 ... cmdN
898
899 An example (5.3.1) that showcases how top-level access improves user experience is the creation of a VM. A VM is created with the command server-create. This command is called with three parameters:
900
901 * the name of the new VM
902 * the flavor id
903 * the image id
904
905 It is often the case that a user who works in the context command, needs to create a new VM, but doesn't know the flavor or image id of preference. Therefore, it is necessary to list all available flavors (flavor-list) or images (image-list. Both commands belong to different contexts.
906
907 .. code-block:: console
908     :emphasize-lines: 1
909
910     Example 5.3.1: Create a VM from server context
911
912     [server]:create -h
913     create <name> <flavor id> <image id> ...
914     ...
915     
916     [server]:/flavor list
917     ...
918     20. AFLAVOR
919         SNF:disk_template:  drbd
920         cpu              :  4
921         disk             :  10
922         id               :  43
923         ram              :  2048
924     
925     [server]:/image list
926     1580deb4-edb3-7a246c4c0528 (Ubuntu Desktop)
927     18a82962-43eb-8f8880af89d7 (Windows 7)
928     531aa018-9a40-a4bfe6a0caff (Windows XP)
929     6aa6eafd-dccb-67fe2bdde87e (Debian Desktop)
930     
931     [server]:create 'my debian' 43 6aa6eafd-dccb-67fe2bdde87e
932     ...
933
934 An other example (5.3.2) showcases how to acquire and modify configuration settings from a different context. In this scenario, the user token expires at server side while the user is working. When that happens, the system responds with an *(401) UNAUTHORIZED* message. The user can acquires a new token (with a browser) which has to be set to kamaki.
935
936 .. code-block:: console
937     :emphasize-lines: 1
938
939     Example 5.3.2: Set a new token from store context
940
941
942     [store]:list
943     (401) UNAUTHORIZED Access denied
944
945     [store]:/astakos authenticate
946     (401) UNAUTHORIZED Invalid X-Auth-Token
947
948     [store]:/config get token
949     my3xp1r3dt0k3n==
950
951     [store]:/config set token myfr35ht0k3n==
952
953     [store]:/config get token
954     myfr35ht0k3n==
955
956     [store]:list
957     1.  pithos (10MB, 2 objects)
958     2.  trash (0B, 0 objects)
959
960 The following example compares some equivalent calls that run *astakos-authenticate* after a *store-list* 401 failure.
961
962 .. code-block:: console
963     :emphasize-lines: 1,3,10,17,26
964
965     Example 5.3.3: Equivalent astakos-authenticate calls after a store-list 401 failure
966
967     * without kamaki interactive shell *
968     $ kamaki store list
969     (401) UNAUTHORIZED Access denied
970     $ kamaki astakos authenticate
971     ...
972     $
973
974     * from top-level context *
975     [kamaki]:store list
976     (401) UNAUTHORIZED Access denied
977     [kamaki]:astakos authenticate
978     ...
979     [kamaki]
980
981     * maximum typing *
982     [store]:list
983     (401) UNAUTHORIZED Access denied
984     [store]:exit
985     [kamaki]:astakos
986     [astakos]:authenticate
987     ...
988     [astakos]:
989
990     * minimum typing *
991     [store]: list
992     (401) UNAUTHORIZED Access denied
993     [store]:/astakos authenticate
994     ...
995     [store]:
996
997 .. hint:: To exit kamaki shell while in a context, try */exit*
998
999 Using config
1000 ^^^^^^^^^^^^
1001
1002 The configuration mechanism of kamaki is detailed at the `setup section <setup.html>`_ and it is common for both interaction modes. In specific, the configuration mechanism is implemented as a command group, namely *config*. Using the config commands is as straightforward as any other kamaki commands.
1003
1004 It is often useful to set, delete or update a value. This can be managed either inside the config context or from any command context by using the / detour.
1005
1006 .. Note:: config updates in kamaki shell persist even after the session is over. All setting changes affects the physical kamaki config file (automatically created, if not set manually)
1007
1008 In example 5.4.1 the user is going to work with only one storage container. The store commands use the container:path syntax, but if the user could set a container as a default, the container name could be omitted in most cases. This is possible by setting a store.container setting.
1009
1010 .. code-block:: console
1011     :emphasize-lines: 1
1012
1013     Example 5.4.1: Set default storage container
1014
1015
1016     [store]:list
1017     1.  mycontainer (32MB, 2 objects)
1018     2.  pithos (0B, 0 objects)
1019     3.  trash (2MB, 1 objects)
1020
1021     [store]:list mycontainer
1022     1.  D mydir/
1023     2.  20M mydir/rndm_local.file
1024     
1025     [store]:/config set store.container mycontainer
1026
1027     [store]: list
1028     1.  D mydir/
1029     2.  20M mydir/rndm_local.file
1030
1031 After a while, the user needs to work with multiple containers, therefore a default container is not longer needed. The store.container setting can be deleted, as shown in example 5.4.2 .
1032
1033 .. code-block:: console
1034     :emphasize-lines: 1
1035
1036     Example 5.4.2: Delete a setting option
1037
1038
1039     [store]:/config delete store.container
1040
1041     [store]:list
1042     1.  mycontainer (32MB, 2 objects)
1043     2.  pithos (0B, 0 objects)
1044     3.  trash (2MB, 1 objects)
1045
1046 .. warning:: In some cases, the config setting updates are not immediately effective. If that is the case, they will be after the next command run, whatever that command is.
1047
1048 Using history
1049 ^^^^^^^^^^^^^
1050
1051 There are two history modes: session and permanent. Session history keeps record of all actions in a kamaki shell session, while permanent history appends all commands to an accessible history file.
1052
1053 Session history is only available in interactive shell mode. Users can iterate through past commands in the same session by with the *up* and *down* keys. Session history is not stored, although syntactically correct commands are recorded through the permanent history mechanism
1054
1055 Permanent history is implemented as a command group and is common to both the one-command and shell interfaces. In specific, every syntactically correct command is appended in a history file (configured as *history.file* in settings, see `setup section <setup.html>`_ for details). Commands executed in one-command mode are mixed with the ones run in kamaki shell (also see :ref:`using-history-ref` section on this guide).
1056
1057 Tab completion
1058 ^^^^^^^^^^^^^^
1059
1060 Kamaki shell features tab completion for the first level of command terms of the current context. Tab completion pool changes dynamically when the context is switched. Currently, tab completion is not supported when the / detour is used (see :ref:accessing-top-level-commands-ref ).
1061
1062 OS Shell integration
1063 ^^^^^^^^^^^^^^^^^^^^
1064
1065 Kamaki shell features the ability to execute OS-shell commands from any context. This can be achieved by typing *!* or *shell*::
1066
1067     [kamaki_context]:!<OS shell command>
1068     ... OS shell command output ...
1069
1070     [kamaki_context]:shell <OS shell command>
1071     ... OS shell command output ...
1072
1073 .. code-block:: console
1074     :emphasize-lines: 1
1075
1076     Example 5.7.1: Run unix-style shell commands from kamaki shell
1077
1078
1079     [kamaki]:!ls -al
1080     total 16
1081     drwxrwxr-x 2 saxtouri saxtouri 4096 Nov 27 16:47 .
1082     drwxrwxr-x 7 saxtouri saxtouri 4096 Nov 27 16:47 ..
1083     -rw-rw-r-- 1 saxtouri saxtouri 8063 Jun 28 14:48 kamaki-logo.png
1084
1085     [kamaki]:shell cp kamaki-logo.png logo-copy.png
1086
1087     [kamaki]:shell ls -al
1088     total 24
1089     drwxrwxr-x 2 saxtouri saxtouri 4096 Nov 27 16:47 .
1090     drwxrwxr-x 7 saxtouri saxtouri 4096 Nov 27 16:47 ..
1091     -rw-rw-r-- 1 saxtouri saxtouri 8063 Jun 28 14:48 kamaki-logo.png
1092     -rw-rw-r-- 1 saxtouri saxtouri 8063 Jun 28 14:48 logo-copy.png
1093
1094
1095 Kamaki shell commits command strings to the outside shell and prints the results, without interacting with it. After a command is finished, kamaki shell returns to its initial state, which involves the current directory, as show in example 5.7.2 .
1096
1097 .. code-block:: console
1098     :emphasize-lines: 1
1099
1100     Example 5.7.2: Attempt (and fail) to change working directory
1101
1102
1103     [kamaki]:!pwd
1104     /home/username
1105
1106     [kamaki]:!cd ..
1107
1108     [kamaki]:shell pwd
1109     /home/username