vitrage-specs/specs/pike/datasource-skeleton-generator.rst
Yujun Zhang c9debfdf3b Move datasource skeleton generator to pike
- It won't be completed in ocata
- Move to pike to make ocata folder clean for release

Implement: blueprint datasource-skeleton-generator
Change-Id: I3bf315d16d5a96e1b64c21ea1afffd69c39fde85
2017-02-05 19:13:35 +08:00

3.3 KiB

Datasource Skeleton Generator

https://blueprints.launchpad.net/vitrage/+spec/datasource-skeleton-generator

A command line tool to generate skeleton of new datasource. A skeleton contains stubs of required classes and methods as described in the design specs, without detail implementation. It aims to bootstrapping the development of new datasource.

Problem description

The design specs has given detail instructions on how to add a new data source. However, there is much overhead to create it from scratch. Developers used to copy from existing datasource as a start. It is sometimes out of date and always contains many specific codes.

Proposed change

Create templates for the datasource skeleton with placeholders of names and render the Python source file on demand.

Example template in Jinja2:

from oslo_config import cfg
from vitrage.common.constants import UpdateMethod

{{ name|upper }}_DATASOURCE = '{{ name }}'

# define needed options
OPTS = [
    # Transformer with the path to your transformer classes
    cfg.StrOpt('transformer',
               default='vitrage.datasources.{{ name }}_datasource.transformer.'
                       '{{ name|capitalize }}Transformer',
               help='{{ name|capitalize }} transformer class path',
               required=True),

Providing name=foo, it will generate the skeleton source file in Python:

from oslo_config import cfg
from vitrage.common.constants import UpdateMethod

FOO_DATASOURCE = 'foo'

# define needed options
OPTS = [
    # Transformer with the path to your transformer classes
    cfg.StrOpt('transformer',
               default='vitrage.datasources.foo_datasource.transformer.'
                       'FooTransformer',
               help='Foo transformer class path',
               required=True),

Alternatives

Create and maintain a sample datasource to allow user to modify as base. In this way, developer is likely to miss some string replacement somewhere as we experienced in the abandoned patch set.

Data model impact

None

REST API impact

None

Versioning impact

None

Other end user impact

None

Deployer impact

None

Developer impact

None

Horizon impact

None

Implementation

Assignee(s)

Primary assignee:

yujunz

Other contributors:

None

Work Items

  • Create datasource skeleton template
    • driver
    • transformer
  • Create unit test skeleton template
    • test driver
    • test transformer
    • mock configuration
    • mock driver
    • trace generator
  • Templates for datasource with different update methods

Dependencies

None

Testing

The changes shall be covered by new unit test.

Documentation Impact

How to use the generator will be documented.

References