Support parameters in Vitrage templates
A new optional --params parameter was added to 'vitrage template add' and 'vitrage template validate' APIs, to allow assigning actual values to parameters in Vitrage templates. Story: 2004056 Task: 29134 Depends-On: Iac163aaf6de0e029893386fc4274421df4706c4e Change-Id: I144f6cb889be6e97e0d4cbcf1fe5820c8d38c716
This commit is contained in:
parent
a7b134c0bd
commit
a0e346b6db
|
@ -191,7 +191,11 @@ Topology Example
|
||||||
----------------
|
----------------
|
||||||
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
||||||
|
|
||||||
topology show::
|
topology show
|
||||||
|
^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
|
vitrage topology show
|
||||||
|
|
||||||
{
|
{
|
||||||
"directed": true,
|
"directed": true,
|
||||||
|
@ -609,7 +613,9 @@ RCA Example
|
||||||
-----------
|
-----------
|
||||||
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
||||||
|
|
||||||
rca show::
|
rca show
|
||||||
|
^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage rca show
|
vitrage rca show
|
||||||
|
|
||||||
|
@ -681,7 +687,9 @@ Resources Examples
|
||||||
------------------
|
------------------
|
||||||
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
||||||
|
|
||||||
resource list::
|
resource list
|
||||||
|
^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage resource list
|
vitrage resource list
|
||||||
+--------------------------------------+-------------------+--------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------+
|
+--------------------------------------+-------------------+--------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
@ -695,7 +703,9 @@ resource list::
|
||||||
| 374203a6-e7bc-4bd6-bc32-1137f4f3d234 | nova.zone | nova | OK | {'name': u'nova', 'update_timestamp': u'2018-01-03 09:06:07.628148+00:00'} |
|
| 374203a6-e7bc-4bd6-bc32-1137f4f3d234 | nova.zone | nova | OK | {'name': u'nova', 'update_timestamp': u'2018-01-03 09:06:07.628148+00:00'} |
|
||||||
+--------------------------------------+-------------------+--------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------+
|
+--------------------------------------+-------------------+--------------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
|
||||||
resource show::
|
resource show
|
||||||
|
^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage resource show 786efe03-55ff-41b2-bdc1-6cd94bc355ad
|
vitrage resource show 786efe03-55ff-41b2-bdc1-6cd94bc355ad
|
||||||
+---------------------------+--------------------------------------+
|
+---------------------------+--------------------------------------+
|
||||||
|
@ -719,7 +729,9 @@ resource show::
|
||||||
| vitrage_type | nova.instance |
|
| vitrage_type | nova.instance |
|
||||||
+---------------------------+--------------------------------------+
|
+---------------------------+--------------------------------------+
|
||||||
|
|
||||||
resource count::
|
resource count
|
||||||
|
^^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage resource count
|
vitrage resource count
|
||||||
{
|
{
|
||||||
|
@ -848,10 +860,14 @@ Template Examples
|
||||||
**Note:** for templates version 2 --type <template type> is not required.
|
**Note:** for templates version 2 --type <template type> is not required.
|
||||||
Template type is specified in the metadata section.
|
Template type is specified in the metadata section.
|
||||||
|
|
||||||
template validate::
|
template validate
|
||||||
|
^^^^^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage template validate --path /home/stack/my_template.yaml --type standard
|
vitrage template validate --path /home/stack/my_template.yaml --type standard
|
||||||
|
|
||||||
Valid types are: standard, definition and equivalence
|
Valid types are: standard, definition and equivalence
|
||||||
|
|
||||||
{
|
{
|
||||||
"results": [
|
"results": [
|
||||||
{
|
{
|
||||||
|
@ -877,7 +893,9 @@ template validate::
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
template list::
|
template list
|
||||||
|
^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage template list
|
vitrage template list
|
||||||
+--------------------------------------+-----------------------------------------+--------+---------------------------+---------------------+-------------+
|
+--------------------------------------+-----------------------------------------+--------+---------------------------+---------------------+-------------+
|
||||||
|
@ -890,12 +908,16 @@ template list::
|
||||||
+--------------------------------------+-----------------------------------------+--------+---------------------------+---------------------+-------------+
|
+--------------------------------------+-----------------------------------------+--------+---------------------------+---------------------+-------------+
|
||||||
|
|
||||||
|
|
||||||
template show::
|
template show
|
||||||
|
^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage template show 72f47086-366f-44d1-b88f-e420a8bc8ff0
|
vitrage template show 72f47086-366f-44d1-b88f-e420a8bc8ff0
|
||||||
returns a loaded template as json
|
returns a loaded template as json
|
||||||
|
|
||||||
template add::
|
template add
|
||||||
|
^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
For template of version 2:
|
For template of version 2:
|
||||||
vitrage template add --path /etc/vitrage/templates/host_disk_io_usage_scenarios.yaml
|
vitrage template add --path /etc/vitrage/templates/host_disk_io_usage_scenarios.yaml
|
||||||
|
@ -911,13 +933,58 @@ template add::
|
||||||
| ae3c0752-1df9-408c-89d5-8b32b86f403f | host_disk_io_overloaded_usage_scenarios | LOADING | Template validation is OK | 2018-01-23 10:14:05.135990 | standard |
|
| ae3c0752-1df9-408c-89d5-8b32b86f403f | host_disk_io_overloaded_usage_scenarios | LOADING | Template validation is OK | 2018-01-23 10:14:05.135990 | standard |
|
||||||
+--------------------------------------+-----------------------------------------+---------+---------------------------+----------------------------+----------+
|
+--------------------------------------+-----------------------------------------+---------+---------------------------+----------------------------+----------+
|
||||||
|
|
||||||
template delete::
|
template delete
|
||||||
|
^^^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage template delete ae3c0752-1df9-408c-89d5-8b32b86f403f
|
vitrage template delete ae3c0752-1df9-408c-89d5-8b32b86f403f
|
||||||
|
|
||||||
for multiple delete:
|
For deleting multiple templates:
|
||||||
vitrage template delete ae3c0752-1df9-408c-89d5-8b32b86f403f f254edb0-53cb-4552-969b-bdad24a14a03
|
vitrage template delete ae3c0752-1df9-408c-89d5-8b32b86f403f f254edb0-53cb-4552-969b-bdad24a14a03
|
||||||
|
|
||||||
|
Templates with parameters
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
|
vitrage template validate --path ./with_single_param.yaml
|
||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"status": "validation failed",
|
||||||
|
"file path": "with_single_param.yaml",
|
||||||
|
"status code": 163,
|
||||||
|
"message": "Failed to resolve parameter",
|
||||||
|
"description": "Template content validation"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
vitrage template validate --path ./with_single_param.yaml --params alarm_name=Alarm1
|
||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"status": "validation OK",
|
||||||
|
"file path": "with_single_param.yaml",
|
||||||
|
"status code": 0,
|
||||||
|
"message": "Template validation is OK",
|
||||||
|
"description": "Template validation"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
vitrage template add --path ./with_single_param.yaml
|
||||||
|
+--------------------------------------+-------------------+--------+-----------------------------+----------------------------+----------+
|
||||||
|
| UUID | Name | Status | Status details | Date | Type |
|
||||||
|
+--------------------------------------+-------------------+--------+-----------------------------+----------------------------+----------+
|
||||||
|
| d785f6d4-123b-4271-80cf-c5d9c21adb12 | with_single_param | ERROR | Failed to resolve parameter | 2019-02-11 11:44:50.916064 | standard |
|
||||||
|
+--------------------------------------+-------------------+--------+-----------------------------+----------------------------+----------+
|
||||||
|
|
||||||
|
vitrage template add --path with_params.yaml --params template_name=Template1 alarm_name=Alarm2
|
||||||
|
+--------------------------------------+-----------+---------+---------------------------+----------------------------+----------+
|
||||||
|
| UUID | Name | Status | Status details | Date | Type |
|
||||||
|
+--------------------------------------+-----------+---------+---------------------------+----------------------------+----------+
|
||||||
|
| 1a18a38b-99ee-4835-964d-a3fe2f17d4cd | Template1 | LOADING | Template validation is OK | 2019-02-11 11:57:31.077176 | standard |
|
||||||
|
+--------------------------------------+-----------+---------+---------------------------+----------------------------+----------+
|
||||||
|
|
||||||
Event Examples
|
Event Examples
|
||||||
--------------
|
--------------
|
||||||
|
@ -936,7 +1003,9 @@ Webhook Example
|
||||||
---------------
|
---------------
|
||||||
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
Note: To see complete usage: 'vitrage help' and 'vitrage help <command>'
|
||||||
|
|
||||||
webhook list::
|
webhook list
|
||||||
|
^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage webhook list
|
vitrage webhook list
|
||||||
|
|
||||||
|
@ -948,7 +1017,9 @@ webhook list::
|
||||||
+--------------------------------------+----------------------------+----------------------------------+---------------------------+--------------------------------------+------------------------+
|
+--------------------------------------+----------------------------+----------------------------------+---------------------------+--------------------------------------+------------------------+
|
||||||
|
|
||||||
|
|
||||||
webhook show::
|
webhook show
|
||||||
|
^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage webhook show c35caf11-f34d-440e-a804-0c1a4fdfb95b
|
vitrage webhook show c35caf11-f34d-440e-a804-0c1a4fdfb95b
|
||||||
|
|
||||||
|
@ -963,7 +1034,9 @@ webhook show::
|
||||||
| url | https://requestb.in/tq3fkvtq |
|
| url | https://requestb.in/tq3fkvtq |
|
||||||
+--------------+--------------------------------------+
|
+--------------+--------------------------------------+
|
||||||
|
|
||||||
webhook delete::
|
webhook delete
|
||||||
|
^^^^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage webhook delete c35caf11-f34d-440e-a804-0c1a4fdfb95b
|
vitrage webhook delete c35caf11-f34d-440e-a804-0c1a4fdfb95b
|
||||||
|
|
||||||
|
@ -974,7 +1047,9 @@ webhook delete::
|
||||||
+---------+------------------------------------------------------+
|
+---------+------------------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
webhook add::
|
webhook add
|
||||||
|
^^^^^^^^^^^
|
||||||
|
::
|
||||||
|
|
||||||
vitrage webhook add --url https://www.myurl.com --headers
|
vitrage webhook add --url https://www.myurl.com --headers
|
||||||
"{'content-type': 'application/json'}" --regex_filter "{'vitrage_type':'.*'}"
|
"{'content-type': 'application/json'}" --regex_filter "{'vitrage_type':'.*'}"
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- Added support for parameters in Vitrage templates. ``vitrage template add``
|
||||||
|
can now be called with an additional ``--params`` argument for assigning
|
||||||
|
actual values for the parameters that are defined in the template.
|
|
@ -20,6 +20,15 @@ from cliff import show
|
||||||
|
|
||||||
from vitrageclient.common import utils
|
from vitrageclient.common import utils
|
||||||
|
|
||||||
|
from oslo_log import log
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_template_params(cli_param_list):
|
||||||
|
return dict(cli_param.split('=', 1) for cli_param in cli_param_list) \
|
||||||
|
if cli_param_list else {}
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyAbstractClass
|
# noinspection PyAbstractClass
|
||||||
class TemplateValidate(show.ShowOne):
|
class TemplateValidate(show.ShowOne):
|
||||||
|
@ -35,6 +44,12 @@ class TemplateValidate(show.ShowOne):
|
||||||
choices=['standard', 'definition', 'equivalence'],
|
choices=['standard', 'definition', 'equivalence'],
|
||||||
help='Template type. Valid types:'
|
help='Template type. Valid types:'
|
||||||
'[standard, definition, equivalence]')
|
'[standard, definition, equivalence]')
|
||||||
|
parser.add_argument('--params', nargs='+',
|
||||||
|
help='Actual values for parameters of the '
|
||||||
|
'template. Several key=value pairs may be '
|
||||||
|
'used, for example: --params '
|
||||||
|
'template_name=cpu_problem '
|
||||||
|
'alarm_name=\'High CPU Load\'')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -43,9 +58,13 @@ class TemplateValidate(show.ShowOne):
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
|
||||||
|
cli_param_list = parsed_args.params
|
||||||
|
params = _parse_template_params(cli_param_list)
|
||||||
|
|
||||||
result = utils.get_client(self).template.validate(
|
result = utils.get_client(self).template.validate(
|
||||||
path=parsed_args.path,
|
path=parsed_args.path,
|
||||||
template_type=parsed_args.type)
|
template_type=parsed_args.type,
|
||||||
|
params=params)
|
||||||
|
|
||||||
return self.dict2columns(result)
|
return self.dict2columns(result)
|
||||||
|
|
||||||
|
@ -105,13 +124,23 @@ class TemplateAdd(lister.Lister):
|
||||||
choices=['standard', 'definition', 'equivalence'],
|
choices=['standard', 'definition', 'equivalence'],
|
||||||
help='Template type. Valid types:'
|
help='Template type. Valid types:'
|
||||||
'[standard, definition, equivalence]')
|
'[standard, definition, equivalence]')
|
||||||
|
parser.add_argument('--params', nargs='+',
|
||||||
|
help='Actual values for parameters of the '
|
||||||
|
'template. Several key=value pairs may be '
|
||||||
|
'used, for example: --params '
|
||||||
|
'template_name=cpu_problem '
|
||||||
|
'alarm_name=\'High CPU Load\'')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
path = parsed_args.path
|
path = parsed_args.path
|
||||||
template_type = parsed_args.type
|
template_type = parsed_args.type
|
||||||
|
cli_param_list = parsed_args.params
|
||||||
|
params = _parse_template_params(cli_param_list)
|
||||||
|
|
||||||
templates = utils.get_client(self).template.add(
|
templates = utils.get_client(self).template.add(
|
||||||
path=path, template_type=template_type)
|
path=path, template_type=template_type, params=params)
|
||||||
|
|
||||||
return utils.list2cols_with_rename(
|
return utils.list2cols_with_rename(
|
||||||
(
|
(
|
||||||
('UUID', 'uuid'),
|
('UUID', 'uuid'),
|
||||||
|
|
|
@ -35,19 +35,21 @@ class Template(object):
|
||||||
url = self.url + uuid
|
url = self.url + uuid
|
||||||
return self.api.get(url).json()
|
return self.api.get(url).json()
|
||||||
|
|
||||||
def add(self, path, template_type=None):
|
def add(self, path, template_type=None, params=None):
|
||||||
"""Add a new template"""
|
"""Add a new template"""
|
||||||
|
|
||||||
files_content = self._load_yaml_files(path)
|
files_content = self._load_yaml_files(path)
|
||||||
params = dict(templates=files_content, template_type=template_type)
|
api_params = dict(templates=files_content,
|
||||||
return self.api.put(self.url, json=params).json()
|
template_type=template_type,
|
||||||
|
params=params)
|
||||||
|
return self.api.put(self.url, json=api_params).json()
|
||||||
|
|
||||||
def delete(self, uuid):
|
def delete(self, uuid):
|
||||||
"""Delete existing"""
|
"""Delete existing"""
|
||||||
params = dict(uuid=uuid)
|
params = dict(uuid=uuid)
|
||||||
return self.api.delete(self.url, json=params).json()
|
return self.api.delete(self.url, json=params).json()
|
||||||
|
|
||||||
def validate(self, path, template_type=None):
|
def validate(self, path, template_type=None, params=None):
|
||||||
"""Template validation
|
"""Template validation
|
||||||
|
|
||||||
Make sure that the template file is correct in terms of syntax
|
Make sure that the template file is correct in terms of syntax
|
||||||
|
@ -58,11 +60,14 @@ class Template(object):
|
||||||
|
|
||||||
:param path: the template file path or templates dir path
|
:param path: the template file path or templates dir path
|
||||||
:param template_type: type of templates ('standard','definition',...)
|
:param template_type: type of templates ('standard','definition',...)
|
||||||
|
:param params: (optional) actual values for the template parameters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
files_content = self._load_yaml_files(path)
|
files_content = self._load_yaml_files(path)
|
||||||
params = dict(templates=files_content, template_type=template_type)
|
api_params = dict(templates=files_content,
|
||||||
return self.api.post(self.url, json=params).json()
|
template_type=template_type,
|
||||||
|
params=params)
|
||||||
|
return self.api.post(self.url, json=api_params).json()
|
||||||
|
|
||||||
def _load_yaml_files(self, path):
|
def _load_yaml_files(self, path):
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
|
|
Loading…
Reference in New Issue