Change-Id: Ic6902b9706786ad5f7137d9ba8652186b917f56a Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
10 KiB
Add New Datasource
Add Datasource Package - HOW TO
In order to add a new datasource to Vitrage do the following steps:
- Have your datasource enclosed in a package with the datasources' name and put it under 'vitrage.datasources', For example: vitrage.datasource.cinder.volume.
- Under your datasource package, have both your datasources' driver class and your datasources' transformer class. See below for details on those classes.
- Under your datasources' package __init__.py you must import cfg from oslo_config and declare a list named OPTS. Under OPTS, you can define your needed options using the oslo_config.cfg module. There are three options you must have:
- Driver and transformer with the path to your driver and transformer classes respectively.
- update_method property that describes the type of update mechanism for this datasource. The options are: push, pull or none.
- In addition to those three, you may add any other configuration options you may need for your datasource.
- In case you want your datasource to get registered under other names i.e. for other sub-entities, add a list option named 'entities' under which list all of your sub-entities names (more details below).
- In case you want your datasource to be automatically configured when devstack is installed, you need to add it to the 'types' property in the datasources section in the configuration. To do so, do the following:
add the datasource name to the types property in the "devstack.settings" file.
if the datasource is not one of the main and basic projects of devstack, add the following data in the "devstack.plugin.sh" file":
# remove <datasource_name> vitrage datasource if <datasource_name> datasource not installed
if ! is_service_enabled <datasource_name>; then
disable_vitrage_datasource <datasource_name>
fi
- You are done!
Driver Class
Responsible for importing information regarding entities in the cloud. Entities in this context refer both to resources (physical, virtual, applicative) and alarms (Aodh, Nagios, Zabbix, Monasca, etc.) The datasource has two modes of action:
- get_all (snapshot): Query all entities and send events to the vitrage events queue. When done for the first time, send an "end" event to inform it has finished the get_all for the datasource (because it is done asynchronously).
- notify: Send an event to the vitrage events queue upon any change. This can be done in two ways:
- Built in polling mechanism called get_changes.
- Built in pushing mechanism using the oslo bus.
A driver should inherit from 'vitrage.datasources.driver_base.DriverBase' class and must implement the following methods:
Name | Input | Output | Comments |
---|---|---|---|
get_all | sync mode | void | for snapshot mechanism |
get_changes | sync mode | void | for update pulling mechanism |
get_event_types | conf | void | for update pushing mechanism |
enrich_event | event, event_type | void | for update pushing mechanism |
Transformer Class
The Transformer class understands the specific entity details and outputs a tuple with the following details:
- The vertex with its new details to be added / updated / deleted.
- List of tuples where each tuple consists of:
- Neighbor vertex with it's partial data so vitrage will know to where to connect the edge.
- Edge that connects the vertex to its' neighbor.
Note that for every driver there should be a matching Transformer. A transformer should inherit from 'vitrage.datasoures.transformer_base.TransformerBase' class and must implement the following methods:
Name | Input | Output |
---|---|---|
_create_snapshot_entity_vertex | entity event | vertex |
_create_update_entity_vertex | entity event | vertex |
_create_snapshot_neighbors | entity event | neighbor tuple |
_create_update_neighbors | entity event | neighbor tuple |
_create_entity_key | entity event | the unique key of this entity |
get_type | datasources' type |
Configuration
Holds the following fields:
Name | Type | Description |
---|---|---|
transformer | string - Required! | Transformer class path under vitrage |
driver | string - Required! | Driver class path under vitrage |
update_method | string - Required! | need to be one of: pull, push or none values |
changes_interval | integer - Optional | Interval between checking for changes in polling mechanism |
entities | string list - Optional | Sub-entities of the datasource |
Example
Datasource __init__.py OPTS:
from oslo_config import cfg
= [
OPTS 'transformer',
cfg.StrOpt(='vitrage.datasources.cinder.volume.transformer.'
default'CinderVolumeTransformer',
help='Cinder volume transformer class path',
=True),
required'driver',
cfg.StrOpt(='vitrage.datasources.cinder.volume.driver.'
default'CinderVolumeDriver',
help='Cinder volume driver class path',
=True),
required'update_method',
cfg.StrOpt(=UpdateMethod.PUSH,
defaulthelp='None: updates only via Vitrage periodic snapshots.'
'Pull: updates every [changes_interval] seconds.'
'Push: updates by getting notifications from the'
' datasource itself.',
=True),
required ]
Instantiation flow
Now, when loading Vitrage, vitrage.datasources.launcher.Launcher will get instantiated and will register all of the datasources into Vitrage. Note, that if you want your datasource to also run as a service i.e. get changes every <interval> you need to set under your datasources' OPTS an Integer option named 'changes_interval'. Additionally, vitrage.entity_graph.transformer_manager.TransformerManager will get instantiated and will register all of the datasources transformers into Vitrage. These two steps are using your previously configured driver and transformer path options under your datasources' package __init__.OPTS.
Datasource Configuration Options
Any option your datasource defined can be accessed using oslo_config.cfg or by configuring vitrage.conf.
Example
<datasource_name>.<option_name> cfg.
Example
/etc/vitrage/vitrage.conf
...
[datasources]
snapshots_interval = 300
# Names of supported plugins (list value)
types = nova.host,nova.instance,nova.zone,static_physical,nagios,aodh,cinder.volume,neutron.network,neutron.port,heat.stack
[zabbix]
url = http://135.248.18.30
password = zabbix
user = admin
config_file = /etc/vitrage/zabbix_conf.yaml