summaryrefslogtreecommitdiffstats
path: root/meta-openstack/classes/monitor.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openstack/classes/monitor.bbclass')
-rw-r--r--meta-openstack/classes/monitor.bbclass107
1 files changed, 107 insertions, 0 deletions
diff --git a/meta-openstack/classes/monitor.bbclass b/meta-openstack/classes/monitor.bbclass
new file mode 100644
index 0000000..83aaea2
--- /dev/null
+++ b/meta-openstack/classes/monitor.bbclass
@@ -0,0 +1,107 @@
1MONITOR_STAGING_DIR="${STAGING_DIR}/monitor"
2MONITOR_STAGING_SERVICES_DIR="${MONITOR_STAGING_DIR}/services"
3MONITOR_STAGING_CHECKS_DIR="${MONITOR_STAGING_DIR}/checks"
4MONITOR_CONFIG_DIR="${IMAGE_ROOTFS}/etc/monitor"
5MONITOR_CONFIG_SERVICES_DIR="${MONITOR_CONFIG_DIR}/services"
6MONITOR_CONFIG_CHECKS_DIR="${MONITOR_CONFIG_DIR}/checks"
7
8addtask monitor_install before do_package after do_install
9addtask monitor_clean before do_clean
10
11
12def copy_check_files(d, check_var_name, src, dest):
13 import shutil
14
15 mon_checks = bb.data.getVar(check_var_name, d, 1)
16 if mon_checks != None:
17 if not os.path.exists(dest):
18 os.makedirs(dest)
19 for check in mon_checks.split():
20 if os.path.exists(src + "/" + check):
21 shutil.copy(src + "/" + check, dest)
22 os.chmod(dest + "/" + check, 0755)
23
24python do_monitor_install() {
25 import shutil
26
27 if base_contains('OPENSTACK_EXTRA_FEATURES', 'monitoring', "0", "1", d) == "1":
28 bb.debug(1, 'OpenStack monitoring feature is disabled, skipping do_monitor_install')
29 return
30
31 mon_dir = bb.data.getVar('MONITOR_STAGING_DIR', d, 1)
32 mon_services_dir = bb.data.getVar('MONITOR_STAGING_SERVICES_DIR', d, 1)
33 mon_checks_dir = bb.data.getVar('MONITOR_STAGING_CHECKS_DIR', d, 1)
34 if not os.path.exists(mon_dir):
35 os.makedirs(mon_dir)
36 if not os.path.exists(mon_services_dir):
37 os.makedirs(mon_services_dir)
38 if not os.path.exists(mon_checks_dir):
39 os.makedirs(mon_checks_dir)
40 workdir = d.getVar('WORKDIR', True)
41
42 # Process monitor SERVICE catagory
43 mon_service_pkgs = bb.data.getVar('MONITOR_SERVICE_PACKAGES', d, 1)
44 if mon_service_pkgs != None:
45 for pkg in mon_service_pkgs.split():
46 f_name = os.path.join(mon_services_dir, pkg + '.service')
47 if os.path.exists(f_name):
48 os.remove(f_name)
49 data = bb.data.getVar('MONITOR_SERVICE_' + pkg, d, 1)
50 if data != None:
51 f = open(f_name, 'w')
52 f.write(d.getVar('MONITOR_SERVICE_' + pkg))
53
54 # Process monior CHECKS catagory
55 packages = (d.getVar('PACKAGES', True) or "").split()
56 if len(packages) >= 1 and os.path.exists(mon_checks_dir):
57 for pkg in packages:
58 copy_check_files(d, 'MONITOR_CHECKS_' + pkg, workdir, mon_checks_dir + '/' + pkg)
59}
60
61python do_monitor_clean() {
62 import shutil
63
64 mon_dir = bb.data.getVar('MONITOR_STAGING_DIR', d, 1)
65 mon_services_dir = bb.data.getVar('MONITOR_STAGING_SERVICES_DIR', d, 1)
66 mon_checks_dir = bb.data.getVar('MONITOR_STAGING_CHECKS_DIR', d, 1)
67 if not os.path.exists(mon_dir):
68 return
69
70 # Clean up monitor SERVICE catagory
71 mon_service_pkgs = bb.data.getVar('MONITOR_SERVICE_PACKAGES', d, 1)
72 if mon_service_pkgs != None and os.path.exists(mon_services_dir):
73 for pkg in mon_service_pkgs.split():
74 f_name = os.path.join(mon_services_dir, pkg + '.service')
75 if os.path.exists(f_name):
76 os.remove(f_name)
77
78 # Process monior CHECKS catagory
79 packages = (d.getVar('PACKAGES', True) or "").split()
80 if len(packages) >= 1 and os.path.exists(mon_checks_dir):
81 for pkg in packages:
82 if bb.data.getVar('MONITOR_CHECKS_' + pkg, d, 1) != None:
83 shutil.rmtree(mon_checks_dir + "/" + pkg, True)
84}
85
86monitor_rootfs_postprocess() {
87 if ${@base_contains('OPENSTACK_EXTRA_FEATURES', 'monitoring', "false", "true", d)}; then
88 echo "OpenStack monitoring feature is disabled, skipping monitor_rootfs_postprocess"
89 exit
90 fi
91
92 mkdir -p ${MONITOR_CONFIG_DIR} > /dev/null 2>&1
93 mkdir -p ${MONITOR_CONFIG_SERVICES_DIR} > /dev/null 2>&1
94 mkdir -p ${MONITOR_CONFIG_CHECKS_DIR} > /dev/null 2>&1
95
96 # Process monitor SERVICE catagory
97 files_list=`find ${MONITOR_STAGING_SERVICES_DIR} -type f`
98 for f in ${files_list}; do
99 cat $f >> ${MONITOR_CONFIG_SERVICES_DIR}/service_list.cfg
100 echo >> ${MONITOR_CONFIG_SERVICES_DIR}/service_list.cfg
101 done
102
103 # Process monior CHECKS catagory
104 cp -rf ${MONITOR_STAGING_CHECKS_DIR}/* ${MONITOR_CONFIG_CHECKS_DIR}
105}
106
107ROOTFS_POSTPROCESS_COMMAND += "monitor_rootfs_postprocess ; "