30a73f5d6cb1a92d245a00c2c5f5986bdda98dfe
[doctor.git] / doctor_tests / installer / common / vitrage.py
1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import os
10
11
12 vitrage_template_file = \
13     '/etc/vitrage/templates/vitrage_host_down_scenarios.yaml'
14
15 template = """
16 metadata:
17  name: host_down_scenarios
18  description: scenarios triggered by Doctor monitor 'compute.host.down' alarm
19 definitions:
20  entities:
21   - entity:
22      category: ALARM
23      name: compute.host.down
24      template_id: host_down_alarm
25   - entity:
26      category: ALARM
27      type: vitrage
28      name: Instance Down
29      template_id: instance_alarm
30   - entity:
31      category: RESOURCE
32      type: nova.instance
33      template_id: instance
34   - entity:
35      category: RESOURCE
36      type: nova.host
37      template_id: host
38  relationships:
39   - relationship:
40      source: host_down_alarm
41      relationship_type: on
42      target: host
43      template_id : host_down_alarm_on_host
44   - relationship:
45      source: host
46      relationship_type: contains
47      target: instance
48      template_id : host_contains_instance
49   - relationship:
50      source: instance_alarm
51      relationship_type: on
52      target: instance
53      template_id : alarm_on_instance
54 scenarios:
55  - scenario:
56     condition: host_down_alarm_on_host
57     actions:
58      - action:
59         action_type: set_state
60         action_target:
61          target: host
62         properties:
63          state: ERROR
64      - action:
65         action_type: mark_down
66         action_target:
67          target: host
68  - scenario:
69     condition: host_down_alarm_on_host and host_contains_instance
70     actions:
71      - action:
72         action_type: raise_alarm
73         action_target:
74          target: instance
75         properties:
76          alarm_name: Instance Down
77          severity: critical
78  - scenario:
79     condition: host_down_alarm_on_host and host_contains_instance and alarm_on_instance
80     actions:
81      - action:
82         action_type: add_causal_relationship
83         action_target:
84          source: host_down_alarm
85          target: instance_alarm
86      - action:
87         action_type: mark_down
88         action_target:
89           target: instance
90 """    # noqa
91
92
93 def set_vitrage_host_down_template():
94     if os.path.isfile(vitrage_template_file):
95         print('Vitrage host_down template file: %s already exists.'
96               % vitrage_template_file)
97     else:
98         print('Create Vitrage host_down template file:%s.'
99               % vitrage_template_file)
100         with open(vitrage_template_file, 'w') as file:
101             file.write(template)