2020-04-24 07:23:52 +00:00
|
|
|
#! /usr/bin/env python3
|
2015-06-17 15:57:34 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
Keep consistent of naming convention
In the project, some of the terminology, like URL, URLs, API, APIs, OpenStack,
UUID, Cinder are neglectfully written as url, api, openstack, uuid, cinder.
This patch is to keep consistent of naming convention.
Change-Id: I98777fb4748cbc58b6e2fd1aca058d3e44069d07
2017-07-10 02:46:44 +00:00
|
|
|
"""Generate list of Cinder drivers"""
|
2015-06-17 15:57:34 +00:00
|
|
|
|
2016-07-27 12:04:58 +00:00
|
|
|
import argparse
|
2019-02-06 19:50:42 +00:00
|
|
|
import operator
|
2016-07-15 11:15:54 +00:00
|
|
|
import os
|
2017-02-10 18:17:41 +00:00
|
|
|
import json
|
2018-04-25 22:15:23 +00:00
|
|
|
import textwrap
|
2016-07-15 11:15:54 +00:00
|
|
|
|
2016-03-23 21:39:07 +00:00
|
|
|
from cinder.interface import util
|
2017-01-16 23:17:48 +00:00
|
|
|
from cinder import objects
|
|
|
|
|
|
|
|
|
|
|
|
# Object loading can cause issues loading drivers, force it up front
|
|
|
|
objects.register_all()
|
2016-03-23 21:39:07 +00:00
|
|
|
|
|
|
|
|
2016-07-27 12:04:58 +00:00
|
|
|
parser = argparse.ArgumentParser(prog="generate_driver_list")
|
|
|
|
|
|
|
|
parser.add_argument("--format", default='str', choices=['str', 'dict'],
|
|
|
|
help="Output format type")
|
|
|
|
|
|
|
|
# Keep backwards compatibilty with the gate-docs test
|
|
|
|
# The tests pass ['docs'] on the cmdln, but it's never been used.
|
|
|
|
parser.add_argument("output_list", default=None, nargs='?')
|
|
|
|
|
2016-08-11 10:18:09 +00:00
|
|
|
CI_WIKI_ROOT = "https://wiki.openstack.org/wiki/ThirdPartySystems/"
|
|
|
|
|
2016-07-27 12:04:58 +00:00
|
|
|
|
2016-07-23 17:13:34 +00:00
|
|
|
class Output(object):
|
|
|
|
|
2016-07-27 12:04:58 +00:00
|
|
|
def __init__(self, base_dir, output_list):
|
2016-07-23 17:13:34 +00:00
|
|
|
# At this point we don't care what was passed in, just a trigger
|
|
|
|
# to write this out to the doc tree for now
|
|
|
|
self.driver_file = None
|
2016-07-27 12:04:58 +00:00
|
|
|
if output_list:
|
2016-07-23 17:13:34 +00:00
|
|
|
self.driver_file = open(
|
|
|
|
'%s/doc/source/drivers.rst' % base_dir, 'w+')
|
|
|
|
self.driver_file.write('===================\n')
|
|
|
|
self.driver_file.write('Available Drivers\n')
|
|
|
|
self.driver_file.write('===================\n\n')
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback):
|
2016-08-02 13:56:57 +00:00
|
|
|
if self.driver_file:
|
|
|
|
self.driver_file.close()
|
2016-07-23 17:13:34 +00:00
|
|
|
|
|
|
|
def write(self, text):
|
|
|
|
if self.driver_file:
|
|
|
|
self.driver_file.write('%s\n' % text)
|
|
|
|
else:
|
|
|
|
print(text)
|
|
|
|
|
|
|
|
|
|
|
|
def format_description(desc, output):
|
2016-03-23 21:39:07 +00:00
|
|
|
desc = desc or '<None>'
|
|
|
|
lines = desc.rstrip('\n').split('\n')
|
2018-04-25 22:15:23 +00:00
|
|
|
output.write('* Description: %s' % lines[0])
|
|
|
|
output.write('')
|
|
|
|
output.write(textwrap.dedent('\n'.join(lines[1:])))
|
2016-03-23 21:39:07 +00:00
|
|
|
|
2019-02-06 19:50:42 +00:00
|
|
|
|
|
|
|
def format_options(driver_options, output):
|
|
|
|
if driver_options and len(driver_options) > 0:
|
|
|
|
|
|
|
|
output.write('* Driver Configuration Options:')
|
|
|
|
output.write('')
|
|
|
|
output.write('.. list-table:: **Driver configuration options**')
|
|
|
|
output.write(' :header-rows: 1')
|
|
|
|
output.write(' :widths: 14 30')
|
|
|
|
output.write('')
|
|
|
|
output.write(' * - Name = Default Value')
|
|
|
|
output.write(' - (Type) Description')
|
|
|
|
sorted_options = sorted(driver_options,
|
|
|
|
key=operator.attrgetter('name'))
|
|
|
|
for opt in sorted_options:
|
|
|
|
output.write(' * - %s = %s' %
|
|
|
|
(opt.name, opt.default))
|
|
|
|
output.write(' - (%s) %s' % (opt.type, opt.help))
|
|
|
|
output.write('')
|
|
|
|
|
|
|
|
def filter_drivers(drivers):
|
|
|
|
'''This filters all of the drivers into separate lists.'''
|
|
|
|
|
|
|
|
supported_drivers = []
|
|
|
|
unsupported_drivers = []
|
|
|
|
|
|
|
|
for driver in drivers:
|
2016-11-16 12:29:12 +00:00
|
|
|
if not driver.supported:
|
2019-02-06 19:50:42 +00:00
|
|
|
unsupported_drivers.append(driver)
|
|
|
|
else:
|
|
|
|
supported_drivers.append(driver)
|
|
|
|
|
|
|
|
return supported_drivers, unsupported_drivers
|
|
|
|
|
|
|
|
|
|
|
|
def print_drivers(drivers, config_name, output, section_char='-',
|
|
|
|
display_unsupported=True):
|
|
|
|
for driver in sorted(drivers, key=lambda x: x.class_name):
|
|
|
|
driver_name = driver.class_name
|
|
|
|
if not driver.supported and display_unsupported:
|
2016-11-16 12:29:12 +00:00
|
|
|
driver_name += " (unsupported)"
|
|
|
|
output.write(driver_name)
|
2019-02-06 19:50:42 +00:00
|
|
|
output.write(section_char * len(driver_name))
|
2016-03-23 21:39:07 +00:00
|
|
|
if driver.version:
|
2016-07-23 17:13:34 +00:00
|
|
|
output.write('* Version: %s' % driver.version)
|
|
|
|
output.write('* %s=%s' % (config_name, driver.class_fqn))
|
2017-01-06 19:52:38 +00:00
|
|
|
if driver.ci_wiki_name and 'Cinder_Jenkins' not in driver.ci_wiki_name:
|
2016-08-11 10:18:09 +00:00
|
|
|
output.write('* CI info: %s%s' % (CI_WIKI_ROOT,
|
|
|
|
driver.ci_wiki_name))
|
2019-02-06 19:50:42 +00:00
|
|
|
format_options(driver.driver_options, output)
|
2016-07-23 17:13:34 +00:00
|
|
|
format_description(driver.desc, output)
|
|
|
|
output.write('')
|
|
|
|
output.write('')
|
2015-06-17 15:57:34 +00:00
|
|
|
|
|
|
|
|
2016-07-27 12:04:58 +00:00
|
|
|
def output_str(cinder_root, args):
|
|
|
|
with Output(cinder_root, args.output_list) as output:
|
|
|
|
output.write('Volume Drivers')
|
|
|
|
output.write('==============')
|
2019-02-06 19:50:42 +00:00
|
|
|
supported_drivers, unsupported_drivers = filter_drivers(
|
|
|
|
util.get_volume_drivers())
|
|
|
|
|
|
|
|
output.write('Supported Drivers')
|
|
|
|
output.write('-----------------')
|
|
|
|
output.write('')
|
|
|
|
print_drivers(supported_drivers, 'volume_driver', output, '~')
|
|
|
|
|
|
|
|
output.write('Unsupported Drivers')
|
|
|
|
output.write('-------------------')
|
|
|
|
output.write('')
|
|
|
|
print_drivers(unsupported_drivers, 'volume_driver', output, '~')
|
2016-07-27 12:04:58 +00:00
|
|
|
|
|
|
|
output.write('Backup Drivers')
|
|
|
|
output.write('==============')
|
|
|
|
print_drivers(util.get_backup_drivers(), 'backup_driver', output)
|
|
|
|
|
|
|
|
output.write('FC Zone Manager Drivers')
|
|
|
|
output.write('=======================')
|
|
|
|
print_drivers(util.get_fczm_drivers(), 'zone_driver', output)
|
|
|
|
|
|
|
|
|
|
|
|
def collect_driver_info(driver):
|
|
|
|
"""Build the dictionary that describes this driver."""
|
|
|
|
|
|
|
|
info = {'name': driver.class_name,
|
|
|
|
'version': driver.version,
|
|
|
|
'fqn': driver.class_fqn,
|
|
|
|
'description': driver.desc,
|
2017-01-24 11:18:14 +00:00
|
|
|
'ci_wiki_name': driver.ci_wiki_name,
|
2019-02-06 19:50:42 +00:00
|
|
|
'supported': driver.supported,
|
|
|
|
'options': driver.driver_options,
|
|
|
|
}
|
2016-07-27 12:04:58 +00:00
|
|
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
def output_dict():
|
Keep consistent of naming convention
In the project, some of the terminology, like URL, URLs, API, APIs, OpenStack,
UUID, Cinder are neglectfully written as url, api, openstack, uuid, cinder.
This patch is to keep consistent of naming convention.
Change-Id: I98777fb4748cbc58b6e2fd1aca058d3e44069d07
2017-07-10 02:46:44 +00:00
|
|
|
"""Output the results as a JSON dict."""
|
2016-07-27 12:04:58 +00:00
|
|
|
|
|
|
|
driver_list = []
|
|
|
|
drivers = util.get_volume_drivers()
|
|
|
|
for driver in drivers:
|
|
|
|
driver_list.append(collect_driver_info(driver))
|
|
|
|
|
2017-02-10 18:17:41 +00:00
|
|
|
print(json.dumps(driver_list))
|
2016-07-27 12:04:58 +00:00
|
|
|
|
|
|
|
|
2015-06-17 15:57:34 +00:00
|
|
|
def main():
|
2016-07-15 11:15:54 +00:00
|
|
|
tools_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
cinder_root = os.path.dirname(tools_dir)
|
|
|
|
cur_dir = os.getcwd()
|
|
|
|
os.chdir(cinder_root)
|
2016-07-27 12:04:58 +00:00
|
|
|
args = parser.parse_args()
|
2016-03-23 21:39:07 +00:00
|
|
|
|
2016-07-15 11:15:54 +00:00
|
|
|
try:
|
2016-07-27 12:04:58 +00:00
|
|
|
if args.format == 'str':
|
|
|
|
output_str(cinder_root, args)
|
|
|
|
elif args.format == 'dict':
|
|
|
|
output_dict()
|
|
|
|
|
2016-07-15 11:15:54 +00:00
|
|
|
finally:
|
|
|
|
os.chdir(cur_dir)
|
2015-06-17 15:57:34 +00:00
|
|
|
|
2016-11-17 02:10:36 +00:00
|
|
|
|
2015-06-17 15:57:34 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|