Statistics
| Branch: | Tag: | Revision:

root / docs / usage.rst @ 2151584b

History | View | Annotate | Download (21.7 kB)

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
One-command interface
96
---------------------
97

    
98
Kamaki usage as a one-command tool is detailed in this section
99

    
100
Using help
101
^^^^^^^^^^
102

    
103
Kamaki help is used to see available commands, with description, syntax and their corresponding optional arguments.
104

    
105
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.
106

    
107
.. code-block:: console
108
    :emphasize-lines: 1
109

    
110
    Example 3.1.1: kamaki help shows available parameters and command groups
111

    
112

    
113
    $ kamaki -h
114
    usage: kamaki <cmd_group> [<cmd_subbroup> ...] <cmd>
115
        [-s] [-V] [-i] [--config CONFIG] [-o OPTIONS] [-h]
116

    
117
    optional arguments:
118
      -v, --verbose         More info at response
119
      -s, --silent          Do not output anything
120
      -V, --version         Print current version
121
      -d, --debug           Include debug output
122
      -i, --include         Include protocol headers in the output
123
      --config CONFIG       Path to configuration file
124
      -o OPTIONS, --options OPTIONS
125
                            Override a config value
126
      -h, --help            Show help message
127

    
128
    Options:
129
     - - - -
130
    astakos:  Astakos API commands
131
    config :  Configuration commands
132
    flavor :  Compute/Cyclades API flavor commands
133
    history:  Command history
134
    image  :  Compute/Cyclades or Glance API image commands
135
    network:  Compute/Cyclades API network commands
136
    server :  Compute/Cyclades API server commands
137
    store  :  Pithos+ storage commands
138

    
139
.. code-block:: console
140
    :emphasize-lines: 1
141

    
142
    Example 3.1.2: Cyclades help contains all first-level commands of Cyclades command group
143

    
144

    
145
    $ kamaki cyclades -h
146
    usage: kamaki server <...> [-v] [-s] [-V] [-d] [-i] [--config CONFIG]
147
                               [-o OPTIONS] [-h]
148

    
149
    optional arguments:
150
      -v, --verbose         More info at response
151
      -s, --silent          Do not output anything
152
      -V, --version         Print current version
153
      -d, --debug           Include debug output
154
      -i, --include         Include protocol headers in the output
155
      --config CONFIG       Path to configuration file
156
      -o OPTIONS, --options OPTIONS
157
                            Override a config value
158
      -h, --help            Show help message
159

    
160
    Options:
161
     - - - -
162
    addmeta :  Add server metadata
163
    addr    :  List a server's nic address
164
    console :  Get a VNC console
165
    create  :  Create a server
166
    delete  :  Delete a server
167
    delmeta :  Delete server metadata
168
    firewall:  Set the server's firewall profile
169
    info    :  Get server details
170
    list    :  List servers
171
    meta    :  Get a server's metadata
172
    reboot  :  Reboot a server
173
    rename  :  Update a server's name
174
    setmeta :  Update server's metadata
175
    shutdown:  Shutdown a server
176
    start   :  Start a server
177
    stats   :  Get server statistics
178
    wait    :  Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
179

    
180
.. code-block:: console
181
    :emphasize-lines: 1
182

    
183
    Example 3.1.3: Help for command "server list" with syntax, description and available user options
184

    
185

    
186
    $ kamaki server list -h
187
    usage: kamaki server list [-V] [-i] [--config CONFIG] [-h] [-l]
188

    
189
    List servers
190

    
191
    optional arguments:
192
      -v, --verbose         More info at response
193
      -s, --silent          Do not output anything
194
      -V, --version         Print current version
195
      -d, --debug           Include debug output
196
      -i, --include         Include protocol headers in the output
197
      --config CONFIG       Path to configuration file
198
      -o OPTIONS, --options OPTIONS
199
                            Override a config value
200
      -h, --help            Show help message
201
      -l                    show detailed output
