Generate api-ref redirects for service type aliases

We track official service type names and their historical aliases. As
api-ref is organized by service-type, it stands to reason that if a
service-type changes (or has changed) that a link might exist to the old
value.

Use the service types authority data to generate a set of redirects for
all aliases of a service to the official service type location.

Change-Id: I96a5502ca6cd3e78f996ad9b60101c907e2150cd
This commit is contained in:
Monty Taylor 2017-08-18 09:37:21 -05:00 committed by Andreas Jaeger
parent 3a85f163cb
commit 7d9497a373
3 changed files with 27 additions and 4 deletions

View File

@ -14,5 +14,8 @@ openstackdocstheme>=1.16.0 # Apache-2.0
nwdiag
sphinxcontrib-nwdiag
requests
os-service-types
# For translations
Babel>=2.3.4,!=2.4.0 # BSD

View File

@ -20,6 +20,8 @@ import sys
import lxml.html
from lxml import etree
import jinja2
import os_service_types
import requests
def initialize_logging(debug, verbose):
@ -67,8 +69,16 @@ def main():
logger.error("initialising template environment failed: %s" % e)
return 1
try:
service_types = os_service_types.ServiceTypes(
session=requests.Session(), only_remote=True)
except Exception as e:
logger.error("initialising service types data failed: %s" % e)
return 1
for templateFile in environment.list_templates():
if not templateFile.endswith('.html'):
if not (templateFile.endswith('.html')
or templateFile.endswith('.htaccess')):
continue
logger.info("generating %s" % templateFile)
@ -80,10 +90,14 @@ def main():
(templateFile, e))
continue
try:
output = lxml.html.tostring(
lxml.html.fromstring(template.render()),
pretty_print=True)
if templateFile.endswith('.html'):
output = lxml.html.tostring(
lxml.html.fromstring(template.render()),
pretty_print=True)
else:
output = template.render(REVERSE=service_types.reverse)
except Exception as e:
logger.error("rendering template %s failed: %s" %
(templateFile, e))

View File

@ -60,3 +60,9 @@ redirect 301 /api-ref-share-v2.html /api-ref/shared-file-system/index.html
redirect 301 /api-ref-share-v1.html /api-ref/shared-file-system/index.html
# Redirect Telemetry (ceilometer only) API
redirect 301 /api-ref-telemetry-v2.html https://docs.openstack.org/ceilometer/latest/webapi/v2.html
# Redirect service-type aliases to service-type api-ref locations
{% for alias, service_type in REVERSE.items() -%}
redirectmatch 301 /api-ref/{{ alias }}/(.*) /api-ref/{{ service_type }}/$1
{% endfor %}