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.
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 <developers/code.html#the-clients-api>`_ section.
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.
13 It is essential for users to get a valid configuration token that works with for a synnefo-compliant Identity Manager service (okeanos.grnet.gr users go `here <https://accounts.okeanos.grnet.gr/im/>`_) and provide it to kamaki:
15 .. code-block:: console
18 Example 1.1: Set user token to myt0k3n==
20 $ kamaki config set token myt0k3n==
24 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.
26 In favor of interactive shell behavior:
28 * tab completion for commands (mostly on (X)nix OSs)
29 * session history with "up" / "down" keys
30 * shorter commands with command context switching
31 * re-run old commands with /history
33 In favor of one-command behavior:
35 * can be used along with advanced shell features (pipelines, redirection, etc.)
36 * can be used in shell scripts
37 * prints debug and verbose messages if needed
41 To use kamaki as a shell, run:
43 * without any parameters or arguments
45 .. code-block:: console
48 Example 2.2.1: Run kamaki shell
52 * with any kind of '-' prefixed arguments, except '-h', '--help'.
54 .. code-block:: console
57 Example 2.2.2: Run kamaki shell with custom configuration file
59 $ kamaki --config myconfig.file
64 To use kamaki as an one-command tool, run:
66 * with the '-h' or '--help' arguments (help for kamaki one-command)
68 .. code-block:: console
71 Example 2.3.1: Kamaki help
75 * with one or more command parameters:
77 .. code-block:: console
80 Example 2.3.2: List VMs managed by user
90 Kamaki help is used to list available commands with description, syntax and corresponding optional arguments.
92 To see the command groups, 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.
94 .. code-block:: console
97 Example 3.1.1: kamaki help shows available parameters and command groups
101 usage: kamaki <cmd_group> [<cmd_subbroup> ...] <cmd>
102 [-s] [-V] [-i] [--config CONFIG] [-o OPTIONS] [-h]
105 -v, --verbose More info at response
106 -s, --silent Do not output anything
107 -V, --version Print current version
108 -d, --debug Include debug output
109 -i, --include Include protocol headers in the output
110 --config CONFIG Path to configuration file
111 -o OPTIONS, --options OPTIONS
112 Override a config value
113 -h, --help Show help message
117 user: Astakos API commands
118 config: Configuration commands
119 flavor: Compute/Cyclades API flavor commands
120 history: Command history
121 image: Plankton (and Compute) Image API commands
122 network: Compute/Cyclades API network commands
123 server: Compute/Cyclades API server commands
124 file: Pithos+ storage commands
126 .. code-block:: console
129 Example 3.1.2: Cyclades help contains all first-level commands of Cyclades command group
133 usage: kamaki server <...> [-v] [-s] [-V] [-d] [-i] [--config CONFIG]
137 -v, --verbose More info at response
138 -s, --silent Do not output anything
139 -V, --version Print current version
140 -d, --debug Include debug output
141 -i, --include Include protocol headers in the output
142 --config CONFIG Path to configuration file
143 -o OPTIONS, --options OPTIONS
144 Override a config value
145 -h, --help Show help message
149 addmeta : Add server metadata
150 addr : List a server's nic address
151 console : Get a VNC console
152 create : Create a server
153 delete : Delete a server
154 delmeta : Delete server metadata
155 firewall: Set the server's firewall profile
156 info : Get server details
158 meta : Get a server's metadata
159 reboot : Reboot a server
160 rename : Update a server's name
161 setmeta : Update server's metadata
162 shutdown: Shutdown a server
163 start : Start a server
164 stats : Get server statistics
165 wait : Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
167 .. code-block:: console
170 Example 3.1.3: Help for command "server list" with syntax, description and available user options
173 $ kamaki server list -h
174 usage: kamaki server list [-V] [-i] [--config CONFIG] [-h] [-l]
179 -v, --verbose More info at response
180 -s, --silent Do not output anything
181 -V, --version Print current version
182 -d, --debug Include debug output
183 -i, --include Include protocol headers in the output
184 --config CONFIG Path to configuration file
185 -o OPTIONS, --options OPTIONS
186 Override a config value
187 -h, --help Show help message
188 -l show detailed output
190 .. _using-history-ref:
195 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>`_).
197 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:
199 .. code-block:: console
202 Example 3.2.1: Available history options
208 clean: Clean up history (permanent)
209 run : Run previously executed command(s)
210 show : Show intersession command history
212 The following example showcases how to use history in kamaki
214 .. code-block:: console
217 Example 3.2.2: Clean up everything, run a kamaki command, show full and filtered history
220 $ kamaki history clean
223 $ kamaki history show
224 1. kamaki server list
225 2. kamaki history show
226 $ kamaki history show --match server
227 1. kamaki server list
228 3. kamaki history show --match server
233 In case of errors, kamaki in debug mode shows useful debug information, like the stack trace. Kamaki in debug mode cancels suppression of warning messages.
235 To run kamaki in debug mode use the -d or --debug option (can be combined with any other parameters or options)
240 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.
242 To run kamaki in verbose mode use the -v or --verbose option
244 Be default, kamaki in verbose mode prints down only the headers and the address information, thus hiding the data body of the request or response. To see the data body, the -i option can be used.
249 Kamaki commands can be used along with advanced shell features.
251 .. code-block:: console
254 Example 3.4.1: Print username for token us3rt0k3n== using grep
257 $ kamaki user authenticate -o token=us3rt0k3n== | grep userame
258 userame : user@synnefo.org
260 The -o argument can be used to temporarily override various (set or unset) options. In one command, all -o option sets are forgotten just after the command has been completed, and the previous settings are restored (a.k.a. the configuration file is not modified).
262 The user-authenticate command in example 3.4.1 runs with an explicitly provided token, which temporarily overrides the token provided in the configuration file.
270 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 ("file" in example 4.1.1).
272 .. code-block:: console
275 Example 4.1.1: Enter file commands context / group
282 Type **exit** (alternatively **ctrl-D** in (X)nix systems or **ctrl-Z** in Windows) 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.
284 .. code-block:: console
287 Example 4.1.2: Exit file context and then exit kamaki
293 A user might **browse** through different contexts during one session.
295 .. code-block:: console
298 Example 4.1.3: Execute list command in different contexts
303 ... (configuration options listing) ...
307 ... (storage containers listing) ...
311 ... (VMs listing) ...
315 Users have the option to avoid switching between contexts: all commands can run from the **top context**. As a result, examples 4.1.3 and 4.1.4 are equivalent.
317 .. code-block:: console
320 Example 4.1.4: Execute different "list" commands from top context
323 [kamaki]: config list
324 ... (configuration options listing) ...
326 ... (storage container listing) ...
327 [kamaki]: server list
328 ... (VMs listing) ...
334 There are two help mechanisms: a context-level and a command-level.
336 **Context-level help** lists the available commands in a context and can also offer a short description for each command.
338 Context-level help syntax::
340 * Show available commands in current context *
344 * Show help for command cmd *
348 The context-level help results change from context to context
350 .. code-block:: console
353 Example 4.2.1: Get available commands, pick a context and get help there as well
360 user config flavor history image network server file
362 interactive shell commands:
363 ===========================
367 Configuration commands (config -h for more options)
377 interactive shell commands:
378 ===========================
382 Set a configuration option (set -h for more options)
384 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.
386 **Command-level help** prints the syntax, arguments and description of a specific (terminal) command
388 Command-level help syntax::
390 * Get help for command cmd1 cmd2 ... cmdN *
391 [context]: cmd1 cmd2 ... cmdN -h
396 <arguments and possible extensions>
398 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.
400 .. code-block:: console
403 Example 4.2.2: Get command-level help for config and config-set
406 [kamaki]: config --help
407 config: Configuration commands
408 delete: Delete a configuration option (and use the default value)
409 get : Show a configuration option
410 list : List configuration options
411 set : Set a configuration option
416 usage: set <option> <value> [-v] [-d] [-h] [-i] [--config CONFIG] [-s]
418 Set a configuration option
421 -v, --verbose More info at response
422 -d, --debug Include debug output
423 -h, --help Show help message
424 -i, --include Include protocol headers in the output
425 --config CONFIG Path to configuration file
426 -s, --silent Do not output anything
428 There are many ways of producing a help message, as shown in example 4.2.3
430 .. code-block:: console
433 Example 4.2.3: Equivalent calls of command-level help for config-set
438 [kamaki]: config set -h
439 [kamaki]: config set --help
440 [file]: /config set -h
441 [server]: /config set --help
443 .. _accessing-top-level-commands-ref:
445 Accessing top-level commands
446 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
448 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::
450 * access a command "anothercontext cmd1 cmd2 ... cmdN"
451 [context]: /anothercontext cmd1 cmd2 ... cmdN
453 An example (4.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:
455 * the name of the new VM
459 It is often the case that a user who works in the context command, needs to create a new VM, but hasn't selected a flavor or an image id, or cannot recall the id of that flavor or image. Therefore, it is necessary to list all available flavors (flavor-list) or images (image-compute-list). Both commands belong to different contexts.
461 .. code-block:: console
464 Example 4.3.1: Create a VM from server context
467 create <name> <flavor id> <image id> ...
470 [server]: /flavor list
473 SNF:disk_template: drbd
478 [server]: /image compute list
479 1580deb4-edb3-7a246c4c0528 (Ubuntu Desktop)
480 18a82962-43eb-8f8880af89d7 (Windows 7)
481 531aa018-9a40-a4bfe6a0caff (Windows XP)
482 6aa6eafd-dccb-67fe2bdde87e (Debian Desktop)
484 [server]: create 'my debian' 43 6aa6eafd-dccb-67fe2bdde87e
487 An other example (4.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 acquire a new token (valid for the Astakos identity manager of preference) which has to be set to kamaki.
489 .. code-block:: console
492 Example 4.3.2: Set a new token from file context
496 (401) UNAUTHORIZED Access denied
498 [file]: /user authenticate
499 (401) UNAUTHORIZED Invalid X-Auth-Token
501 [file]: /config get token
504 [file]: /config set token myfr35ht0k3n==
506 [file]: /config get token
510 1. pithos (10MB, 2 objects)
511 2. trash (0B, 0 objects)
513 .. note:: The error messages on this example where shortened for clarity. Actual kamaki error messages are more helpful and descriptive.
515 The following example compares some equivalent calls that run *user-authenticate* after a *file-list* 401 failure.
517 .. code-block:: console
518 :emphasize-lines: 1,3,10,17,26
520 Example 4.3.3: Equivalent user-authenticate calls after a file-list 401 failure
522 * without kamaki interactive shell *
524 (401) UNAUTHORIZED Access denied
525 $ kamaki user authenticate
529 * from top-level context *
531 (401) UNAUTHORIZED Access denied
532 [kamaki]: user authenticate
538 (401) UNAUTHORIZED Access denied
547 (401) UNAUTHORIZED Access denied
548 [file]: /user authenticate
552 .. hint:: To exit kamaki shell while in a context, try */exit*
557 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.
559 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 / prefix.
561 .. Note:: config updates in kamaki shell persist even after the session is over.
563 All setting changes affect the physical kamaki config file. The config file is created automatically at callers' home firectory the first time a config option is set, and lives there as *.kamakirc* . It can be edited with any text editor or managed with kamaki config commands.
565 In example 4.4.1 the user is going to work with only one storage container. The file commands use the container:path syntax, but if the user sets a container name as default, the container name can be omitted. This is possible by setting a *file.container* setting.
567 .. code-block:: console
570 Example 4.4.1: Set default storage container
574 1. mycontainer (32MB, 2 objects)
575 2. pithos (0B, 0 objects)
576 3. trash (2MB, 1 objects)
578 [file]: list mycontainer
580 2. 20M mydir/rndm_local.file
582 [file]: /config set file.container mycontainer
586 2. 20M mydir/rndm_local.file
588 After a while, the user needs to work with multiple containers, therefore a default container is no longer needed. The *file.container* setting can be deleted, as shown in example 4.4.2 .
590 .. code-block:: console
593 Example 4.4.2: Delete a setting option
596 [file]: /config delete file.container
599 1. mycontainer (32MB, 2 objects)
600 2. pithos (0B, 0 objects)
601 3. trash (2MB, 1 objects)
606 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.
608 Session history is only available in interactive shell mode. Users can iterate through past commands in the same session with the *up* and *down* keys. Session history is not stored, although syntactically correct commands are recorded through the permanent history mechanism
610 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).
615 The history-run feature allows the sequential run of previous command executions in kamaki shell.
617 The following sequence copies and downloads a file from *mycontainer1* , uploads it to *mycontainer2* , then undo the proccess and repeats it with history-run
619 .. code-block:: console
620 :emphasize-lines: 1,12,19,32
622 * Download mycontainer1:myfile and upload it to mycontainer2:myfile
624 [file]: copy mycontainer1:somefile mycontainer1:myfile
625 [file]: download mycontainer1:myfile mylocalfile
627 [file]: upload mylocalfile mycontainer2:myfile
631 [file]: !rm mylocalfile
632 [file]: delete mycontainer1:myfile
633 [file]: delete mycontainer2:myfile
635 * check history entries *
640 2. file copy mycontainer1:somefile mycontainer1:myfile
641 3. file download mycontainer1:myfile mylocalfile
642 4. file upload mylocalfile mycontainer2:myfile
643 5. file delete mycontainer1:myfile
644 6. file delete mycontainer2:myfile
648 *repeat the process *
650 <file copy mycontainer1:somefile mycontainer1:myfile>
651 <file download mycontainer1:myfile mylocalfile>
653 <file upload mylocalfile mycontainer2:myfile>
656 For powerfull scripting, users are advised to take advantage of their os shell scripting capabilities and combine them with kamaki one-command. Still, the history-run functionality might prove handy in many occasions.
661 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 / is used (see :ref:`accessing-top-level-commands-ref` ).
666 Kamaki shell features the ability to execute OS-shell commands from any context. This can be achieved by typing *!* or *shell*::
668 [kamaki_context]: !<OS shell command>
669 ... OS shell command output ...
671 [kamaki_context]: shell <OS shell command>
672 ... OS shell command output ...
674 .. code-block:: console
677 Example 4.7.1: Run unix-style shell commands from kamaki shell
682 drwxrwxr-x 2 username username 4096 Nov 27 16:47 .
683 drwxrwxr-x 7 username username 4096 Nov 27 16:47 ..
684 -rw-rw-r-- 1 username username 8063 Jun 28 14:48 kamaki-logo.png
686 [kamaki]: shell cp kamaki-logo.png logo-copy.png
688 [kamaki]: shell ls -al
690 drwxrwxr-x 2 username username 4096 Nov 27 16:47 .
691 drwxrwxr-x 7 username username 4096 Nov 27 16:47 ..
692 -rw-rw-r-- 1 username username 8063 Jun 28 14:48 kamaki-logo.png
693 -rw-rw-r-- 1 username username 8063 Jun 28 14:48 logo-copy.png
696 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 4.8.2 .
698 .. code-block:: console
701 Example 4.8.2: Attempt (and fail) to change working directory