~corey.bryant/charms/trusty/cinder/contrib.python.packages

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/sysctl.py

  • Committer: Edward Hope-Morley
  • Date: 2014-10-09 10:20:37 UTC
  • Revision ID: edward.hope-morley@canonical.com-20141009102037-3z1zr5gwh6wquesu
synced charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
 
5
 
 
6
import yaml
 
7
 
 
8
from subprocess import check_call
 
9
 
 
10
from charmhelpers.core.hookenv import (
 
11
    log,
 
12
    DEBUG,
 
13
)
 
14
 
 
15
 
 
16
def create(sysctl_dict, sysctl_file):
 
17
    """Creates a sysctl.conf file from a YAML associative array
 
18
 
 
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
 
23
    :returns: None
 
24
    """
 
25
    sysctl_dict = yaml.load(sysctl_dict)
 
26
 
 
27
    with open(sysctl_file, "w") as fd:
 
28
        for key, value in sysctl_dict.items():
 
29
            fd.write("{}={}\n".format(key, value))
 
30
 
 
31
    log("Updating sysctl_file: %s values: %s" % (sysctl_file, sysctl_dict),
 
32
        level=DEBUG)
 
33
 
 
34
    check_call(["sysctl", "-p", sysctl_file])