Statistics
| Branch: | Tag: | Revision:

root / docs / usage.rst @ 6489c38b

History | View | Annotate | Download (27.9 kB)

1
Usage
2
=====
3

    
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
7
both interfaces.
8

    
9
What's more, kamaki offers a clients library for the development of external
10
client applications for Synnefo. The clients library API is detailed in the
11
`Clients lib <developers/code.html#the-clients-api>`_ section.
12

    
13
Quick Setup
14
-----------
15

    
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.
18

    
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:
21

    
22
.. code-block:: console
23
    :emphasize-lines: 1
24

    
25
    Example 1.1: Set authentication URL, user token and cloud alias "default"
26

    
27
    $ kamaki config set cloud.default.url <authentication URL>
28
    $ kamaki config set cloud.default.token myt0k3n==
29

    
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
32
    be easily modified.
33

    
34
Shell vs one-command
35
--------------------
36
Kamaki users can access Synnefo services through either the interactive shell
37
or the one-command interface. 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.
40

    
41
In favor of interactive shell:
42

    
43
* tab completion for commands (if supported by the user shell)
44
* session history with ↑ or ↓ keys (if supported by the user shell)
45
* shorter commands with command context switching
46
* re-run old commands with /history
47

    
48
In favor of one-command:
49

    
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
53

    
54
Run as shell
55
^^^^^^^^^^^^
56
To use kamaki as a shell, run:
57

    
58
* without any parameters or arguments
59

    
60
.. code-block:: console
61
    :emphasize-lines: 1
62

    
63
    Example 2.2.1: Run kamaki shell
64

    
65
    $ kamaki
66

    
67
* with any kind of '-' prefixed arguments, except '-h', '--help', '-V',
68
    '- - version'.
69

    
70
.. code-block:: console
71
    :emphasize-lines: 1
72

    
73
    Example 2.2.2: Run kamaki shell with custom configuration file
74

    
75
    $ kamaki -c myconfig.file
76

    
77

    
78
Run as one-command
79
^^^^^^^^^^^^^^^^^^
80
To use kamaki as an one-command tool, run:
81

    
82
* with the '-h' or '--help' arguments (help for kamaki one-command)
83

    
84
.. code-block:: console
85
    :emphasize-lines: 1
86

    
87
    Example 2.3.1: Kamaki help
88

    
89
    $kamaki -h
90

    
91
* with one or more command parameters:
92

    
93
.. code-block:: console
94
    :emphasize-lines: 1
95

    
96
    Example 2.3.2: List servers managed by user
97

    
98
    $ kamaki server list
99

    
100
One-command interface
101
---------------------
102

    
103
Using help
104
^^^^^^^^^^
105

    
106
Kamaki help provides information on available commands (description, syntax and
107
corresponding optional arguments).
108

    
109
To see the command groups, use -h or --help (example 1.3.1). The
110
following examples demonstrate the help messages of kamaki, in the context of a
111
command group (server) and of a command in that group (list).
112

    
113
.. code-block:: console
114
    :emphasize-lines: 1
115

    
116
    Example 3.1.1: kamaki help shows available parameters and command groups
117

    
118

    
119
    $ kamaki -h
120
    usage: kamaki <cmd_group> [<cmd_subbroup> ...] <cmd>
121
        [-v] [-s] [-V] [-d] [-i] [-c CONFIG] [-o OPTIONS] [--cloud CLOUD] [-h]
122

    
123
    optional arguments:
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
135

    
136
    Options:
137
     - - - -
138
    network: Cyclades/Compute API network commands
139
    user: Astakos API commands
140
    livetest: Client func. tests on live servers
141
    server: Cyclades/Compute API server commands
142
    project: Synnefo project management CLI
143
    file: Pithos+/Storage API commands
144
    flavor: Cyclades/Compute API flavor commands
145
    config: Kamaki configurations
146
    image: Cyclades/Plankton API image commands
147
    image compute:  Cyclades/Compute API image commands
148
    history: Kamaki command history
149

    
150

    
151
.. code-block:: console
152
    :emphasize-lines: 1,2
153

    
154
    Example 3.1.2: Cyclades help contains all first-level commands of Cyclades
155
    command group
156

    
157
    $ kamaki server -h
158
    usage: kamaki server <...> [-v] [-s] [-V] [-d] [-i] [-c CONFIG]
