summaryrefslogtreecommitdiffstats
path: root/manifests/mount.pp
blob: 2e842b1cda1873a2c0f6988a8ca32452633f0d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# GlusterFS module by James
# Copyright (C) 2010-2013+ James Shubin
# Written by James Shubin <james@shubin.ca>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# XXX: try mounting with: glusterfs --volfile-server=<server-address> --volfile-id=<volume-name> <mount-point> --xlator-option='*dht*.assert-no-child-down=yes' 	# TODO: quotes or not?
define gluster::mount(
	$server,		# NOTE: use a vip as server hostname
	$rw = false,		# mount read only (true) or rw (false)
#	$suid = false,		# mount with suid (true) or nosuid (false)	# TODO: will this work with gluster ?
	$mounted = true,	# useful if we want to pull in the group
				# defs, but not actually mount (testing)
	$repo = true,		# add a repo automatically? true or false
	$version = '',		# pick a specific version (defaults to latest)
	$ip = '',	# you can specify which ip address to use (if multiple)
	$shorewall = false
) {
	include gluster::params

	#mount -t glusterfs brick1.example.com:/test /test
	#include gluster::mount::base
	#class { '::gluster::mount::base':
	#	repo => $repo,
	#	version => $version,
	#}
	$params = {
		'repo' => $repo,
		'version' => $version,
	}
	# because multiple gluster::mount types are allowed on the same server,
	# we include with the ensure_resource function to avoid identical calls
	ensure_resource('class', 'gluster::mount::base', $params)

	# eg: vip:/volume
	$split = split($server, ':')	# do some $server parsing
	$host = $split[0]		# host fqdn or ip (eg: vip)
	# NOTE: technically $path should be everything BUT split[0]. This
	# lets our $path include colons if for some reason they're needed.
	#$path = $split[1]		# volume
	# TODO: create substring function
	$path = inline_template("<%= '${server}'.slice('${host}'.length+1, '${server}'.length-'${host}'.length-1) %>")
	$short_path = sprintf("%s", regsubst($path, '\/$', ''))	# no trailing
	#$valid_path = sprintf("%s/", regsubst($path, '\/$', ''))
	$volume = sprintf("%s", regsubst($short_path, '^\/', ''))	# no leading

	if ! ( "${host}:${path}" == "${server}" ) {
		fail('The $server must match a $host:$path pattern.')
	}

	if ! ( "${host}:/${volume}" == "${server}" ) {
		fail('The $server must match a $host:/$volume pattern.')
	}

	$short_name = sprintf("%s", regsubst("${name}", '\/$', ''))	# no trailing
	$long_name = sprintf("%s/", regsubst("${name}", '\/$', ''))	# trailing...

	$valid_ip = "${ip}" ? {
		'' => "${::gluster_host_ip}" ? {	# smart fact...
			'' => "${::ipaddress}",		# puppet picks!
			default => "${::gluster_host_ip}",	# smart
		},
		default => "${ip}",			# user selected
	}
	if "${valid_ip}" == '' {
		fail('No valid IP exists!')
	}

	if $shorewall {
		$safename = regsubst("${name}", '/', '_', 'G')	# make /'s safe
		@@shorewall::rule { "glusterd-management-${fqdn}-${safename}":
		#@@shorewall::rule { "glusterd-management-${volume}-${fqdn}":
			action => 'ACCEPT',
			source => '',	# override this on collect...
			source_ips => ["${valid_ip}"],
			dest => '$FW',
			proto => 'tcp',
			port => '24007',
			comment => 'Allow incoming tcp:24007 from each glusterd.',
			tag => 'gluster_firewall_management',
			ensure => present,
		}

		# wrap shorewall::rule in a fake type so that we can add $match
		#@@shorewall::rule { "gluster-volume-${fqdn}-${safename}":
		@@gluster::rulewrapper { "gluster-volume-${fqdn}-${safename}":
			action => 'ACCEPT',
			source => '',	# override this on collect...
			source_ips => ["${valid_ip}"],
			dest => '$FW',
			proto => 'tcp',
			port => '',	# override this on collect...
			#comment => "${fqdn}",
			comment => 'Allow incoming tcp port from glusterfsds.',
			tag => 'gluster_firewall_volume',
			match => "${volume}",	# used for collection
			ensure => present,
		}
	}

	$rw_bool = $rw ? {
		true => 'rw',
		default => 'ro',
	}

	# TODO: will this work with gluster ?
	#$suid_bool = $suid ? {
	#	true => 'suid',
	#	default => 'nosuid',
	#}

	$mounted_bool = $mounted ? {
		false => unmounted,
		default => mounted,
	}

	# ensure parent directories exist
	exec { "gluster-mount-mkdir-${name}":
		command => "/bin/mkdir -p '${long_name}'",
		creates => "${long_name}",
		logoutput => on_failure,
		before => File["${long_name}"],
	}

	# make an empty directory for the mount point
	file { "${long_name}":			# ensure a trailing slash
		ensure => directory,		# make sure this is a directory
		recurse => false,		# don't recurse into directory
		purge => false,			# don't purge unmanaged files
		force => false,			# don't purge subdirs and links
		alias => "${short_name}",	# don't allow duplicates name's
	}

	$packages = "${::gluster::params::package_glusterfs_fuse}" ? {
		'' => ["${::gluster::params::package_glusterfs}"],
		default => [
			"${::gluster::params::package_glusterfs}",
			"${::gluster::params::package_glusterfs_fuse}",
		],
	}
	# Mount Options:
	# * backupvolfile-server=server-name
	# * fetch-attempts=N (where N is number of attempts)
	# * log-level=loglevel
	# * log-file=logfile
	# * direct-io-mode=[enable|disable]
	# * ro (for readonly mounts)
	# * acl (for enabling posix-ACLs)
	# * worm (making the mount WORM - Write Once, Read Many type)
	# * selinux (enable selinux on GlusterFS mount)
	# XXX: consider mounting only if some exported resource, collected and turned into a fact shows that the volume is available...
	# XXX: or something... consider adding the notify => Poke[] functionality
	mount { "${short_name}":
		atboot => true,
		ensure => $mounted_bool,
		device => "${server}",
		fstype => 'glusterfs',
		options => "defaults,_netdev,${rw_bool}",	# TODO: will $suid_bool work with gluster ?
		dump => '0',		# fs_freq: 0 to skip file system dumps
		pass => '0',		# fs_passno: 0 to skip fsck on boot
		require => [
			Package[$packages],
			File["${long_name}"],		# the mountpoint
			Exec['gluster-fuse'],	# ensure fuse is loaded!
		],
	}
}

# vim: ts=8