9ea32271b667c0892023b02b1b73fed3bc1a7e8c
[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 = '/etc/vitrage/templates/vitrage_host_down_scenarios.yaml'
13
14 template = """
15 metadata:
16  name: host_down_scenarios
17  description: scenarios triggered by Doctor monitor 'compute.host.down' alarm
18 definitions:
19  entities:
20   - entity:
21      category: ALARM
22      name: compute.host.down
23      template_id: host_down_alarm
24   - entity:
25      category: ALARM
26      type: vitrage
27      name: Instance Down
28      template_id: instance_alarm
29   - entity:
30      category: RESOURCE
31      type: nova.instance
32      template_id: instance
33   - entity:
34      category: RESOURCE
35      type: nova.host
36      template_id: host
37  relationships:
38   - relationship:
39      source: host_down_alarm
40      relationship_type: on
41      target: host
42      template_id : host_down_alarm_on_host
43   - relationship:
44      source: host
45      relationship_type: contains
46      target: instance
47      template_id : host_contains_instance
48   - relationship:
49      source: instance_alarm
50      relationship_type: on
51      target: instance
52      template_id : alarm_on_instance
53 scenarios:
54  - scenario:
55     condition: host_down_alarm_on_host
56     actions:
57      - action:
58         action_type: set_state
59         action_target:
60          target: host
61         properties:
62          state: ERROR
63      - action:
64         action_type: mark_down
65         action_target:
66          target: host
67  - scenario:
68     condition: host_down_alarm_on_host and host_contains_instance
69     actions:
70      - action:
71         action_type: raise_alarm
72         action_target:
73          target: instance
74         properties:
75          alarm_name: Instance Down
76          severity: critical
77  - scenario:
78     condition: host_down_alarm_on_host and host_contains_instance and alarm_on_instance
79     actions:
80      - action:
81         action_type: add_causal_relationship
82         action_target:
83          source: host_down_alarm
84          target: instance_alarm
85      - action:
86         action_type: mark_down
87         action_target:
88           target: instance
89 """
90
91
92 def set_vitrage_host_down_template():
93     if os.path.isfile(vitrage_template_file):
94         print('Vitrage host_down template file: %s already exists.' % vitrage_template_file)
95     else:
96         print('Create Vitrage host_down template file:%s.' % vitrage_template_file)
97         with open(vitrage_template_file, 'w') as file:
98             file.write(template)