159
                               [-o OPTIONS] [--cloud CLOUD] [-h]
160

    
161
    optional arguments:
162
      -v, --verbose         More info at response
163
      -s, --silent          Do not output anything
164
      -V, --version         Print current version
165
      -d, --debug           Include debug output
166
      -i, --include         Include protocol headers in the output
167
      -c CONFIG, --config CONFIG
168
                            Path to configuration file
169
      -o OPTIONS, --options OPTIONS
170
                            Override a config value
171
      --cloud CLOUD         Chose a cloud to connect to
172
      -h, --help            Show help message
173

    
174
    Options:
175
     - - - -
176
    info: Detailed information on a Virtual Machine
177
    rename: Set/update a virtual server name
178
    delete: Delete a virtual server
179
    console: Get a VNC console to access an existing virtual server
180
    addr: List the addresses of all network interfaces on a virtual server
181
    firewall: Manage virtual server firewall profiles for public networks
182
    create: Create a server (aka Virtual Machine)
183
    list: List Virtual Machines accessible by user
184
    reboot: Reboot a virtual server
185
    start: Start an existing virtual server
186
    shutdown: Shutdown an active virtual server
187
    stats: Get virtual server statistics
188
    metadata: Manage Server metadata (key:value pairs of server attributes)
189
    resize: Set a different flavor for an existing server
190
    wait: Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
191

    
192
.. code-block:: console
193
    :emphasize-lines: 1,2
194

    
195
    Example 3.1.3: Help for command "server list" with syntax, description and
196
    available user options
197

    
198
    $ kamaki server list -h
199
    usage: kamaki server list [-v] [-s] [-V] [-d] [-i] [-c CONFIG] [-o OPTIONS]
200
                              [--cloud CLOUD] [-h] [--since SINCE] [--enumerate]
201
                              [-l] [--more] [-n LIMIT] [-j]
202

    
203
    List Virtual Machines accessible by user
204

    
205
    optional arguments:
206
      -v, --verbose         More info at response
207
      -s, --silent          Do not output anything
208
      -V, --version         Print current version
209
      -d, --debug           Include debug output
210
      -i, --include         Include raw connection data in the output
211
      -c CONFIG, --config CONFIG
212
                            Path to config file
213
      -o OPTIONS, --options OPTIONS
214
                            Override a config value
215
      --cloud CLOUD         Chose a cloud to connect to
216
      -h, --help            Show help message
217
      --status STATUS       filter by status (ACTIVE, STOPPED, REBOOT, ERROR,
218
                            etc.)
219
      --enumerate           Enumerate results
220
      --name-suffix NAME_SUFF
221
                            filter by name suffix (case insensitive)
222
      --image-id IMAGE_ID   filter by image id
223
      --metadata META       filter by metadata key=values
224
      -j, --json            show headers in json
225
      --id ID               filter by id
226
      --user-id USER_ID     filter by user id
227
      --id-like ID_LIKE     print only if id contains this (case insensitive)
228
      --id-suffix ID_SUFF   filter by id suffix (case insensitive)
229
      --since SINCE         show only items since date (' d/m/Y H:M:S ')
230
      -l, --details         show detailed output
231
      --name NAME           filter by name
232
      --more                output results in pages (-n to set items per page,
233
                            default 10)
234
      --name-prefix NAME_PREF
235
                            filter by name prefix (case insensitive)
236
      -n LIMIT, --number LIMIT
237
                            limit number of listed virtual servers
238
      --id-prefix ID_PREF   filter by id prefix (case insensitive)
239
      --user-name USER_NAME
240
                            filter by user name
241
      --name-like NAME_LIKE
242
                            print only if name contains this (case insensitive)
243
      --metadata-like META_LIKE
244
                            print only if in key=value, the value is part of
245
                            actual value
246
      --flavor-id FLAVOR_ID
247
                            filter by flavor id
248

    
249
    Details:
250
    Use filtering arguments (e.g., --name-like) to manage long server lists
