Permalink
Browse files

Merge pull request #7 from puppetlabs-operations/master

+1 -- Release of 1.1.0
  • Loading branch information...
2 parents 8a4ac13 + 38d6968 commit 42b7827006157dba3ba02d5f159b1f3f72d71788 @ryanycoleman ryanycoleman committed Oct 3, 2012
Showing with 228 additions and 5 deletions.
  1. +10 −0 CHANGELOG
  2. +2 −2 Modulefile
  3. +160 −0 files/export-mrepo
  4. +44 −0 manifests/exports.pp
  5. +6 −1 manifests/params.pp
  6. +6 −2 templates/mrepo.conf.erb
View
@@ -1,5 +1,15 @@
CHANGELOG
+1.1.0
+=====
+
+ * Correct invalid Modulefile dependency
+ * Changes to conform to style guide.
+ * Allow tuning of email recipient
+ * Add in mrepo::exports class
+ * Add in support for creating NFS shares of mrepo disks. This is primarily
+ needed for mirroring and building on SLES.
+
1.0.0
=====
View
@@ -1,5 +1,5 @@
name 'puppetlabs-mrepo'
-version '1.0.0'
+version '1.1.0'
source 'git://github.com/puppetlabs/puppetlabs-mrepo'
author 'puppetlabs'
license 'Apache 2.0'
@@ -8,7 +8,7 @@ description 'Puppet module to configure and manage mrepo mirrors. Mirrors can
be generated from distribution ISOs, existing RPM mirrors, the Redhat Network,
or Yast Online Update.'
-dependency 'puppetlabs-apache', '>= 0.0.3'
+dependency 'puppetlabs/apache', '>= 0.0.3'
dependency 'puppetlabs/vcsrepo', '>= 0.0.3'
dependency 'puppetlabs/stdlib', '>= 0.1.6'
dependency 'nanliu/staging', '>= 0.1.0'
View
@@ -0,0 +1,160 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+
+# Extract all mountpoints to share
+#
+# @param [String] The mrepo www root
+#
+# @return [Array] A list of all the ISO mountpoints under the mrepo www root
+def mount_list(www_root)
+ arr = []
+ %x{mount -t iso9660}.scan(/\S+ on (\S+)/) do |a|
+ mountpoint = a[0]
+ arr << mountpoint if mountpoint.match %r{#{www_root}}
+ end
+ arr
+end
+
+# Provide every 2-tuple combination of two given arrays
+#
+# @param [Array] one
+# @param [Array] two
+#
+# @yield [Object, Object] every successive combination
+#
+# @return [Array<Array<Object, Object>>]
+def combine(one, two)
+
+ tuples = []
+
+ one.each do |o|
+ two.each do |t|
+ pair = [o, t]
+ tuples << pair
+ yield o, t if block_given?
+ end
+ end
+
+ tuples
+end
+
+# Return formatted lines for /etc/exports
+#
+# @param [Array<String>] paths
+# @param [Array<String>] clients
+# @param [String] options The NFS export options
+def generate_exports(paths, clients, options)
+
+ contents = []
+
+ combine(paths, clients) do |path, client|
+ line = "#{path} #{client}(#{options})"
+ contents << line
+ end
+
+ contents
+end
+
+# @param [Array<String>] The argument list to parse
+#
+# @return [Hash] The parsed options
+def parse(args)
+ options = {
+ :options => %w{ro sec=sys crossmnt},
+ :www_root => default_www_root,
+ :action => 'print'
+ }
+
+ parser = OptionParser.new do |p|
+ p.banner = "Usage: #{File.basename($0)} [options] [print|write]"
+
+ p.on('-r',
+ '--root=val',
+ 'The mrepo root to use when locating mountpoints',
+ "default: (#{options[:www_root].dup})"
+ ) do |val|
+ options[:www_root] = val
+ end
+
+ p.on('-o',
+ '--options=val',
+ "NFS export options",
+ "default: (#{options[:options].dup.join(', ')})"
+ ) do |val|
+ options[:options] ||= []
+ options[:options] << val
+ end
+
+ p.on('-c',
+ '--client=val',
+ 'The NFS mount recipient'
+ ) do |val|
+ options[:clients] ||= []
+ options[:clients] << val
+ end
+ end
+
+ action = parser.parse!(args)
+
+ if options[:clients].nil?
+ raise OptionParser::MissingArgument, 'client'
+ end
+
+ if action.empty?
+ options[:action] = :print
+ elsif action.length == 1
+ if action[0].match /write|print/
+ options[:action] = action[0].intern
+ else
+ $stderr.puts "ACTION must be one of [print, write]"
+ $stderr.puts parser
+ exit 1
+ end
+ else
+ $stderr.puts parser
+ exit 1
+ end
+
+ options
+end
+
+# @return [String] The wwwdir value from /etc/mrepo.conf
+def default_www_root
+ contents = File.read '/etc/mrepo.conf'
+
+ if(m = contents.match /\s*wwwdir\s*=\s*(.*)/)
+ m[1]
+ end
+end
+
+def header
+ str = <<-EOT
+# This file is being managed by export-mrepo. It may stomp on any changes you make manually.
+# export-mrepo does not care if it crushes your changes, hopes, or dreams. export-mrepo is
+# a program. export-mrepo has no feelings and is merciless. See #{File.expand_path $0}
+# to understand why it is an unstoppable engine of destruction.
+ EOT
+end
+
+if $0 == __FILE__
+ opts = parse(ARGV)
+
+ nfs_opts = opts[:options].join(',')
+ paths = mount_list(opts[:www_root])
+
+ # Manually add the www_root to the export paths
+ paths << opts[:www_root]
+
+ lines = generate_exports(paths, opts[:clients], nfs_opts)
+
+ contents = [header, lines].join("\n")
+
+ if opts[:action] == :print
+ puts contents
+ elsif opts[:action] == :write
+ File.open('/etc/exports', 'w') do |fh|
+ fh.write contents
+ end
+ end
+end
View
@@ -0,0 +1,44 @@
+# This class configures NFS exporting of mrepo repository data.
+#
+# == Examples
+#
+# class { 'mrepo::exports':
+# clients => '10.10.0.0/24',
+# }
+#
+# == Author
+#
+# Adrien Thebo <adrien@puppetlabs.com>
+#
+# == Copyright
+#
+# Copyright 2012 Puppet Labs, unless otherwise noted
+#
+class mrepo::exports($clients) {
+ include mrepo::params
+
+ $file_path = '/usr/local/sbin/export-mrepo'
+
+ file { $file_path:
+ ensure => present,
+ source => 'puppet:///modules/mrepo/export-mrepo',
+ owner => '0',
+ group => '0',
+ mode => '0755',
+ }
+
+ if is_array($clients) {
+ $clients_real = inline_template('<%= scope.lookupvar("clients").map {|c| "-c #{c}"}.join(" ") %>')
+ }
+ else {
+ $clients_real = "-c ${clients}"
+ }
+
+ cron { "Export mrepo repositories":
+ command => "${file_path} ${clients_real} write",
+ ensure => present,
+ user => 'root',
+ minute => fqdn_rand(60),
+ require => File[$file_path],
+ }
+}
View
@@ -39,6 +39,10 @@
# [*rhn_password*]
# The Redhat Network password. Must be set if the param rhn is true.
#
+# [*mailto*]
+#
+# The email recipient for mrepo updates. Defaults to unset
+#
# == Examples
#
# node default {
@@ -70,7 +74,8 @@
$selinux = undef,
$rhn = false,
$rhn_username = undef,
- $rhn_password = undef
+ $rhn_password = undef,
+ $mailto = 'UNSET'
) {
validate_re($source, "^git$|^package$")
validate_bool($rhn)
View
@@ -1,12 +1,16 @@
# This file is managed by puppet. Any changes to this file will be
# overwritten the next time puppet runs. Update with caution!
[main]
-srcdir = <%= scope.lookupvar('mrepo::params::src_root') %>
-wwwdir = <%= scope.lookupvar('mrepo::params::www_root') %>
+srcdir = <%= scope.lookupvar('mrepo::params::src_root') %>
+wwwdir = <%= scope.lookupvar('mrepo::params::www_root') %>
confdir = /etc/mrepo.conf.d
<% if not scope.lookupvar('mrepo::params::rhn_username').empty? and not scope.lookupvar('mrepo::params::rhn_password').empty? -%>
rhnlogin = <%= scope.lookupvar('mrepo::params::rhn_username') %>:<%= scope.lookupvar('mrepo::params::rhn_password') %>
<% elsif not scope.lookupvar('mrepo::params::rhn_username').empty? -%>
rhnlogin = <%= scope.lookupvar('mrepo::params::rhn_username') %>
<% end -%>
+
+<% unless (mailto = scope.lookupvar('mrepo::params::mailto')) == 'UNSET' -%>
+mailto = <%= mailto %>
+<% end -%>

0 comments on commit 42b7827

Please sign in to comment.