coren has uploaded a new change for review.

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

Change subject: Creat tc class analogous to ferm for traffic control
......................................................................

Creat tc class analogous to ferm for traffic control

Change-Id: I2fdf0421b87acc20e6cb320f25dd765cfa8aa606
---
A modules/tc/files/apply-tc
A modules/tc/manifests/init.pp
A modules/tc/manifests/interface.pp
A modules/tc/manifests/rule.pp
A modules/tc/templates/initscripts/tc.systemd.erb
A modules/tc/templates/initscripts/tc.upstart.erb
A modules/tc/templates/rule.erb
7 files changed, 121 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/58/209558/1

diff --git a/modules/tc/files/apply-tc b/modules/tc/files/apply-tc
new file mode 100644
index 0000000..17f9054
--- /dev/null
+++ b/modules/tc/files/apply-tc
@@ -0,0 +1,14 @@
+#! /bin/bash
+#
+# This configures traffic shaping on the host by executing the
+# files in /etc/rc/$iface.d that are intended to contain actual
+# /sbin/tc invocations.
+#
+# the scripts are invoked with $1 as the interface name so that
+# they can be made generic.
+
+
+for dir in /etc/tc/*.d; do
+    iface=$(basename "$dir" .d)
+    /bin/run-parts "--arg=$iface" "$dir"
+done
diff --git a/modules/tc/manifests/init.pp b/modules/tc/manifests/init.pp
new file mode 100644
index 0000000..61ecbe6
--- /dev/null
+++ b/modules/tc/manifests/init.pp
@@ -0,0 +1,39 @@
+# == class tc ==
+#
+# Allows for setting up traffic control scripts to be run
+# at boot time (and on change) in a way that works
+# regardless of OS flavour.
+#
+# It constructs a tree, at /etc/tc, that contains one directory
+# (named $iface.d) for every interface to manage tc for, and
+# the upstart/systemd scripts to enable tc by running their
+# contents with run-parts
+#
+
+class tc {
+
+    file { '/etc/tc':
+        ensure  => directory,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0755',
+    }
+
+    file { '/usr/local/sbin/apply-tc':
+        ensure  => present,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0755',
+        source  => 'puppet:///modules/tc/apply-tc',
+    }
+
+    base::service_unit { 'tc':
+        ensure  => present,
+        strict  => true,
+        upstart => true,
+        systemd => true,
+        refresh => true,
+    }
+
+}
+
diff --git a/modules/tc/manifests/interface.pp 
b/modules/tc/manifests/interface.pp
new file mode 100644
index 0000000..5143ea1
--- /dev/null
+++ b/modules/tc/manifests/interface.pp
@@ -0,0 +1,25 @@
+
+
+define tc::interface($iface) {
+
+    file { "/etc/rc/${iface}.d":
+        ensure => directory,
+        owner  => 'root',
+        group  => 'root',
+        mode   => '0755',
+        recurse => true,
+        purge   => true,
+    }
+
+    # Rules are applied additively; insert a 00_flush
+    # rule to clean the slate before anything else
+
+    tc::rule('flush':
+        iface  => $iface,
+        action => 'del',
+        rule   => 'root',
+        prio   => '00',
+    }
+
+}
+
diff --git a/modules/tc/manifests/rule.pp b/modules/tc/manifests/rule.pp
new file mode 100644
index 0000000..e57cec7
--- /dev/null
+++ b/modules/tc/manifests/rule.pp
@@ -0,0 +1,21 @@
+
+
+define tc::rule(
+    $rule,
+    $iface,
+    $action = 'add',
+    $type   = 'qdisc',
+    $prio   = 10,
+) {
+
+    file { "/etc/tc/${iface}.d/${prio}_${name}":
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0500',
+        content => template('tc/rule.erb'),
+        require => File["/etc/tc/${iface}.d"]
+        notify  => Service['tc'],
+    }
+
+}
+
diff --git a/modules/tc/templates/initscripts/tc.systemd.erb 
b/modules/tc/templates/initscripts/tc.systemd.erb
new file mode 100644
index 0000000..2bd5545
--- /dev/null
+++ b/modules/tc/templates/initscripts/tc.systemd.erb
@@ -0,0 +1,12 @@
+[Unit]
+Description="Apply traffic control rules from /etc/tc/*.d"
+Wants=network.target network-online.target
+After=network.target network-online.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/local/sbin/apply-tc
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/modules/tc/templates/initscripts/tc.upstart.erb 
b/modules/tc/templates/initscripts/tc.upstart.erb
new file mode 100644
index 0000000..d930057
--- /dev/null
+++ b/modules/tc/templates/initscripts/tc.upstart.erb
@@ -0,0 +1,7 @@
+description "Apply traffic control rules from /etc/tc/*.d"
+
+start on started networking
+
+task
+
+exec /usr/local/sbin/apply-tc
diff --git a/modules/tc/templates/rule.erb b/modules/tc/templates/rule.erb
new file mode 100644
index 0000000..465f13f
--- /dev/null
+++ b/modules/tc/templates/rule.erb
@@ -0,0 +1,3 @@
+# Autogenerated by puppet. DO NOT EDIT BY HAND!
+
+exec /sbin/tc <%= @type %> <%= @action %> dev <%= @iface %> <%= @rule %>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2fdf0421b87acc20e6cb320f25dd765cfa8aa606
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: coren <mpellet...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to