shell.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2017;" >
  5. ]>
  6. <chapter id="kea-shell">
  7. <title>Kea Shell</title>
  8. <section id="shell-overview">
  9. <title>Overview</title>
  10. <para>Kea 1.2.0 introduced Control Agent (see <xref linkend="kea-ctrl-agent"/>) that
  11. provides a RESTful control interface over HTTP. That API is typically expected to be used by
  12. various IPAMs and similar management systems. Nevertheless, there are cases when a simple
  13. client is required to issue commands. Kea shell fulfills that need. It is a simple,
  14. command-line, scripting friendly text client that is able connect to CA, send commands with
  15. parameters, retrieve and print CA responses.</para>
  16. <para>The primary use case for shell is to be used as a tool in scriting environment,
  17. therefore the tool is not interactive. However, with simple tricks it can be run manually.
  18. </para>
  19. </section>
  20. <section id="shell-usage">
  21. <title>Shell Usage</title>
  22. <para>kea-shell accepts a number of optional parameters:
  23. </para>
  24. <itemizedlist>
  25. <listitem>
  26. <simpara>
  27. <command>--host <replaceable>hostname</replaceable></command> specifies the hostname
  28. of CA. If not specified, "localhost" is used.
  29. </simpara>
  30. </listitem>
  31. <listitem>
  32. <simpara>
  33. <command>--port <replaceable>number</replaceable></command> specifies the TCP port
  34. on which CA listens. If not specified, 8000 is used.
  35. </simpara>
  36. </listitem>
  37. <listitem>
  38. <simpara>
  39. <command>--timeout <replaceable>seconds</replaceable></command> specifies the
  40. timeout in seconds for connection. If not specified, 10 seconds is used.
  41. </simpara>
  42. </listitem>
  43. <listitem>
  44. <simpara>
  45. <command>-h</command> prints out help message.
  46. </simpara>
  47. </listitem>
  48. <listitem>
  49. <simpara>
  50. <command>-v</command> prints software version.
  51. </simpara>
  52. </listitem>
  53. <listitem>
  54. <simpara>
  55. <command>command</command> specifies the command to be sent. If not specified,
  56. <command>list-commands</command> command is used.
  57. </simpara>
  58. </listitem>
  59. </itemizedlist>
  60. <para>
  61. Once started, the shell reads command parameters from the standard input. Those are
  62. expected to be in JSON format. After read ends, the shell establishes connection using
  63. http protocol to CA, sends the command and awaits response. Once the response becomes
  64. available it is being printed on standart output.
  65. </para>
  66. <para>
  67. For a list of available commands, see <xref linkend="ctrl-channel"/>. Additional commands
  68. may be provided by hook libraries. If unsure which commands are supported, please use
  69. <command>list-commands</command> command. It will instruct CA to list all supported commands.
  70. </para>
  71. <para>Several examples of kea-shell usage are presented below. This example will expect
  72. parameters to be provided on standard input. Since list-commands does not take any
  73. arguments, ctrl-d may be pressed to indicate end of file. Kea shell will then contact
  74. CA and will print out a list of available commands.
  75. <screen>
  76. $ <userinput>kea-shell --host 192.0.2.1 --port 8001 list-commands</userinput>
  77. </screen>
  78. </para>
  79. <para>Kea shell is envisaged to be most frequently used in scripts. Here is an example of
  80. very simple scripted execution. It will issue command "config-write" with parameters
  81. specified in param.json. The result will be stored in result.json.
  82. <screen>
  83. $ cat param.json
  84. "filename": "my-config-file.json"
  85. $ <userinput>cat param.json | kea-shell --host 192.0.2.1 config-write > result.json</userinput>
  86. </screen>
  87. </para>
  88. <para>Kea shell requires python to run. It was tested with python 2.7 and various versions
  89. of python 3, up to 3.5. Since not every Kea deployment uses this feature and there are
  90. certainly deployments that do not have python, Kea shell is not enabled by default. To
  91. enable it, make sure you pass <command>--enable-shell</command> to configure script.</para>
  92. <para>Kea shell is intended to serve more a demonstration of the RESTful interface
  93. capabilities and perhaps an illustration for people interested in integrating their
  94. management evironments with Kea, rather than a serious management client. Do not expect it
  95. to be significantly expanded in the future. It is and will remain a simple tool.</para>
  96. </section>
  97. </chapter>