shell.xml 6.2 KB

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