~openstack-charmers-archive/charms/trusty/nova-compute/old-1501

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-12-15 09:10:57 UTC
  • mfrom: (91.1.8 nova-compute)
  • Revision ID: james.page@ubuntu.com-20141215091057-yixgfa5av3tebjwy
[corey.bryant,r=james-page] Sort out charmhelpers issues.

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])