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