shell.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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>The Kea Shell</title>
  8. <section id="shell-overview">
  9. <title>Overview</title>
  10. <para>Kea 1.2.0 introduced the Control Agent (CA, 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 may be cases when you want
  13. to send a command to the CA directly. The Kea Shell provides a way to do this. It is a simple
  14. command-line, scripting-friendly text client that is able connect to the CA, send it commands
  15. with parameters, retrieve the responses and display them.</para>
  16. <para>As the primary purpose of the Kea Shell is as a tool in scripting environment,
  17. it 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><command>kea-shell</command> is run as follows:
  23. <screen>
  24. kea-shell [--host hostname] [--port number] [--timeout seconds] [command]
  25. </screen>
  26. where:
  27. </para>
  28. <itemizedlist>
  29. <listitem>
  30. <simpara>
  31. <command>--host <replaceable>hostname</replaceable></command> specifies the hostname
  32. of the CA. If not specified, "localhost" is used.
  33. </simpara>
  34. </listitem>
  35. <listitem>
  36. <simpara>
  37. <command>--port <replaceable>number</replaceable></command> specifies the TCP port
  38. on which the CA listens. If not specified, 8000 is used.
  39. </simpara>
  40. </listitem>
  41. <listitem>
  42. <simpara>
  43. <command>--timeout <replaceable>seconds</replaceable></command> specifies the
  44. timeout (in seconds) for the connection. If not given, 10 seconds is used.
  45. </simpara>
  46. </listitem>
  47. <listitem>
  48. <simpara>
  49. <command>command</command> specifies the command to be sent. If not specified,
  50. <command>list-commands</command> command is used.
  51. </simpara>
  52. </listitem>
  53. </itemizedlist>
  54. <para>Other switches are:</para>
  55. <itemizedlist>
  56. <listitem>
  57. <simpara>
  58. <command>-h</command> prints a help message.
  59. </simpara>
  60. </listitem>
  61. <listitem>
  62. <simpara>
  63. <command>-v</command> prints the software version.
  64. </simpara>
  65. </listitem>
  66. </itemizedlist>
  67. <para>
  68. Once started, the shell reads parameters for the command from standard input, which are
  69. expected to be in JSON format. When all have been read, the shell establishes a connection
  70. with the CA using HTTP, sends the command and awaits a response. Once that is received,
  71. it is printed on standard output.
  72. </para>
  73. <para>
  74. For a list of available commands, see <xref linkend="ctrl-channel"/>. Additional commands
  75. may be provided by hook libraries. If unsure which commands are supported, use the
  76. <command>list-commands</command> command. It will instruct the CA to return a list of
  77. all supported commands.
  78. </para>
  79. <para>The following shows a simple example of usage:
  80. <screen>
  81. $ <userinput>kea-shell --host 192.0.2.1 --port 8001 list-commands</userinput>
  82. ^D
  83. </screen>
  84. After the command line is entered, the program waits for command parameters to be entered.
  85. Since <command>list-commands</command> does not take any
  86. arguments, CTRL-D (represented in the above example by "^D") is pressed to indicate end
  87. of file (and so terminate the parameter input). The Shell will then contact
  88. the CA and print out the list of available commands returned.
  89. </para>
  90. <para>It is envisaged that Kea Shell will be most frequently used in scripts. The next example
  91. shows a simple scripted execution. It sends the command "config-write" to the CA, along
  92. with the parameters specified in param.json. The result will be stored in result.json.
  93. <screen>
  94. $ cat param.json
  95. "filename": "my-config-file.json"
  96. $ <userinput>cat param.json | kea-shell --host 192.0.2.1 config-write > result.json</userinput>
  97. </screen>
  98. </para>
  99. <para>Kea Shell requires Python to to be installed on the system. It was tested with
  100. Python 2.7 and various versions
  101. of Python 3, up to 3.5. Since not every Kea deployment uses this feature and there are
  102. deployments that do not have Python, the Kea Shell is not enabled by default. To use it,
  103. you must specify <command>--enable-shell</command> to when running "configure" during the
  104. installation of Kea.</para>
  105. <para>The Kea Shell is intended to serve more as a demonstration of the RESTful interface
  106. capabilities (and, perhaps, an illustration for people interested in integrating their
  107. management evironments with Kea) than as a serious management client. Do not expect it
  108. to be significantly expanded in the future. It is, and will remain, a simple tool.</para>
  109. </section>
  110. </chapter>