From 0ba34b5c0d5089e3359827a9edad9176a70614cd Mon Sep 17 00:00:00 2001 From: Jorge Niedbalski Date: Tue, 7 Oct 2014 11:01:56 +0200 Subject: [PATCH] - Moved sysctl logic to charmhelpers for make it compatible with ceph-osd --- config.yaml | 8 +++++++- hooks/charmhelpers/core/sysctl.py | 34 +++++++++++++++++++++++++++++++ hooks/hooks.py | 6 ++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 hooks/charmhelpers/core/sysctl.py diff --git a/config.yaml b/config.yaml index 95e9485..218f7af 100644 --- a/config.yaml +++ b/config.yaml @@ -154,4 +154,10 @@ options: NOTE: these charms do not currently support IPv6 privacy extension. In order for this charm to function correctly, the privacy extension must be disabled and a non-temporary address must be configured/available on - your network interface. + your network interface. + sysctl: + type: string + default: "" + description: | + YAML formatted associative array of sysctl values, e.g.: + '{ kernel.pid_max : 4194303 }' diff --git a/hooks/charmhelpers/core/sysctl.py b/hooks/charmhelpers/core/sysctl.py new file mode 100644 index 0000000..0f29963 --- /dev/null +++ b/hooks/charmhelpers/core/sysctl.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +__author__ = 'Jorge Niedbalski R. ' + +import yaml + +from subprocess import check_call + +from charmhelpers.core.hookenv import ( + log, + DEBUG, +) + + +def create(sysctl_dict, sysctl_file): + """Creates a sysctl.conf file from a YAML associative array + + :param sysctl_dict: a dict of sysctl options eg { 'kernel.max_pid': 1337 } + :type sysctl_dict: dict + :param sysctl_file: path to the sysctl file to be saved + :type sysctl_file: str or unicode + :returns: None + """ + sysctl_dict = yaml.load(sysctl_dict) + + with open(sysctl_file, "w") as fd: + for key, value in sysctl_dict.items(): + fd.write("{}={}\n".format(key, value)) + + log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict), + level=DEBUG) + + check_call(["sysctl", "-p", sysctl_file]) diff --git a/hooks/hooks.py b/hooks/hooks.py index 8a6c26c..4b8fb45 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -45,6 +45,8 @@ from charmhelpers.contrib.network.ip import ( format_ipv6_addr ) +from charmhelpers.core.sysctl import create as create_sysctl + from utils import ( render_template, get_public_addr, @@ -119,6 +121,10 @@ def config_changed(): log('Invalid OSD disk format configuration specified', level=ERROR) sys.exit(1) + sysctl_dict = config('sysctl') + if sysctl_dict: + create_sysctl(sysctl_dict, '/etc/sysctl.d/50-ceph-charm.conf') + emit_cephconf() e_mountpoint = config('ephemeral-unmount')