202

    
203
.. _using-history-ref:
204

    
205
Using history
206
^^^^^^^^^^^^^
207

    
208
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>`_).
209

    
210
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:
211

    
212
.. code-block:: console
213
    :emphasize-lines: 1
214

    
215
    Example 3.2.1: Available history options
216

    
217

    
218
    $ kamaki history -h
219
    ...
220
    clean:  Clean up history
221
    show :  Show history
222

    
223
The following example showcases how to use history in kamaki
224

    
225
.. code-block:: console
226
    :emphasize-lines: 1
227

    
228
    Example 3.2.2: Clean up everything, run a kamaki command, show full and filtered history
229
    
230

    
231
    $ kamaki history clean
232
    $ kamaki server list
233
    ...
234
    $ kamaki history show
235
    1.  kamaki server list
236
    2.  kamaki history show
237
    $ kamaki history show --match server
238
    1. kamaki server list
239
    3. kamaki history show --match server
240

    
241
Debug
242
^^^^^
243

    
244
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.
245

    
246
To run kamaki in debug mode use the -d or --debug option
247

    
248
Verbose
249
"""""""
250

    
251
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.
252

    
253
To run kamaki in verbose mode use the -v or --verbose option
254

    
255
One-command features
256
^^^^^^^^^^^^^^^^^^^^
257

    
258
Kamaki commands can be used along with advanced shell features.
259

    
260
.. code-block:: console
261
    :emphasize-lines: 1
262

    
263
    Example 3.4.1: Print username for token us3rt0k3n== using grep
264
    
265

    
266
    $ kamaki astakos authenticate -o token=us3rt0k3n== | grep uniq
267
    uniq        : user@synnefo.org
268

    
269
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).
270

    
271
The astakos-authenticate command in example 3.4.1 run against an explicitly provided token, which temporarily overrode the token provided in the configuration file.
272

    
273
Interactive shell
274
-----------------
275

    
276
Kamaki interactive shell is details in this section
277

    
278
Command Contexts
279
^^^^^^^^^^^^^^^^
280

    
281
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 4.1.1).
282

    
283
.. code-block:: console
284
    :emphasize-lines: 1
285

    
286
    Example 4.1.1: Enter store commands context / group
287

    
288

    
289
    $ kamaki
290
    [kamaki]:store
291
    [store]:
292

    
293
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.
294

    
295
.. code-block:: console
296
    :emphasize-lines: 1
297

    
298
    Example 4.1.2: Exit store context and then exit kamaki
299

    
300
    [store]: exit
301
    [kamaki]: exit
302
    $
303

    
304
A user might **browse** through different contexts during one session.
305

    
306
.. code-block:: console
307
    :emphasize-lines: 1
308

    
309
    Example 4.1.3: Execute list command in different contexts
310

    
311
    $ kamaki
312
    [kamaki]:config
313
    [config]:list
314
    ... (configuration options listing) ...
315
    [config]:exit
316
    [kamaki]:store
317
    [store]:list
318
    ... (storage containers listing) ...
319
    [store]:exit
320
    [kamaki]:server
321
    [server]:list
322
    ... (VMs listing) ...
323
    [server]: exit
324
    [kamaki]:
325

    
326
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.
327

    
328
.. code-block:: console
329
    :emphasize-lines: 1
330

    
331
    Example 4.1.4: Execute different "list" commands from top context
332

    
333

    
334
    [kamaki]:config list
335
    ... (configuration options listing) ...
336
    [kamaki]:store list
337
    ... (storage container listing) ...
338
    [kamaki]:server list
339
    ... (VMs listing) ...
340
    [kamaki]:
341

    
342
Using Help
343
^^^^^^^^^^
344

    
345
There are two help mechanisms: a context-level and a command-level.
346

    
347
**Context-level help** lists the available commands in a context and can also offer a short description for each command.
348

    
349
Context-level help syntax::
350

    
351
    * Show available commands in current context *
352
    [context]:help
353
    [context]:?
354

    
355
    * Show help for command cmd *
356
    [context]:help cmd
357
    [context]:?cmd
358

    
359
The context-level help results change from context to context
360

    
361
.. code-block:: console
362
    :emphasize-lines: 1
363

    
364
    Example 4.2.1: Get available commands, pick a context and get help there as well
365

    
366

    
367
    [kamaki]:help
368

    
369
    kamaki commands:
370
    ================
371
    astakos  config  flavor  history  image  network  server  store
372

    
373
    interactive shell commands:
374
    ===========================
375
    exit  help  shell
376

    
377
    [kamaki]:?config
378
    Configuration commands (config -h for more options)
379

    
380
    [kamaki]:config
381

    
382
    [config]:?
383

    
384
    config commands:
385
    ================
386
    delete  get  list  set
387

    
388
    interactive shell commands:
389
    ===========================
390
    exit  help  shell
391

    
392
    [config]:help set
393
    Set a configuration option (set -h for more options)
394

    
395
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.
396

    
397
**Command-level help** prints the syntax, arguments and description of a specific (terminal) command
398

    
399
Command-level help syntax::
400

    
401
    * Get help for command cmd1 cmd2 ... cmdN *
402
    [context]:cmd1 cmd2 ... cmdN -h
403
    <syntax>
404

    
405
    <description>
406

    
407
    <arguments and possible extensions>
408

    
409
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.
410

    
411
.. code-block:: console
412
    :emphasize-lines: 1
413

    
414
    Example 4.2.2: Get command-level help for config and config-set
415

    
416

    
417
    [kamaki]:config --help
418
    config: Configuration commands
419
    delete:  Delete a configuration option (and use the default value)
420
    get   :  Show a configuration option
421
    list  :  List configuration options
422
    set   :  Set a configuration option
423

    
424
    [kamaki]:config
425

    
426
    [config]:set -h
427
    usage: set <option> <value> [-v] [-d] [-h] [-i] [--config CONFIG] [-s]
428

    
429
    Set a configuration option
430

    
431
    optional arguments:
432
      -v, --verbose    More info at response
433
      -d, --debug      Include debug output
434
      -h, --help       Show help message
435
      -i, --include    Include protocol headers in the output
436
      --config CONFIG  Path to configuration file
437
      -s, --silent     Do not output anything
438

    
439
There are many ways of producing a help message, as shown in example 4.2.3
440

    
441
.. code-block:: console
442
    :emphasize-lines: 1
443

    
444
    Example 4.2.3: Equivalent calls of command-level help for config-set
445

    
446

    
447
    [config]:set -h
448
    [config]:set -help
449
    [kamaki]:config set -h
450
    [kamaki]:config set --help
451
    [store]:/config set -h
452
    [server]:/config set --help
453

    
454
.. _accessing-top-level-commands-ref:
455

    
456
Accessing top-level commands
457
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
458

    
459
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::
460

    
461
    * access a command "anothercontext cmd1 cmd2 ... cmdN"
462
    [context]:/anothercontext cmd1 cmd2 ... cmdN
463

    
464
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:
465

    
466
* the name of the new VM
467
* the flavor id
468
* the image id
469

    
470
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.
471

    
472
.. code-block:: console
473
    :emphasize-lines: 1
474

    
475
    Example 4.3.1: Create a VM from server context
476

    
477
    [server]:create -h
478
    create <name> <flavor id> <image id> ...
479
    ...
480
    
481
    [server]:/flavor list
482
    ...
483
    20. AFLAVOR
484
        SNF:disk_template:  drbd
485
        cpu              :  4
486
        disk             :  10
487
        id               :  43
488
        ram              :  2048
489
    
490
    [server]:/image list
491
    1580deb4-edb3-7a246c4c0528 (Ubuntu Desktop)
492
    18a82962-43eb-8f8880af89d7 (Windows 7)
493
    531aa018-9a40-a4bfe6a0caff (Windows XP)
494
    6aa6eafd-dccb-67fe2bdde87e (Debian Desktop)
495
    
496
    [server]:create 'my debian' 43 6aa6eafd-dccb-67fe2bdde87e
497
    ...
498

    
499
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 acquires a new token (with a browser) which has to be set to kamaki.
500

    
501
.. code-block:: console
502
    :emphasize-lines: 1
503

    
504
    Example 4.3.2: Set a new token from store context
505

    
506

    
507
    [store]:list
508
    (401) UNAUTHORIZED Access denied
509

    
510
    [store]:/astakos authenticate
511
    (401) UNAUTHORIZED Invalid X-Auth-Token
512

    
513
    [store]:/config get token
514
    my3xp1r3dt0k3n==
515

    
516
    [store]:/config set token myfr35ht0k3n==
517

    
518
    [store]:/config get token
519
    myfr35ht0k3n==
520

    
521
    [store]:list
522
    1.  pithos (10MB, 2 objects)
523
    2.  trash (0B, 0 objects)
524

    
525
The following example compares some equivalent calls that run *astakos-authenticate* after a *store-list* 401 failure.
526

    
527
.. code-block:: console
528
    :emphasize-lines: 1,3,10,17,26
529

    
530
    Example 4.3.3: Equivalent astakos-authenticate calls after a store-list 401 failure
531

    
532
    * without kamaki interactive shell *
533
    $ kamaki store list
534
    (401) UNAUTHORIZED Access denied
535
    $ kamaki astakos authenticate
536
    ...
537
    $
538

    
539
    * from top-level context *
540
    [kamaki]:store list
541
    (401) UNAUTHORIZED Access denied
542
    [kamaki]:astakos authenticate
543
    ...
544
    [kamaki]
545

    
546
    * maximum typing *
547
    [store]:list
548
    (401) UNAUTHORIZED Access denied
549
    [store]:exit
550
    [kamaki]:astakos
551
    [astakos]:authenticate
552
    ...
553
    [astakos]:
554

    
555
    * minimum typing *
556
    [store]: list
557
    (401) UNAUTHORIZED Access denied
558
    [store]:/astakos authenticate
559
    ...
560
    [store]:
561

    
562
.. hint:: To exit kamaki shell while in a context, try */exit*
563

    
564
Using config
565
^^^^^^^^^^^^
566

    
567
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.
568

    
569
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.
570

    
571
.. 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)
572

    
573
In example 4.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.
574

    
575
.. code-block:: console
576
    :emphasize-lines: 1
577

    
578
    Example 4.4.1: Set default storage container
579

    
580

    
581
    [store]:list
582
    1.  mycontainer (32MB, 2 objects)
583
    2.  pithos (0B, 0 objects)
584
    3.  trash (2MB, 1 objects)
585

    
586
    [store]:list mycontainer
587
    1.  D mydir/
588
    2.  20M mydir/rndm_local.file
589
    
590
    [store]:/config set store.container mycontainer
591

    
592
    [store]: list
593
    1.  D mydir/
594
    2.  20M mydir/rndm_local.file
595

    
596
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 4.4.2 .
597

    
598
.. code-block:: console
599
    :emphasize-lines: 1
600

    
601
    Example 4.4.2: Delete a setting option
602

    
603

    
604
    [store]:/config delete store.container
605

    
606
    [store]:list
607
    1.  mycontainer (32MB, 2 objects)
608
    2.  pithos (0B, 0 objects)
609
    3.  trash (2MB, 1 objects)
610

    
611
.. 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.
612

    
613
Using history
614
^^^^^^^^^^^^^
615

    
616
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.
617

    
618
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
619

    
620
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).
621

    
622
Tab completion
623
^^^^^^^^^^^^^^
624

    
625
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 ).
626

    
627
OS Shell integration
628
^^^^^^^^^^^^^^^^^^^^
629

    
630
Kamaki shell features the ability to execute OS-shell commands from any context. This can be achieved by typing *!* or *shell*::
631

    
632
    [kamaki_context]:!<OS shell command>
633
    ... OS shell command output ...
634

    
635
    [kamaki_context]:shell <OS shell command>
636
    ... OS shell command output ...
637

    
638
.. code-block:: console
639
    :emphasize-lines: 1
640

    
641
    Example 4.7.1: Run unix-style shell commands from kamaki shell
642

    
643

    
644
    [kamaki]:!ls -al
645
    total 16
646
    drwxrwxr-x 2 saxtouri saxtouri 4096 Nov 27 16:47 .
647
    drwxrwxr-x 7 saxtouri saxtouri 4096 Nov 27 16:47 ..
648
    -rw-rw-r-- 1 saxtouri saxtouri 8063 Jun 28 14:48 kamaki-logo.png
649

    
650
    [kamaki]:shell cp kamaki-logo.png logo-copy.png
651

    
652
    [kamaki]:shell ls -al
653
    total 24
654
    drwxrwxr-x 2 saxtouri saxtouri 4096 Nov 27 16:47 .
655
    drwxrwxr-x 7 saxtouri saxtouri 4096 Nov 27 16:47 ..
656
    -rw-rw-r-- 1 saxtouri saxtouri 8063 Jun 28 14:48 kamaki-logo.png
657
    -rw-rw-r-- 1 saxtouri saxtouri 8063 Jun 28 14:48 logo-copy.png
658

    
659

    
660
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.7.2 .
661

    
662
.. code-block:: console
663
    :emphasize-lines: 1
664

    
665
    Example 4.7.2: Attempt (and fail) to change working directory
666

    
667

    
668
    [kamaki]:!pwd
669
    /home/username
670

    
671
    [kamaki]:!cd ..
672

    
673
    [kamaki]:shell pwd
674
    /home/username