Improve cinder supported drivers output

Method list_supported_drivers was intended for human consumption, so all
values for the options in driver_options where strings, which makes it
harder to parse by automation tools since they have to:

- Convert values from 'None' to ``None``, 'False' to ``False``, etc.
- Parse a string with type of the option to determine the additional
  options, such as choices, max and min values.

This patch adds the possibility to get an output intended for automation
tools.

To maintain backward compatibility the method accepts
``output_version`` parameter that defaults to ``1`` (old output) but can get
``2`` for the new output.

Change-Id: I2ade5d2e6b2c97d905e09fee509c81c2cfb602ed
This commit is contained in:
Gorka Eguileor
2020-06-29 15:22:26 +02:00
parent 3a1ff321e8
commit a37a93154f
5 changed files with 167 additions and 39 deletions

View File

@@ -143,6 +143,15 @@ Available drivers for *cinderlib* depend on the Cinder version installed, so we
have a method, called `list_supported_drivers` to list information about the
drivers that are included with the Cinder release installed in the system.
The method accepts parameter ``output_version`` where we can specify the
desired output format:
- ``1`` for human usage (default value).
- ``2`` for automation tools.
The main difference are the values of the driver options and how the expected
type of these options is described.
.. code-block:: python
import cinderlib
@@ -158,11 +167,74 @@ Here's the entry for the LVM driver:
{'LVMVolumeDriver':
{'ci_wiki_name': 'Cinder_Jenkins',
'class_fqn': 'cinder.volume.drivers.lvm.LVMVolumeDriver',
'class_name': 'LVMVolumeDriver',
'desc': 'Executes commands relating to Volumes.',
'supported': True,
'version': '3.0.0'}}
'class_fqn': 'cinder.volume.drivers.lvm.LVMVolumeDriver',
'class_name': 'LVMVolumeDriver',
'desc': 'Executes commands relating to Volumes.',
'supported': True,
'version': '3.0.0',
'driver_options': [
{'advanced': 'False',
'default': '64',
'deprecated_for_removal': 'False',
'deprecated_opts': '[]',
'deprecated_reason': 'None',
'deprecated_since': 'None',
'dest': 'spdk_max_queue_depth',
'help': 'Queue depth for rdma transport.',
'metavar': 'None',
'mutable': 'False',
'name': 'spdk_max_queue_depth',
'positional': 'False',
'required': 'False',
'sample_default': 'None',
'secret': 'False',
'short': 'None',
'type': 'Integer(min=1, max=128)'},
],
}
},
The equivalent for the LVM driver for automation would be:
.. code-block::
import cinderlib
drivers = cinderlib.list_supported_drivers(2)
{'LVMVolumeDriver':
{'ci_wiki_name': 'Cinder_Jenkins',
'class_fqn': 'cinder.volume.drivers.lvm.LVMVolumeDriver',
'class_name': 'LVMVolumeDriver',
'desc': 'Executes commands relating to Volumes.',
'supported': True,
'version': '3.0.0',
'driver_options': [
{'advanced': False,
'default': 64,
'deprecated_for_removal': False,
'deprecated_opts': [],
'deprecated_reason': None,
'deprecated_since': None,
'dest': 'spdk_max_queue_depth',
'help': 'Queue depth for rdma transport.',
'metavar': None,
'mutable': False,
'name': 'spdk_max_queue_depth',
'positional': False,
'required': False,
'sample_default': None,
'secret': False,
'short': None,
'type': {'choices': None,
'max': 128,
'min': 1,
'num_type': <class 'int'>,
'type_class': Integer(min=1, max=128),
'type_name': 'integer value'}}
],
}
},
Stats
-----