4 Kamaki offers command line interfaces that implement specific command
5 specifications. A detailed list of the command specifications can be found in
6 `Commands <commands.html>`_ section. This guide covers the generic usage of
9 What's more, kamaki offers a clients API that allows the development of
10 external applications for synnefo. The clients API is listed in the
11 `Clients lib <developers/code.html#the-clients-api>`_ section.
16 Kamaki interfaces rely on a list of configuration options. A detailed guide for
17 setting up kamaki can be found in the `Setup <setup.html>`_ section.
19 As rule of the thump, it is enough to set the authentication URL and user token
20 for the cloud kamaki should communicate with by default:
22 .. code-block:: console
25 Example 1.1: Set authentication URL, user token and cloud alias "default"
27 $ kamaki config set cloud.default.url <authentication URL>
28 $ kamaki config set cloud.default.token myt0k3n==
30 .. note:: The term *default* can be replaced by any arbitary term chosen by
31 the user. This term will serve as a cloud alias for kamaki users, and can
36 Kamaki users can access synnefo services through either the interactive shell
37 or the one-command behaviors. In practice, both systems rely on the same
38 command set implementations and API clients, with identical responses and error
39 messages. Still, there are some differences.
41 In favor of interactive shell behavior:
43 * tab completion for commands (if supported by host command line shell)
44 * session history with ↑ or ↓ keys (if supported by host command line shell)
45 * shorter commands with command context switching
46 * re-run old commands with /history
48 In favor of one-command behavior:
50 * can be used along with advanced shell features (pipelines, redirection, etc.)
51 * can be used in shell scripts
52 * prints debug and verbose messages if needed
56 To use kamaki as a shell, run:
58 * without any parameters or arguments
60 .. code-block:: console
63 Example 2.2.1: Run kamaki shell
67 * with any kind of '-' prefixed arguments, except '-h', '--help'.
69 .. code-block:: console
72 Example 2.2.2: Run kamaki shell with custom configuration file
74 $ kamaki -c myconfig.file
79 To use kamaki as an one-command tool, run:
81 * with the '-h' or '--help' arguments (help for kamaki one-command)
83 .. code-block:: console
86 Example 2.3.1: Kamaki help
90 * with one or more command parameters:
92 .. code-block:: console
95 Example 2.3.2: List VMs managed by user
100 ---------------------
105 Kamaki help is used to list available commands with description, syntax and
106 corresponding optional arguments.
108 To see the command groups, use -h or --help like in example 1.3.1. In the same
109 way, help information for command groups and commands is printed. In the
110 following examples, the help messages of kamaki, of a command group (server)
111 and of a command in that group (list) are shown.
113 .. code-block:: console
116 Example 3.1.1: kamaki help shows available parameters and command groups
120 usage: kamaki <cmd_group> [<cmd_subbroup> ...] <cmd>
121 [-v] [-s] [-V] [-d] [-i] [-c CONFIG] [-o OPTIONS] [--cloud CLOUD] [-h]
124 -v, --verbose More info at response
125 -s, --silent Do not output anything
126 -V, --version Print current version
127 -d, --debug Include debug output
128 -i, --include Include protocol headers in the output
129 -c CONFIG, --config CONFIG
130 Path to configuration file
131 -o OPTIONS, --options OPTIONS
132 Override a config value
133 --cloud CLOUD Chose a cloud to connect to
134 -h, --help Show help message
138 config : Kamaki configurations
139 file : Pithos+/Storage API commands
140 flavor : Cyclades/Compute API flavor commands
141 history: Kamaki command history
142 image : Cyclades/Plankton API image commands
143 image compute: Cyclades/Compute API image commands
144 network: Cyclades/Compute API network commands
145 server : Cyclades/Compute API server commands
146 user : Astakos API commands
148 .. code-block:: console
149 :emphasize-lines: 1,2
151 Example 3.1.2: Cyclades help contains all first-level commands of Cyclades
155 usage: kamaki server <...> [-v] [-s] [-V] [-d] [-i] [-c CONFIG]
156 [-o OPTIONS] [--cloud CLOUD] [-h]
159 -v, --verbose More info at response
160 -s, --silent Do not output anything
161 -V, --version Print current version
162 -d, --debug Include debug output
163 -i, --include Include protocol headers in the output
164 -c CONFIG, --config CONFIG
165 Path to configuration file
166 -o OPTIONS, --options OPTIONS
167 Override a config value
168 --cloud CLOUD Chose a cloud to connect to
169 -h, --help Show help message
173 addr : List the addresses of all network interfaces on a server (VM)
174 console : Get a VNC console to access an existing server (VM)
175 create : Create a server (aka Virtual Machine)
176 delete : Delete a server (VM)
177 firewall: Manage server (VM) firewall profiles for public networks
178 info : Detailed information on a Virtual Machine
179 list : List Virtual Machines accessible by user
180 metadata: Manage Server metadata (key:value pairs of server attributes)
181 reboot : Reboot a server (VM)
182 rename : Set/update a server (VM) name
183 shutdown: Shutdown an active server (VM)
184 start : Start an existing server (VM)
185 stats : Get server (VM) statistics
186 wait : Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
188 .. code-block:: console
189 :emphasize-lines: 1,2
191 Example 3.1.3: Help for command "server list" with syntax, description and
192 available user options
194 $ kamaki server list -h
195 usage: kamaki server list [-v] [-s] [-V] [-d] [-i] [-c CONFIG] [-o OPTIONS]
196 [--cloud CLOUD] [-h] [--since SINCE] [--enumerate]
197 [-l] [--more] [-n LIMIT] [-j]
199 List Virtual Machines accessible by user
201 * to check authentication: /user authenticate
202 * to set authentication token: /config set cloud.default.token <token>
205 -v, --verbose More info at response
206 -s, --silent Do not output anything
207 -V, --version Print current version
208 -d, --debug Include debug output
209 -i, --include Include raw connection data in the output
210 -c CONFIG, --config CONFIG
211 Path to configuration file
212 -o OPTIONS, --options OPTIONS
213 Override a config value
214 --cloud CLOUD Chose a cloud to connect to
215 -h, --help Show help message
216 --since SINCE show only items since date (' d/m/Y H:M:S ')
217 --enumerate Enumerate results
218 -l, --details show detailed output
219 --more output results in pages (-n to set items per page,
221 -n LIMIT, --number LIMIT
222 limit number of listed VMs
223 -j, --json show headers in json
225 .. _using-history-ref:
230 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>`_).
232 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:
234 .. code-block:: console
237 Example 3.2.1: Available history options
243 clean: Clean up history (permanent)
244 run : Run previously executed command(s)
245 show : Show intersession command history
247 The following example showcases how to use history in kamaki
249 .. code-block:: console
252 Example 3.2.2: Clean up everything, run a kamaki command, show full and filtered history
255 $ kamaki history clean
258 $ kamaki history show
259 1. kamaki server list
260 2. kamaki history show
261 $ kamaki history show --match server
262 1. kamaki server list
263 3. kamaki history show --match server
271 In case of errors, kamaki in debug mode shows useful debug information, like
272 the stack trace. Kamaki in debug mode cancels suppression of warning messages.
274 To run kamaki in debug mode use the -d or --debug option (can be combined with
275 any other parameters or options)
280 Kamaki keeps its logs in a file specified as global.log_file and its value
281 defaults to ${HOME}/.kamaki.log . This value may change with a config setting::
283 kamaki config set log_file /new/log/file/path
285 Kamaki logs mostly the http connection requests and responses, including http
286 methods, urls, parameters and headers. There is some special handling in two
289 * HTTP bodies are not logged by default
290 to enable logging the full http bodies, set log_data to `on`::
292 kamaki config set log_data on
294 to disable it, set it to `off`::
296 kamaki config set log_data off
300 kamaki config delete log_data
302 * X-Auth-Token header is not logged by default
303 to enable logging the X-Auth-Token header, set log_token to `on`::
305 kamaki config set log_token on
307 to disable it, set it to `off`::
309 kamaki config set log_token off
313 kamaki config delete log_token
318 Most kamaki commands are translated into http requests. Kamaki clients API
319 translated the semantics to REST and handles the response. Users who need to
320 have access to these commands can use the verbose mode that presents the HTTP
321 Request details as well as the full server response.
323 To run kamaki in verbose mode use the -v or --verbose option
325 Be default, kamaki in verbose mode prints down only the headers and the address
326 information, thus hiding the data body of the request or response. To see the
327 data body, the -i option can be used.
332 Kamaki commands can be used along with advanced shell features.
334 .. code-block:: console
337 Example 3.4.1: List the trash container contents, containing c1_
340 $ kamaki file list -o cloud.default.pithos_container=trash| grep c1_
345 The -o argument can be used to temporarily override various (set or unset)
346 options. In one command, all -o option sets are forgotten just after the
347 command has been completed, and the previous settings are restored (the
348 configuration file is not modified).
350 The file-list command in example 3.4.1 runs with an explicitly provided
351 pithos_account, which temporarily overrides the one probably provided in the
352 configuration file (it works even if the user has not set the optional
353 pithos_account config option).
361 The kamaki interactive shell implements the notion of command contexts. Each
362 command group is also a context where the users can **enter** by typing the
363 group name. If the context switch is successful, the kamaki shell prompt
364 changes to present the new context ("file" in example 4.1.1).
366 .. code-block:: console
369 Example 4.1.1: Enter file commands context / group
376 Type **exit** (alternatively **ctrl-D** in (X)nix systems or **ctrl-Z** in
377 Windows) to exit a context and return to the context of origin. If already at
378 the top context (kamaki), an exit is equivalent to exiting the program.
380 .. code-block:: console
383 Example 4.1.2: Exit file context and then exit kamaki
389 A user might **browse** through different contexts during one session.
391 .. code-block:: console
394 Example 4.1.3: Execute list command in different contexts
399 ... (configuration options listing) ...
403 ... (storage containers listing) ...
407 ... (VMs listing) ...
411 Users have the option to avoid switching between contexts: all commands can run
412 from the **top context**. As a result, examples 4.1.3 and 4.1.4 are equivalent.
414 .. code-block:: console
417 Example 4.1.4: Execute different "list" commands from top context
420 [kamaki]: config list
421 ... (configuration options listing) ...
423 ... (storage container listing) ...
424 [kamaki]: server list
425 ... (VMs listing) ...
431 There are two help mechanisms: a context-level and a command-level.
433 **Context-level help** lists the available commands in a context and can also
434 offer a short description for each command.
436 Context-level help syntax::
438 * Show available commands in current context *
442 * Show help for command cmd *
446 The context-level help results may change from context to context
448 .. code-block:: console
451 Example 4.2.1: Get available commands and then get help in a context
458 user config flavor history image network server file
460 interactive shell commands:
461 ===========================
465 Configuration commands (config -h for more options)
475 interactive shell commands:
476 ===========================
480 Set a configuration option (set -h for more options)
482 In context-level, there is a distinction between kamaki-commands and
483 interactive shell commands. The former are available in one-command mode and
484 are related to the cloud client setup and use, while the later are
485 context-shell functions.
487 **Command-level help** prints the syntax, arguments and description of a
488 specific (terminal) command
490 Command-level help syntax::
492 * Get help for command cmd1 cmd2 ... cmdN *
493 [context]: cmd1 cmd2 ... cmdN -h
498 <arguments and possible extensions>
500 Command-level help mechanism is exactly the same as the one used in
501 one-command mode. For example, it is invoked by using the -h or --help
502 parameter at any point.
504 .. code-block:: console
507 Example 4.2.2: Get command-level help for config and config-set
510 [kamaki]: config --help
511 config: Configuration commands
512 delete: Delete a configuration option (and use the default value)
513 get : Show a configuration option
514 list : List configuration options
515 set : Set a configuration option
520 usage: set <option> <value> [-v] [-d] [-h] [-i] [--config CONFIG] [-s]
522 Set a configuration option
525 -v, --verbose More info at response
526 -d, --debug Include debug output
527 -h, --help Show help message
528 -i, --include Include protocol headers in the output
529 --config CONFIG Path to configuration file
530 -s, --silent Do not output anything
532 There are many ways of producing a help message, as shown in example 4.2.3
534 .. code-block:: console
537 Example 4.2.3: Equivalent calls of command-level help for config-set
542 [kamaki]: config set -h
543 [kamaki]: config set --help
544 [file]: /config set -h
545 [server]: /config set --help
547 .. _accessing-top-level-commands-ref:
549 Accessing top-level commands
550 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
552 When working in a context, it is often useful to access other contexts or
553 top-level commands. Kamaki offers access to top-level commands by using the
554 `/` prefix, as shown bellow::
556 * access a command "anothercontext cmd1 cmd2 ... cmdN"
557 [context]: /anothercontext cmd1 cmd2 ... cmdN
559 An example (4.3.1) that showcases how top-level access improves user experience
560 is the creation of a VM. A VM is created with the command server-create. This
561 command is called with three parameters:
563 * the name of the new VM
567 It is often the case that a user who works in the context command, needs to
568 create a new VM, but hasn't selected a flavor or an image id, or cannot recall
569 the id of that flavor or image. Therefore, it is necessary to list all
570 available flavors (flavor-list) or images (image-compute-list). Both commands
571 belong to different contexts.
573 .. code-block:: console
576 Example 4.3.1: Create a VM from server context
579 create <name> <flavor id> <image id> ...
582 [server]: /flavor list
585 SNF:disk_template: drbd
590 [server]: /image compute list
591 1580deb4-edb3-7a246c4c0528 (Ubuntu Desktop)
592 18a82962-43eb-8f8880af89d7 (Windows 7)
593 531aa018-9a40-a4bfe6a0caff (Windows XP)
594 6aa6eafd-dccb-67fe2bdde87e (Debian Desktop)
596 [server]: create 'my debian' 43 6aa6eafd-dccb-67fe2bdde87e
599 An other example (4.3.2) showcases how to acquire and modify configuration
600 settings from a different context. In this scenario, the user token expires at
601 server side while the user is working. When that happens, the system responds
602 with an *(401) UNAUTHORIZED* message. The user can acquire a new token (valid
603 for the Astakos identity manager of preference) which has to be set to kamaki.
605 .. code-block:: console
608 Example 4.3.2: Set a new token from file context
612 (401) UNAUTHORIZED Access denied
614 [file]: /user authenticate
615 (401) UNAUTHORIZED Invalid X-Auth-Token
617 [file]: /config get cloud.default.token
620 [file]: /config set cloud.default.token myfr35ht0k3n==
622 [file]: /config get cloud.default
623 cloud.default.url = https://astakos.example.com/astakos/identity/2.0/
624 cloud.default.token = myfr35ht0k3n==
627 1. pithos (10MB, 2 objects)
628 2. trash (0B, 0 objects)
630 .. note:: The error messages on this example where shortened for clarity.
631 Actual kamaki error messages are more helpful and descriptive.
633 The following example compares some equivalent calls that run
634 *user-authenticate* after a *file-list* 401 failure.
636 .. code-block:: console
637 :emphasize-lines: 1,3,10,17,26
639 Example 4.3.3: Equivalent user-authenticate calls after a file-list 401
641 * without kamaki interactive shell *
643 (401) UNAUTHORIZED Access denied
644 $ kamaki user authenticate
648 * from top-level context *
650 (401) UNAUTHORIZED Access denied
651 [kamaki]: user authenticate
657 (401) UNAUTHORIZED Access denied
666 (401) UNAUTHORIZED Access denied
667 [file]: /user authenticate
671 .. hint:: To exit kamaki shell while in a context, try */exit*
676 The configuration mechanism of kamaki is detailed in the
677 `setup section <setup.html>`_ and it is common for both interaction modes. In
678 specific, the configuration mechanism is implemented as a command group, namely
679 `config`. Using the config commands is as straightforward as any other kamaki
682 It is often useful to set, delete or update a value. This can be managed either
683 inside the config context or from any command context by using the / prefix.
685 .. Note:: config updates in kamaki shell persist even after the session is over
687 All setting changes affect the physical kamaki config file. The config file is
688 created automatically at callers' home firectory the first time a config option
689 is set, and lives there as *.kamakirc* . It can be edited with any text editor
690 or managed with kamaki config commands.
692 In example 4.4.1 the user is going to work with only one storage container. The
693 file commands use the container:path syntax, but if the user sets a container
694 name as default, the container name can be omitted. This is possible by setting
695 a *file.container* setting.
697 .. code-block:: console
700 Example 4.4.1: Set default storage container (cloud: default)
704 1. mycontainer (32MB, 2 objects)
705 2. pithos (0B, 0 objects)
706 3. trash (2MB, 1 objects)
708 [file]: list mycontainer
710 2. 20M mydir/rndm_local.file
712 [file]: /config set cloud.default.pithos_container mycontainer
716 2. 20M mydir/rndm_local.file
718 After a while, the user needs to work with multiple containers, therefore a
719 default container is no longer needed. The *pithos_container* setting can be
720 deleted, as shown in example 4.4.2
722 .. code-block:: console
725 Example 4.4.2: Delete a setting option (cloud: default)
728 [file]: /config delete cloud.default.pithos_container
731 1. mycontainer (32MB, 2 objects)
732 2. pithos (0B, 0 objects)
733 3. trash (2MB, 1 objects)
738 There are two history modes: session and permanent. Session history keeps
739 record of all actions in a kamaki shell session, while permanent history
740 appends all commands to an accessible history file.
742 Session history is only available in interactive shell mode. Users can iterate
743 through past commands in the same session with the ↑ and ↓ keys. Session
744 history is not stored, although syntactically correct commands are recorded
745 through the permanent history mechanism.
747 Permanent history is implemented as a command group and is common to both the
748 one-command and shell interfaces. In specific, every syntactically correct
749 command is appended in a history file (configured as `history_file` in
750 settings, see `setup section <setup.html>`_ for details). Commands executed in
751 one-command mode are mixed with the ones run in kamaki shell (also
752 see :ref:`using-history-ref` section on this guide).
757 The history-run feature allows the sequential run of previous command
758 executions in kamaki shell.
760 The following sequence copies and downloads a file from *mycontainer1* ,
761 uploads it to *mycontainer2* , then undo the proccess and repeats it with
764 .. code-block:: console
765 :emphasize-lines: 1,12,19,32
767 * Download mycontainer1:myfile and upload it to mycontainer2:myfile
769 [file]: copy mycontainer1:somefile mycontainer1:myfile
770 [file]: download mycontainer1:myfile mylocalfile
772 [file]: upload mylocalfile mycontainer2:myfile
776 [file]: !rm mylocalfile
777 [file]: delete mycontainer1:myfile
778 [file]: delete mycontainer2:myfile
780 * check history entries *
785 2. file copy mycontainer1:somefile mycontainer1:myfile
786 3. file download mycontainer1:myfile mylocalfile
787 4. file upload mylocalfile mycontainer2:myfile
788 5. file delete mycontainer1:myfile
789 6. file delete mycontainer2:myfile
793 *repeat the process *
795 <file copy mycontainer1:somefile mycontainer1:myfile>
796 <file download mycontainer1:myfile mylocalfile>
798 <file upload mylocalfile mycontainer2:myfile>
801 For powerfull scripting, users are advised to take advantage of their os shell
802 scripting capabilities and combine them with kamaki one-command. Still, the
803 history-run functionality might prove handy in many occasions.
808 Kamaki shell features tab completion for the first level of command terms of
809 the current context. Tab completion pool changes dynamically when the context
810 is switched. Currently, tab completion is not supported when / is used
811 (see :ref:`accessing-top-level-commands-ref` ).
816 Kamaki shell features the ability to execute OS-shell commands from any
817 context. This can be achieved by typing *!* or *shell*::
819 [kamaki_context]: !<OS shell command>
820 ... OS shell command output ...
822 [kamaki_context]: shell <OS shell command>
823 ... OS shell command output ...
825 .. code-block:: console
828 Example 4.7.1: Run unix-style shell commands from kamaki shell
833 drwxrwxr-x 2 username username 4096 Nov 27 16:47 .
834 drwxrwxr-x 7 username username 4096 Nov 27 16:47 ..
835 -rw-rw-r-- 1 username username 8063 Jun 28 14:48 kamaki-logo.png
837 [kamaki]: shell cp kamaki-logo.png logo-copy.png
839 [kamaki]: shell ls -al
841 drwxrwxr-x 2 username username 4096 Nov 27 16:47 .
842 drwxrwxr-x 7 username username 4096 Nov 27 16:47 ..
843 -rw-rw-r-- 1 username username 8063 Jun 28 14:48 kamaki-logo.png
844 -rw-rw-r-- 1 username username 8063 Jun 28 14:48 logo-copy.png
847 Kamaki shell commits command strings to the outside shell and prints the
848 results, without interacting with it. After a command is finished, kamaki shell
849 returns to its initial state, which involves the current directory, as show in
852 .. code-block:: console
855 Example 4.8.2: Attempt (and fail) to change working directory