2
# -*- coding: utf-8 -*-
4
__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
8
from subprocess import check_call
10
from charmhelpers.core.hookenv import (
16
def create(sysctl_dict, sysctl_file):
17
"""Creates a sysctl.conf file from a YAML associative array
19
:param sysctl_dict: a dict of sysctl options eg { 'kernel.max_pid': 1337 }
20
:type sysctl_dict: dict
21
:param sysctl_file: path to the sysctl file to be saved
22
:type sysctl_file: str or unicode
25
sysctl_dict = yaml.load(sysctl_dict)
27
with open(sysctl_file, "w") as fd:
28
for key, value in sysctl_dict.items():
29
fd.write("{}={}\n".format(key, value))
31
log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict),
34
check_call(["sysctl", "-p", sysctl_file])