Skip to content

Commit

Permalink
Fix issues # 337 and # 338 Modify command handling to use general opt…
Browse files Browse the repository at this point in the history
…ions.

Modified the structure to allow use of the general options within an
interactive session.

1. Removed some of the properties (timestats, use_pull, pull_max_cnt,
log, verbose) from PywbemServer class. These are maintained only in the
context and therefore, when set, they apply to all commands, not any
particular pywbem server. They were always accessed from the context
rather than the server so should never have been in the server.

2. Added property setters to PywbemServer class so can individually
set properties.

3. Modified no_verify option. Modified no-verify option to allow 3 values
 (None, True, False). This allows the code to determine if the
option was defined.

4. Reorganized pywbemcli.py slightly to do function cli input argument
processing on all calls, startup and command calls. This produces
resolve_... versions of each of the input arguments so that the code
can determine if the argument was actually input or the default was set.

5. Changed the name of the no_verify option to verify because the order
of processing in the click option that handles '--a/--no_a' is such that
we would have either had to define it as '--no-a/--a' or invert the
argument in processing. Besides this actually seems more logical instead
of the double negative (i.e. is no-verify True or false). Note that the
alternative would have been to make it a choice argument (choice
("true", "false"). We had to do something so that we could determine if
the argument was input or not and the is-flag does not do that.

6. Remove the block on overwrite of connection definitions with
'connection save'.
  • Loading branch information
KSchopmeyer committed Sep 14, 2019
1 parent be049b4 commit bbe4798
Show file tree
Hide file tree
Showing 11 changed files with 724 additions and 455 deletions.
16 changes: 16 additions & 0 deletions docs/appendix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ This documentation uses a few special terms to refer to Python types:
backslash-escaping any double quotes in INSTANCENAME, and putting it into
double quotes.

default connection
A connection definition in the :ref:`--server general option` that is used
by pywbemcli as the :term:`current connection` if pywbemcli is started without
any connection definition (no :ref:`--server general option`,
:ref:`--mock-server general option`, or :ref:`--name general option`).
A connection definition in the :term:`connections file` becomes the
current connection on pywbemcli startup if it is defined using the
:ref:`connection select command`.

current connection
The connection definition in pywbemcli that is currently active; the
target WBEM server for pywbemcli commands. The current server is defined
either upon startup (:ref:`--server general option`,
:ref:`--mock-server general option`, or :ref:`--name general option` or
:term:`default connection`) or with the :ref:`connection select command`.


.. _`Profile advertisement methodologies`:

Expand Down
34 changes: 20 additions & 14 deletions docs/pywbemclicmdshelp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ The following defines the help output for the `pywbemcli --help` command
-p, --password TEXT Password for the WBEM server. Default:
EnvVar PYWBEMCLI_PASSWORD, or prompted for
if --user specified.
-N, --no-verify If true, client does not verify the X.509
--verify / --no-verify If --verify, client verifies the X.509
server certificate presented by the WBEM
server during TLS/SSL handshake. Default:
EnvVar PYWBEMCLI_NO_VERIFY, or false.
server during TLS/SSL handshake. If --no-
verify client bypasses verificationDefault:
EnvVar PYWBEMCLI_VERIFY, or --verify.
--ca-certs FILE Path name of a file or directory containing
certificates that will be matched against
the server certificate presented by the WBEM
Expand Down Expand Up @@ -779,9 +780,14 @@ The following defines the help output for the `pywbemcli connection save --help`

Save the current connection to a new WBEM connection definition.

Create a new WBEM connection definition in the connections file from the
current connection. A connection definition with the name NAME must not
yet exist. The NAME argument (the name of the new connection) is required.
Save WBEM connection definition in the connections file from the current
connection. The NAME argument (the name of the new connection) is
required. If the connection exists, it will be overwritten with the
current connection definition.

In the interactive mode, general options preceeding the connection command
that change the connection definition will be applied before the
connection is saved.

Examples:

Expand Down Expand Up @@ -810,15 +816,15 @@ The following defines the help output for the `pywbemcli connection select --hel

Select a WBEM connection definition as current or default.

Selects a connection from the persistently stored named connections if
NAME exists in the store to be the current connection. If the NAME
argument does not exist, a list of connections from the connections
definition file is presented with a prompt for the user to select a
connection.
Selects the connection named NAME from the persistently stored named
connectionsto be the current connection if NAME exists in the store . If
the NAME argument does not exist, a list of connections from the
connections definition file is presented with a prompt for the user to
select a connection.

Default and current connction are set if the --default option exists;
otherwise only the connection in the current interactive session is set .
Once define the default connection will be used as the server definition
Default and current connection are set if the --default option exists;
otherwise only the current connection the interactive session is set .
Once defined the default connection will be used as the server definition
in future execution of pywbemcli if there is no server definition
(--server or --name or --mock-server) general option.

Expand Down
85 changes: 68 additions & 17 deletions docs/pywbemclicommands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,7 @@ options for pywbemcli. The data includes:
received from the WBEM server during connection setup. See :ref:`--no-verify general option`.
* **certfile** - optional server certificate filename. See :ref:`--certfile general option`.
* **keyfile** - optional client private keyfile filename. See :ref:`--keyfile general option`.
* **use-pull** - optional parameter that defines whether pull operations are
to be required, used if they exist or not used. See :ref:`--use-pull general option`.
* **pull-max-cnt** - optional count of object per pull operation. See :ref:`--pull-max-cnt general option`.
* **timeout** - optional timeout value. See :ref:`--timeout general option`.
* **timestats** - boolean that determines if time stats are captured. See :ref:`--timestats general option`.
* **log** - optional log configuration. See :ref:`--log general option`.
* **verbose** - optional boolean that enables the verbose mode.
* **output-format** - optional output format.
* **mock-server** - optional definition a mock server
environment using the pywbem mock module. This parameter is used, the
``--server`` must not be defined. See :ref:`--mock-server general option`.
Expand All @@ -1009,6 +1002,7 @@ The commands in this group are:
* :ref:`Connection test command` - Test the current connection with a
predefined WBEM request.


.. _`Connection delete command`:

Connection delete command
Expand Down Expand Up @@ -1111,13 +1105,19 @@ Connection select command
^^^^^^^^^^^^^^^^^^^^^^^^^

The ``connection select`` command selects a connection from the connections
file and marks that connection as the default connection. The default
connection will be used if it is defined and pywbemcli is started with no
:ref:`--server general option` or :ref:`--mock-server general option` general options. A connection may be
selected to be default either by using the NAMEargument or if no argument is
provided by selecting from a list presented on the console. The following
example shows changing connection from within the interactive mode of
pywbemcli:
file sets that connection as the :ref:`current connection` and optionally the
:ref:`default connection` (``--default option``).

A connection may be selected
to be the current connection by using the NAME argument or by selecting from a
list presented on the console if there is no NAME argument.

In the interactive mode, the selected connection remains the current connection
for the remainder of the interactive session unless another connection is selected.


The following example shows changing connection from within the interactive
mode of pywbemcli:

.. code-block:: text
Expand Down Expand Up @@ -1154,15 +1154,66 @@ pywbemcli:
log: None
This feature can be used to modify parameters of a connection beyond the scope of the
current connection using the general options. Setting connection parameters using
general options with the select command causes the changes to become the new current
connection definition.

For example:


.. code-block:: text
$ pywbemcl --server http://localhost
pywbemcli> connection list
WBEM server connections: (#: default, *: current)
+------------+-------------+-------------+--------+-----------+----------+
| name | server | namespace | user | timeout | verify |
|------------+-------------+-------------+--------+-----------+----------|
| *not-saved | http://blah | root/cimv2 | | 30 | True |
+------------+-------------+-------------+--------+-----------+----------+
pywbemcli> --user fred --password 234 connection select
pywbemcli> connection list
WBEM server connections: (#: default, *: current)
+------------+-------------+-------------+--------+-----------+----------+
| name | server | namespace | user | timeout | verify |
|------------+-------------+-------------+--------+-----------+----------|
| *not-saved | http://blah | root/cimv2 | Ron | 30 | True |
+------------+-------------+-------------+--------+-----------+----------+
TODO: this feature not done.
See :ref:`pywbemcli connection select --help` for details.


.. _`Connection show command`:

Connection show command
^^^^^^^^^^^^^^^^^^^^^^^^^
The ``connection show`` command shows information in the current connection. See the the ``select``
above for an example of this command.
^^^^^^^^^^^^^^^^^^^^^^^
The ``connection show`` command shows information about the current connection or the
connection with name NAME. The connection to be displayed will be
the :ref:`current connection` if the NAME argument is omitted, the connection named
with the NAME argument, or selected from a selection list the NAME argument "?"

pywbemcli> connection show

.. code-block:: text
name: not-saved (current)
server: http://blah
default-namespace: root/cimv2
user: None
password: None
timeout: 30
verify: True
certfile: None
keyfile: None
mock-server:
ca-certs: None
pywbemcli>
See :ref:`pywbemcli connection show --help` for details.

Expand Down
30 changes: 21 additions & 9 deletions docs/pywbemcligeneraloptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ interactive mode and as a table:
command, general the options redefinition's are not retained between command
executions.

The general options may be used in the interactive mode to override
the default general options or specific general options for the current command.

Thus, behavior of pywbemcli (ex. :ref:`--output-format`) or the parameters of the
current connection (:ref:`--server general option`) can be changed for the
execution of a single command in the interactive mode.


.. _`Defining the WBEM Server`:

Expand All @@ -94,7 +101,7 @@ the following arguments :
* The :ref:`--user general option`, defines the WBEM server user name
* The :ref:`--password general option`, defining the password for the WBEM
server user
* The :ref:`--no-verify general option` that defines whether the client verifies
* The :ref:`--verify general option` that defines whether the client verifies
certificates received from the WBEM server,
* The :ref:`--certfile general option`, client certificate file,
* The :ref:`--keyfile general option`, client key file,
Expand Down Expand Up @@ -368,14 +375,19 @@ server in the time defined by this value. Pywbemcli defaults to a
predefined timeout (normally 30 seconds) if this option is not defined.


.. _`--no-verify general option`:
.. _`--verify general option`:

--no-verify general option
^^^^^^^^^^^^^^^^^^^^^^^^^^
--verify general option
^^^^^^^^^^^^^^^^^^^^^^^

If the ``--verify\--no-verify`` general option is set ``--no-verify``, the client does not
verify any certificates received from the WBEM server. If --verify is defined, certificates
returned from the server are verified. Any certificate returned
by the WBEM server is accepted. The default is to verify certificates returned.

If the ``--no-verify/-n`` boolean general option is set, the client does not
verify any certificates received from the WBEM server. Any certificate returned
by the WBEM server is accepted.
This general option uses this approach with two long option names to allow the
user to specifically enable or disable certificate verification when this
general option is used in interactive mode.


.. _`--certfile general option`:
Expand Down Expand Up @@ -420,7 +432,7 @@ received from the WBEM server. The default is OS dependent and is a set of
system directories where certificates are expected to be stored for the client
OS.

Setting the :ref:`--no-verify general option` bypasses client verification of
Setting the :ref:`--verify general option` to ``--no-verify`` bypasses client verification of
the WBEM server certificate.


Expand Down Expand Up @@ -1091,7 +1103,7 @@ new connection in the CLI command mode:
user: usr1
password: blah
timeout: None
no-verify: False
verify: True
certfile: None
keyfile: None
use-pull: None
Expand Down
Loading

0 comments on commit bbe4798

Please sign in to comment.