Faidon Liambotis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/187430

Change subject: Add sysfs module, to handle /sys settings
......................................................................

Add sysfs module, to handle /sys settings

Copy the sysctl module to a sysfs module as their function and usage are
very similar to each other. This allows us to set arbitrary /sys values,
similarly to how we handle /proc/sys values.

Note that support for /etc/sysfs.d was added post-precise, but we have
backported those changes in our own, internal version of sysfsutils for
precise.

Change-Id: I39d3004299f4bba4ae8142d96e1ce3c793119365
---
A modules/sysfs/manifests/conffile.pp
A modules/sysfs/manifests/init.pp
A modules/sysfs/manifests/parameters.pp
A modules/sysfs/templates/sysfs.conf.erb
4 files changed, 119 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/30/187430/1

diff --git a/modules/sysfs/manifests/conffile.pp 
b/modules/sysfs/manifests/conffile.pp
new file mode 100644
index 0000000..c8aca3e
--- /dev/null
+++ b/modules/sysfs/manifests/conffile.pp
@@ -0,0 +1,50 @@
+# == Define: sysfs::conffile
+#
+# Represents a file with sysfs kernel parameters in /etc/sysfs.d.
+#
+# === Parameters
+#
+# [*content*]
+#   The content of the file provided as a string. Either this or
+#   'source' must be specified.
+#
+# [*source*]
+#   The content of the file provided as a puppet:/// file reference.
+#   Either this or 'content' must be specified.
+#
+# [*priority*]
+#   A numeric value in range 60 - 99. In case of conflict, files with a
+#   higher priority override files with a lower priority.
+#
+#   If you're not sure, leave this unspecified. The default value of 60
+#   should suit most cases.
+#
+# === Examples
+#
+#  sysfs::conffile { 'hadoop':
+#    content  => template('hadoop/hadoop.conf.erb'),
+#    priority => 90,
+#  }
+#
+define sysfs::conffile(
+    $ensure   = present,
+    $content  = undef,
+    $source   = undef,
+    $priority = 70
+) {
+    include ::sysfs
+
+    if $priority !~ /^\d?\d$/ {
+        fail("'priority' must be an integer between 0 - 99 (got: 
${priority}).")
+    }
+
+    $basename = regsubst($title, '\W', '-', 'G')
+    $filename = sprintf('/etc/sysfs.d/%02d-%s.conf', $priority, $basename)
+
+    file { $filename:
+        ensure  => $ensure,
+        content => $content,
+        source  => $source,
+        notify  => Service['sysfsutils'],
+    }
+}
diff --git a/modules/sysfs/manifests/init.pp b/modules/sysfs/manifests/init.pp
new file mode 100644
index 0000000..ac4bb54
--- /dev/null
+++ b/modules/sysfs/manifests/init.pp
@@ -0,0 +1,25 @@
+# == Class: sysfs
+#
+# This Puppet module provides 'sysfs::conffile' and 'sysfs::parameters'
+# resources which manages kernel parameters using /etc/sysfs.d files
+# and the sysfsutils service.
+#
+class sysfs {
+    package { 'sysfsutils':
+       ensure => present,
+    }
+
+    file { '/etc/sysfs.d':
+        ensure  => directory,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0644',
+        recurse => true,
+        purge   => true,
+        force   => true,
+    }
+
+    service { 'sysfsutils':
+        refreshonly => true,
+    }
+}
diff --git a/modules/sysfs/manifests/parameters.pp 
b/modules/sysfs/manifests/parameters.pp
new file mode 100644
index 0000000..daf9c03
--- /dev/null
+++ b/modules/sysfs/manifests/parameters.pp
@@ -0,0 +1,37 @@
+# == Define: sysfs::parameters
+#
+# This custom resource lets you specify sysfs parameters using a Puppet
+# hash, set as the 'values' parameter.
+#
+# === Parameters
+#
+# [*values*]
+#   A hash that maps kernel parameter names to their desire value.
+#
+# [*priority*]
+#   A numeric value in range 60 - 99. In case of conflict, files with a
+#   higher priority override files with a lower priority.
+#
+#   If you're not sure, leave this unspecified. The default value of 60
+#   should suit most cases.
+#
+# === Examples
+#
+#  sysfs::parameters { 'sda_deadline':
+#    values => {
+#      'block.sda.queue.scheduler' => 'deadline',
+#    },
+#    priority => 90,
+#  }
+#
+define sysfs::parameters(
+    $values,
+    $ensure   = present,
+    $priority = 70
+) {
+    sysfs::conffile { $title:
+        ensure   => $ensure,
+        content  => template('sysfs/sysfs.conf.erb'),
+        priority => $priority,
+    }
+}
diff --git a/modules/sysfs/templates/sysfs.conf.erb 
b/modules/sysfs/templates/sysfs.conf.erb
new file mode 100644
index 0000000..285f71c
--- /dev/null
+++ b/modules/sysfs/templates/sysfs.conf.erb
@@ -0,0 +1,7 @@
+# sysfs parameters managed by Puppet.
+<%=
+    @values.sort.map { |k, v|
+        v = v.join(' ') if v.is_a?(Array)
+        [ k, v ].join(' = ')
+    }.join("\n")
+%>

-- 
To view, visit https://gerrit.wikimedia.org/r/187430
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39d3004299f4bba4ae8142d96e1ce3c793119365
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Faidon Liambotis <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to