shell.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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] [--service service-name] [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>--service <replaceable>serive-name</replaceable></command> specifies the
  50. target of a command. If not given, CA will be used as target. May be used more
  51. than once to specify multiple targets.
  52. </simpara>
  53. </listitem>
  54. <listitem>
  55. <simpara>
  56. <command>command</command> specifies the command to be sent. If not specified,
  57. <command>list-commands</command> command is used.
  58. </simpara>
  59. </listitem>
  60. </itemizedlist>
  61. <para>Other switches are:</para>
  62. <itemizedlist>
  63. <listitem>
  64. <simpara>
  65. <command>-h</command> prints a help message.
  66. </simpara>
  67. </listitem>
  68. <listitem>
  69. <simpara>
  70. <command>-v</command> prints the software version.
  71. </simpara>
  72. </listitem>
  73. </itemizedlist>
  74. <para>
  75. Once started, the shell reads parameters for the command from standard input, which are
  76. expected to be in JSON format. When all have been read, the shell establishes a connection
  77. with the CA using HTTP, sends the command and awaits a response. Once that is received,
  78. it is printed on standard output.
  79. </para>
  80. <para>
  81. For a list of available commands, see <xref linkend="ctrl-channel"/>. Additional commands
  82. may be provided by hook libraries. If unsure which commands are supported, use the
  83. <command>list-commands</command> command. It will instruct the CA to return a list of
  84. all supported commands.
  85. </para>
  86. <para>The following shows a simple example of usage:
  87. <screen>
  88. $ <userinput>kea-shell --host 192.0.2.1 --port 8001 --service dhcp4 list-commands</userinput>
  89. ^D
  90. </screen>
  91. After the command line is entered, the program waits for command parameters to be entered.
  92. Since <command>list-commands</command> does not take any
  93. arguments, CTRL-D (represented in the above example by "^D") is pressed to indicate end
  94. of file (and so terminate the parameter input). The Shell will then contact
  95. the CA and print out the list of available commands returned for the service named <command>dhcp4</command>.
  96. </para>
  97. <para>It is envisaged that Kea Shell will be most frequently used in scripts. The next example
  98. shows a simple scripted execution. It sends the command "config-write" to the CA
  99. (<command> --service </command> parameter hasn't been used), along
  100. with the parameters specified in param.json. The result will be stored in result.json.
  101. <screen>
  102. $ cat param.json
  103. "filename": "my-config-file.json"
  104. $ <userinput>cat param.json | kea-shell --host 192.0.2.1 config-write > result.json</userinput>
  105. </screen>
  106. </para>
  107. <para>Kea Shell requires Python to to be installed on the system. It was tested with
  108. Python 2.7 and various versions
  109. of Python 3, up to 3.5. Since not every Kea deployment uses this feature and there are
  110. deployments that do not have Python, the Kea Shell is not enabled by default. To use it,
  111. you must specify <command>--enable-shell</command> to when running "configure" during the
  112. installation of Kea.</para>
  113. <para>The Kea Shell is intended to serve more as a demonstration of the RESTful interface
  114. capabilities (and, perhaps, an illustration for people interested in integrating their
  115. management evironments with Kea) than as a serious management client. Do not expect it
  116. to be significantly expanded in the future. It is, and will remain, a simple tool.</para>
  117. </section>
  118. </chapter>