- Moved sysctl logic to charmhelpers for make it compatible with ceph-osd

This commit is contained in:
Jorge Niedbalski 2014-10-07 11:01:56 +02:00
parent 141e6bc872
commit 0ba34b5c0d
3 changed files with 47 additions and 1 deletions

View File

@ -154,4 +154,10 @@ options:
NOTE: these charms do not currently support IPv6 privacy extension. In NOTE: these charms do not currently support IPv6 privacy extension. In
order for this charm to function correctly, the privacy extension must be order for this charm to function correctly, the privacy extension must be
disabled and a non-temporary address must be configured/available on 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 }'

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
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])

View File

@ -45,6 +45,8 @@ from charmhelpers.contrib.network.ip import (
format_ipv6_addr format_ipv6_addr
) )
from charmhelpers.core.sysctl import create as create_sysctl
from utils import ( from utils import (
render_template, render_template,
get_public_addr, get_public_addr,
@ -119,6 +121,10 @@ def config_changed():
log('Invalid OSD disk format configuration specified', level=ERROR) log('Invalid OSD disk format configuration specified', level=ERROR)
sys.exit(1) sys.exit(1)
sysctl_dict = config('sysctl')
if sysctl_dict:
create_sysctl(sysctl_dict, '/etc/sysctl.d/50-ceph-charm.conf')
emit_cephconf() emit_cephconf()
e_mountpoint = config('ephemeral-unmount') e_mountpoint = config('ephemeral-unmount')