251

    
252
.. _using-history-ref:
253

    
254
Using history
255
^^^^^^^^^^^^^
256

    
257
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>`_).
258

    
259
Every command is appended at the end of that file. In order to see how to use
260
history, use the kamaki help system:
261

    
262
.. code-block:: console
263
    :emphasize-lines: 1
264

    
265
    Example 3.2.1: Available history options
266

    
267

    
268
    $ kamaki history -h
269
    Options:
270
     - - - -
271
    clean:  Clean up history (permanent)
272
    run  :  Run previously executed command(s)
273
    show :  Show intersession command history
274

    
275
The following example showcases how to use history in kamaki
276

    
277
.. code-block:: console
278
    :emphasize-lines: 1
279

    
280
    Example 3.2.2: Clean up everything, run a kamaki command, show full and filtered history
281
    
282

    
283
    $ kamaki history clean
284
    $ kamaki server list
285
    ...
286
    $ kamaki history show
287
    1.  kamaki server list
288
    2.  kamaki history show
289
    $ kamaki history show --match server
290
    1. kamaki server list
291
    3. kamaki history show --match server
292

    
293
Debug and logging
294
^^^^^^^^^^^^^^^^^
295

    
296
Debug
297
"""""
298

    
299
When in debug mode, kamaki outputs some useful debug information (stack trace
300
and http logs). Kamaki in debug mode cancels suppression of warning messages.
301

    
302
To run kamaki in debug mode use the -d or --debug option.
303

    
304

    
305
Verbose
306
"""""""
307

    
308
Most kamaki commands are translated into http requests. Kamaki clients API
309
translated the semantics to REST and handles the response. Users who need to
310
have access to these commands can use the verbose mode that presents the HTTP
311
Request details as well as the full server response.
312

    
313
To run kamaki in verbose mode use the *-v/- - verbose* option
314

    
315
Verbose mode outputs the request and response mode, address and
316
headers as well as the size of the data block, if any. Sensitive information
317
(x-auth-token header and data body) are omitted by default,. Users who need
318
this information may enable it through the log_token and log_data configuration
319
options (see next section)
320

    
321
.. tip:: Use the -o runtime option to enable config options on the fly, e.g, to
322
    include http data:
323

    
324
    .. code-block:: console
325

    
326
        $ kamaki server list -v -o log_data=on
327

    
328

    
329
Logging
330
"""""""
331

    
332
Kamaki keeps its logs in a file specified by the *log_file* option and it
333
defaults to *${HOME}/.kamaki.log*. This configuration option can be modified::
334

    
335
    kamaki config set log_file /new/log/file/path
336

    
337
Kamaki logs http request and response information, namely the method, URL,
338
headers and data size. Sensitive information (data and token header) are
339
omitted by default. There are some configuration options that can switch them
340
on, though:
341

    
342
* HTTP data blocks are not logged by default
343
    to enable logging the full http bodies, set log_data to `on`::
344

    
345
        kamaki config set log_data on
346

    
347
    to disable it, set it to `off`::
348

    
349
        kamaki config set log_data off
350

    
351
    or delete it::
352

    
353
        kamaki config delete log_data
354

    
355
* X-Auth-Token header is not logged by default
356
    to enable logging the X-Auth-Token header, set log_token to `on`::
357

    
358
        kamaki config set log_token on
359

    
360
    to disable it, set it to `off`::
361

    
362
        kamaki config set log_token off
363

    
364
    or delete it::
365

    
366
        kamaki config delete log_token
367

    
368
* The information (pid, name, date) of the processes that handle http requests
369
    is not logged by default, because if they are, logs are difficult to read.
370
    Still, they are useful for resolving race condition problems, so to enable
371
    logging proccess information::
372

    
373
        kamaki config set log_pid on
374

    
375
    to disable it, set if to off::
376

    
377
        kamaki config set log_pid off
378

    
379
    or delete it::
380

    
381
        kamaki config delete log_pid
382

    
383
One-command features
384
^^^^^^^^^^^^^^^^^^^^
385

    
386
Kamaki commands can be used along with advanced shell features.
387

    
388
.. code-block:: console
389
    :emphasize-lines: 1
390

    
391
    Example 3.4.1: List the trash container contents, containing c1_
392
    
393

    
394
    $ kamaki file list -o cloud.default.pithos_container=trash| grep c1_
395
    c1_1370859409.0 20KB
396
    c1_1370859414.0 9MB
397
    c1_1370859409.1 110B
398

    
399
The -o argument can be used to temporarily override various (set or unset)
400
options. In one command, all -o option sets are forgotten just after the
401
command has been completed, and the previous settings are restored (the
402
configuration file is not modified).
403

    
404
The file-list command in example 3.4.1 runs with an explicitly provided
405
pithos_account, which temporarily overrides the one probably provided in the
406
configuration file (it works even if the user has not set the optional
407
pithos_account config option).
408

    
409
.. tip:: There are better ways to list the contents of a container. Example
410
    3.4.1 is using this method for demonstration purposes only. The suggested
411
    method for listing container contents is *- - container=<container>*
412

    
413
Interactive shell
414
-----------------
415

    
416
Command Contexts
417
^^^^^^^^^^^^^^^^
418

    
419
The kamaki interactive shell implements the notion of command contexts. Each
420
command group is also a context where the users can **enter** by typing the
421
group name. If the context switch is successful, the kamaki shell prompt
422
changes to present the new context ("*file*" in example 4.1.1).
423

    
424
.. code-block:: console
425
    :emphasize-lines: 1
426

    
427
    Example 4.1.1: Start kamaki and switch to file context
428

    
429

    
430
    $ kamaki
431
    [kamaki]: file
432
    [file]:
433

    
434
Type **exit** (alternatively **ctrl-D** in (X)nix systems or **ctrl-Z** in
435
Windows) to exit a context and return to the context of origin. If already at
436
the top context (kamaki), an exit is equivalent to exiting the program.
437

    
438
.. code-block:: console
439
    :emphasize-lines: 1
440

    
441
    Example 4.1.2: Exit file context and then exit kamaki
442

    
443
    [file]: exit
444
    [kamaki]: exit
445
    $
446

    
447
A user might **browse** through different contexts during one session.
448

    
449
.. code-block:: console
450
    :emphasize-lines: 1
451

    
452
    Example 4.1.3: Execute list command in different contexts
453

    
454
    $ kamaki
455
    [kamaki]: config
456
    [config]: list
457
    ... (configuration options listing) ...
458
    [config]: exit
459
    [kamaki]: file
460
    [file]: list
461
    ... (storage containers listing) ...
462
    [file]: exit
463
    [kamaki]: server
464
    [server]: list
465
    ... (servers listing) ...
466
    [server]: exit
467
    [kamaki]:
468

    
469
Users have the option to avoid switching between contexts: all commands can run
470
from the **top context**. As a result, examples 4.1.3 and 4.1.4 are equivalent.
471

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

    
475
    Example 4.1.4: Execute different "list" commands from top context
476

    
477

    
478
    [kamaki]: config list
479
    ... (configuration options listing) ...
480
    [kamaki]: file list
481
    ... (storage container listing) ...
482
    [kamaki]: server list
483
    ... (servers listing) ...
484
    [kamaki]:
485

    
486
Using Help
487
^^^^^^^^^^
488

    
489
There are two help mechanisms: a context-level and a command-level.
490

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

    
494
Context-level help syntax::
495

    
496
    * Show available commands in current context *
497
    [context]: help
498
    ...
499
    [context]: ?
500
    ...
501

    
502
    * Show help for command cmd *
503
    [context]: help cmd
504
    ...
505
    [context]: ?cmd
506
    ...
507

    
508
The context-level help results may change from context to context
509

    
510
.. code-block:: console
511
    :emphasize-lines: 1
512

    
513
    Example 4.2.1: Get available commands and then get help in a context
514

    
515

    
516
    [kamaki]: help
517

    
518
    kamaki commands:
519
    ================
520
    user  config  flavor  history  image  network  server  file ...
521

    
522
    interactive shell commands:
523
    ===========================
524
    exit  help  shell
525

    
526
    [kamaki]: ?config
527
    Configuration commands (config -h for more options)
528

    
529
    [kamaki]: config
530

    
531
    [config]: ?
532

    
533
    config commands:
534
    ================
535
    delete  get  list  set
536

    
537
    interactive shell commands:
538
    ===========================
539
    exit  help  shell
540

    
541
    [config]: help set
542
    Set a configuration option (set -h for more options)
543

    
544
In context-level, there is a distinction between kamaki-commands and
545
interactive shell commands. The former are available in one-command mode and
546
are related to the cloud client setup and use, while the later are
547
context-shell functions.
548

    
549
**Command-level help** prints the syntax, arguments and description of a
550
specific (terminal) command
551

    
552
Command-level help syntax::
553

    
554
    * Get help for command cmd1 cmd2 ... cmdN *
555
    [context]: cmd1 cmd2 ... cmdN -h
556
    <syntax>
557

    
558
    <description>
559

    
560
    <arguments and possible extensions>
561

    
562
Command-level help mechanism is exactly the same as the one used in
563
one-command mode. For example, it is invoked by using the -h or --help
564
parameter at any point.
565

    
566
.. code-block:: console
567
    :emphasize-lines: 1
568

    
569
    Example 4.2.2: Get command-level help for config and config-set
570

    
571

    
572
    [kamaki]: config --help
573
    config: Configuration commands
574
    delete:  Delete a configuration option (and use the default value)
575
    get   :  Show a configuration option
576
    list  :  List configuration options
577
    set   :  Set a configuration option
578

    
579
    [kamaki]: config
580

    
581
    [config]: set -h
582
    usage: set <option> <value> [-v] [-d] [-h] [-i] [--config CONFIG] [-s]
583

    
584
    Set a configuration option
585

    
586
    optional arguments:
587
      -v, --verbose    More info at response
588
      -d, --debug      Include debug output
589
      -h, --help       Show help message
590
      -i, --include    Include protocol headers in the output
591
      --config CONFIG  Path to configuration file
592
      -s, --silent     Do not output anything
593

    
594
There are many ways of producing a help message, as shown in example 4.2.3
595

    
596
.. code-block:: console
597
    :emphasize-lines: 1
598

    
599
    Example 4.2.3: Equivalent calls of command-level help for config-set
600

    
601

    
602
    [config]: set -h
603
    [config]: set --help
604
    [kamaki]: config set -h
605
    [kamaki]: config set --help
606
    [file]: /config set -h
607
    [server]: /config set --help
608

    
609
.. _accessing-top-level-commands-ref:
610

    
611
Accessing top-level commands
612
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
613

    
614
When working in a context, it is often useful to access other contexts or
615
top-level commands. Kamaki offers access to top-level commands by using the
616
`/` prefix, as shown bellow::
617

    
618
    * access a command "anothercontext cmd1 cmd2 ... cmdN"
619
    [context]: /anothercontext cmd1 cmd2 ... cmdN
620

    
621
An example (4.3.1) that showcases how top-level access improves user experience
622
is the creation of a server. A server is created with the command server-create. This
623
command is called with three parameters:
624

    
625
* the name of the new server
626
* the flavor id
627
* the image id
628

    
629
An average user would enter the server context and type *create -h* to check the
630
syntax of the command. In that point, it would be nice to have some easy way of
631
accessing the *flavor* and *image* contexts, to list and pick a flavor id and an
632
image id. This is achieved with the / notation, as demonstrated in the following
633
example:
634

    
635
.. code-block:: console
636
    :emphasize-lines: 1
637

    
638
    Example 4.3.1: Create a server from server context
639

    
640
    [server]: create -h
641
    create <name> <flavor id> <image id> ...
642
    ...
643
    
644
    [server]: /flavor list
645
    ...
646
    43 AFLAVOR
647
        SNF:disk_template:  drbd
648
        cpu              :  4
649
        disk             :  10
650
        ram              :  2048
651
    
652
    [server]: /image compute list
653
    1580deb4-edb3-7a246c4c0528 (Ubuntu Desktop)
654
    18a82962-43eb-8f8880af89d7 (Windows 7)
655
    531aa018-9a40-a4bfe6a0caff (Windows XP)
656
    6aa6eafd-dccb-67fe2bdde87e (Debian Desktop)
657
    
658
    [server]: create 'my debian' 43 6aa6eafd-dccb-67fe2bdde87e
659
    ...
660

    
661
An other example (4.3.2) showcases how to acquire and modify configuration
662
settings from a different context. In this scenario, the user token expires at
663
server side while the user is working. When that happens, the system responds
664
with an *(401) UNAUTHORIZED* message. The user can acquire a new token (valid
665
for the Astakos identity manager of preference) which has to be set to kamaki.
666

    
667
.. code-block:: console
668
    :emphasize-lines: 1
669

    
670
    Example 4.3.2: Token suddenly expires. Set a new token from file context
671

    
672

    
673
    [file]: list
674
    (401) UNAUTHORIZED Access denied
675

    
676
    [file]: /user authenticate
677
    (401) UNAUTHORIZED Invalid X-Auth-Token
678

    
679
    [file]: /config get cloud.default.token
680
    my3xp1r3dt0k3n==
681

    
682
    [file]: /config set cloud.default.token myfr35ht0k3n==
683

    
684
    [file]: /config get cloud.default
685
    cloud.default.url = https://astakos.example.com/astakos/identity/2.0/
686
    cloud.default.token = myfr35ht0k3n==
687

    
688
    [file]: list
689
    1.  pithos (10MB, 2 objects)
690
    2.  trash (0B, 0 objects)
691

    
692
.. note:: The error messages on examples are shortened for clarity. Actual error
693
    messages are more helpful and descriptive.
694

    
695
The following example compares some equivalent calls that run
696
*user-authenticate* after a *file-list* 401 failure.
697

    
698
.. code-block:: console
699
    :emphasize-lines: 1,3,10,17,26
700

    
701
    Example 4.3.3: Equivalent user-authenticate calls after a file-list 401
702

    
703
    * I. without kamaki interactive shell *
704
    $ kamaki file list
705
    (401) UNAUTHORIZED Access denied
706
    $ kamaki user authenticate
707
    ...
708
    $
709

    
710
    * II. from top-level context *
711
    [kamaki]: file list
712
    (401) UNAUTHORIZED Access denied
713
    [kamaki]: user authenticate
714
    ...
715
    [kamaki]
716

    
717
    * III. maximum typing *
718
    [file]: list
719
    (401) UNAUTHORIZED Access denied
720
    [file]: exit
721
    [kamaki]: user
722
    [user]: authenticate
723
    ...
724
    [user]:
725

    
726
    * IV. minimum typing *
727
    [file]: list
728
    (401) UNAUTHORIZED Access denied
729
    [file]: /user authenticate
730
    ...
731
    [file]:
732

    
733
.. hint:: To exit kamaki shell while in a context, try */exit*
734

    
735
Using config
736
^^^^^^^^^^^^
737

    
738
The configuration mechanism of kamaki is detailed in the
739
`setup section <setup.html>`_, it is accessible as *config* and it is common for
740
both interaction modes. In specific, the configuration mechanism is implemented
741
as  `config`. Using the config commands is as straightforward as in any other
742
group of commands.
743

    
744
It is often useful to set, delete or update a value. This can be managed either
745
inside the config context or from any command context by using the / prefix.
746

    
747
.. Note:: config updates in kamaki shell persist even after the session is over
748

    
749
All setting changes affect the physical kamaki config file. The config file is
750
created automatically at callers' home firectory the first time a config option
751
is set, and lives there as *.kamakirc* . It can be edited with any text editor
752
or managed with kamaki config commands.
753

    
754
In example 4.4.1 the user is going to work with only one storage container. The
755
file commands use the container:path syntax, but if the user sets a container
756
name as default, the container name can be omitted.
757

    
758
.. code-block:: console
759
    :emphasize-lines: 1
760

    
761
    Example 4.4.1: Set default storage container (cloud alias: default)
762

    
763

    
764
    [file]: list
765
      mycontainer (32MB, 2 objects)
766
      pithos (0B, 0 objects)
767
      trash (2MB, 1 objects)
768

    
769
    [file]: list mycontainer
770
      D mydir/
771
      20M mydir/rndm_local.file
772
    
773
    [file]: /config set cloud.default.pithos_container mycontainer
774

    
775
    [file]: list
776
      D mydir/
777
      20M mydir/rndm_local.file
778

    
779
After a while, the user needs to work with multiple containers, therefore a
780
default container is no longer needed. The *pithos_container* setting can be
781
deleted, as shown in example 4.4.2
782

    
783
.. code-block:: console
784
    :emphasize-lines: 1
785

    
786
    Example 4.4.2: Delete a setting option (cloud: default)
787

    
788

    
789
    [file]: /config delete cloud.default.pithos_container
790

    
791
    [file]: list
792
      mycontainer (32MB, 2 objects)
793
      pithos (0B, 0 objects)
794
      trash (2MB, 1 objects)
795

    
796
History modes
797
^^^^^^^^^^^^^
798

    
799
There are two history modes: session and permanent. Session history keeps
800
record of all actions in a kamaki shell session, while permanent history
801
appends all commands to an accessible history file.
802

    
803
Session history is only available in interactive shell mode. Users can iterate
804
through past commands in the same session with the ↑ and ↓ keys. Session
805
history is not stored, although commands are recorded through the permanent
806
history mechanism.
807

    
808
Permanent history is implemented as a command group and is common to both the
809
one-command and shell interfaces. In specific, every command is appended in a
810
history file (configured as `history_file` in settings, see
811
`setup section <setup.html>`_ for details). Commands executed in one-command
812
mode are mixed with the ones run in kamaki shell (also see
813
:ref:`using-history-ref` section on this guide).
814

    
815
Scripting
816
^^^^^^^^^
817

    
818
The history-run feature allows the sequential run of previous command
819
executions in kamaki shell.
820

    
821
The following sequence copies and downloads a file from *mycontainer1* ,
822
uploads it to *mycontainer2* , then undo the proccess and repeats it with
823
history-run
824

    
825
.. code-block:: console
826
    :emphasize-lines: 1,12,19,32
827

    
828
    * Download mycontainer1:myfile and upload it to mycontainer2:myfile *
829
    [kamaki]: file
830
    [file]: copy mycontainer1:somefile mycontainer1:myfile
831
    [file]: download mycontainer1:myfile mylocalfile
832
    ...
833
    Download completed
834
    [file]: upload mylocalfile mycontainer2:myfile -f
835
    ...
836
    Upload completed
837

    
838
    * undo the process *
839
    [file]: !rm mylocalfile
840
    [file]: delete mycontainer1:myfile
841
    [file]: delete mycontainer2:myfile
842

    
843
    * check history entries *
844
    [file]: exit
845
    [kamaki]: history
846
    [history]: show
847
    1.  file
848
    2.  file copy mycontainer1:somefile mycontainer1:myfile
849
    3.  file download mycontainer1:myfile mylocalfile
850
    4.  file upload mylocalfile mycontainer2:myfile -f
851
    5.  file delete mycontainer1:myfile
852
    6.  file delete mycontainer2:myfile
853
    7.  history
854
    8.  history show
855

    
856
    *repeat the process *
857
    [history]: run 2-4
858
    <file copy mycontainer1:somefile mycontainer1:myfile>
859
    <file download mycontainer1:myfile mylocalfile>
860
    Download completed
861
    <file upload mylocalfile mycontainer2:myfile>
862
    Upload completed
863

    
864
For powerfull scripting, users are advised to take advantage of their os shell
865
scripting capabilities and combine them with kamaki one-command. Still, the
866
history-run functionality might prove handy in many occasions.
867

    
868
OS Shell integration
869
^^^^^^^^^^^^^^^^^^^^
870

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

    
874
    [kamaki_context]: !<OS shell command>
875
    ... OS shell command output ...
876

    
877
    [kamaki_context]: shell <OS shell command>
878
    ... OS shell command output ...
879

    
880
.. code-block:: console
881
    :emphasize-lines: 1
882

    
883
    Example 4.7.1: Run unix-style shell commands from kamaki shell
884

    
885

    
886
    [kamaki]: !ls -al
887
    total 16
888
    drwxrwxr-x 2 username username 4096 Nov 27 16:47 .
889
    drwxrwxr-x 7 username username 4096 Nov 27 16:47 ..
890
    -rw-rw-r-- 1 username username 8063 Jun 28 14:48 kamaki-logo.png
891

    
892
    [kamaki]: shell cp kamaki-logo.png logo-copy.png
893

    
894
    [kamaki]: shell ls -al
895
    total 24
896
    drwxrwxr-x 2 username username 4096 Nov 27 16:47 .
897
    drwxrwxr-x 7 username username 4096 Nov 27 16:47 ..
898
    -rw-rw-r-- 1 username username 8063 Jun 28 14:48 kamaki-logo.png
899
    -rw-rw-r-- 1 username username 8063 Jun 28 14:48 logo-copy.png
900

    
901

    
902
Kamaki shell commits command strings to the outside shell and prints the
903
results, without interacting with it. After a command is finished, kamaki shell
904
returns to its initial state, which involves the current directory, as shown in
905
example 4.8.2
906

    
907
.. code-block:: console
908
    :emphasize-lines: 1
909

    
910
    Example 4.8.2: Attempt (and fail) to change working directory
911

    
912

    
913
    [kamaki]: !pwd
914
    /home/username
915

    
916
    [kamaki]: !cd ..
917

    
918
    [kamaki]: shell pwd
919
    /home/username