shell.xml 5.46 KB
Newer Older
1 2 3 4 5 6 7
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!ENTITY mdash  "&#x2017;" >
]>

<chapter id="kea-shell">
8
  <title>The Kea Shell</title>
9 10 11

  <section id="shell-overview">
    <title>Overview</title>
12
    <para>Kea 1.2.0 introduced the Control Agent (CA, see <xref linkend="kea-ctrl-agent"/>) that
13
    provides a RESTful control interface over HTTP. That API is typically expected to be used by
14 15 16 17
    various IPAMs and similar management systems. Nevertheless, there may be cases when you want
    to send a command to the CA directly.  The Kea Shell provides a way to do this.  It is a simple
    command-line, scripting-friendly text client that is able connect to the CA, send it commands
    with parameters, retrieve the responses and display them.</para>
18

19 20
    <para>As the primary purpose of the Kea Shell is as a tool in scripting environment,
    it is not interactive. However, with simple tricks it can be run manually.
21 22 23 24 25
    </para>
  </section>

  <section id="shell-usage">
    <title>Shell Usage</title>
26 27
    <para><command>kea-shell</command> is run as follows:
<screen>
28
kea-shell [--host hostname] [--port number] [--timeout seconds] [--service service-name] [command]
29 30
</screen>
    where:
31 32 33 34 35
    </para>
    <itemizedlist>
      <listitem>
        <simpara>
          <command>--host <replaceable>hostname</replaceable></command> specifies the hostname
36
          of the CA. If not specified, "localhost" is used.
37 38 39 40 41 42
        </simpara>
      </listitem>

      <listitem>
        <simpara>
          <command>--port <replaceable>number</replaceable></command> specifies the TCP port
43
          on which the CA listens. If not specified, 8000 is used.
44 45 46 47 48 49
        </simpara>
      </listitem>

      <listitem>
        <simpara>
          <command>--timeout <replaceable>seconds</replaceable></command> specifies the
50
          timeout (in seconds) for the connection. If not given, 10 seconds is used.
51 52 53
        </simpara>
      </listitem>

54 55
      <listitem>
        <simpara>
Josh Soref's avatar
Josh Soref committed
56
          <command>--service <replaceable>service-name</replaceable></command> specifies the
57 58
          target of a command. If not given, CA will be used as target.  May be used more
          than once to specify multiple targets.
59 60 61 62
        </simpara>
      </listitem>


63 64
      <listitem>
        <simpara>
65 66
          <command>command</command> specifies the command to be sent. If not specified,
          <command>list-commands</command> command is used.
67 68
        </simpara>
      </listitem>
69 70 71 72
    </itemizedlist>

    <para>Other switches are:</para>
    <itemizedlist>
73 74
      <listitem>
        <simpara>
75
          <command>-h</command> prints a help message.
76 77 78 79
        </simpara>
      </listitem>
      <listitem>
        <simpara>
80
          <command>-v</command> prints the software version.
81 82 83 84 85
        </simpara>
      </listitem>
    </itemizedlist>

    <para>
86 87 88 89
      Once started, the shell reads parameters for the command from standard input, which are
      expected to be in JSON format. When all have been read, the shell establishes a connection
      with the CA using HTTP, sends the command and awaits a response. Once that is received,
      it is printed on standard output.
90 91 92 93
    </para>

    <para>
      For a list of available commands, see <xref linkend="ctrl-channel"/>. Additional commands
94 95 96
      may be provided by hook libraries. If unsure which commands are supported, use the
      <command>list-commands</command> command. It will instruct the CA to return a list of
      all supported commands.
97 98
    </para>

99
    <para>The following shows a simple example of usage:
100
<screen>
101
$ <userinput>kea-shell --host 192.0.2.1 --port 8001 --service dhcp4 list-commands</userinput>
102
^D
103
</screen>
104 105 106 107
    After the command line is entered, the program waits for command parameters to be entered.
    Since <command>list-commands</command> does not take any
    arguments, CTRL-D (represented in the above example by "^D") is pressed to indicate end
    of file (and so terminate the parameter input). The Shell will then contact
108
    the CA and print out the list of available commands returned for the service named <command>dhcp4</command>.
109 110
    </para>

111
    <para>It is envisaged that Kea Shell will be most frequently used in scripts. The next example
112 113
    shows a simple scripted execution. It sends the command "config-write" to the CA
    (<command> --service </command> parameter hasn't been used), along
114
    with the parameters specified in param.json. The result will be stored in result.json.
115 116 117 118 119 120 121
<screen>
$ cat param.json
"filename": "my-config-file.json"
$ <userinput>cat param.json | kea-shell --host 192.0.2.1 config-write > result.json</userinput>
</screen>
    </para>

122 123 124 125 126 127
    <para>Kea Shell requires Python to to be installed on the system. It was tested with
    Python 2.7 and various versions
    of Python 3, up to 3.5. Since not every Kea deployment uses this feature and there are
    deployments that do not have Python, the Kea Shell is not enabled by default. To use it,
    you must specify <command>--enable-shell</command> to when running "configure" during the
    installation of Kea.</para>
128

129 130 131 132 133
    <para>The Kea Shell is intended to serve more as a demonstration of the RESTful interface
    capabilities (and, perhaps, an illustration for people interested in integrating their
    management evironments with Kea) than as a serious management client. Do not expect it
    to be significantly expanded in the future. It is, and will remain, a simple tool.</para>
    </section>
134
</chapter>