Skip to content

Commit

Permalink
Add init class
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Apr 2, 2014
1 parent a08cd3d commit f914213
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git"
symlinks:
"lvm": "#{source_dir}"
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ rvm:
env:
matrix:
- PUPPET_GEM_VERSION="~> 2.7.0"
- PUPPET_GEM_VERSION="~> 3.0.0"
- PUPPET_GEM_VERSION="~> 3.1.0"
- PUPPET_GEM_VERSION="~> 3.2.0"
- PUPPET_GEM_VERSION="~> 3.3.0"
- PUPPET_GEM_VERSION="~> 3.4.0"
global:
matrix:
fast_finish: true
exclude:
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 1.8.7
Expand Down
112 changes: 85 additions & 27 deletions README.markdown → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,96 @@ looks something like:

Here's a simple working example:

physical_volume { '/dev/hdc':
ensure => present,
}

volume_group { 'myvg':
ensure => present,
physical_volumes => '/dev/hdc',
}

logical_volume { 'mylv':
ensure => present,
volume_group => 'myvg',
size => '20G',
}

filesystem { '/dev/myvg/mylv':
ensure => present,
fs_type => 'ext3',
options => '-b 4096 -E stride=32,stripe-width=64',
}
```puppet
physical_volume { '/dev/hdc':
ensure => present,
}
volume_group { 'myvg':
ensure => present,
physical_volumes => '/dev/hdc',
}
logical_volume { 'mylv':
ensure => present,
volume_group => 'myvg',
size => '20G',
}
filesystem { '/dev/myvg/mylv':
ensure => present,
fs_type => 'ext3',
options => '-b 4096 -E stride=32,stripe-width=64',
}
```

This simple 1 physical volume, 1 volume group, 1 logical volume case
is provided as a simple `volume` definition, as well. The above could
be shortened to be:

lvm::volume { 'mylv':
ensure => present,
vg => 'myvg',
pv => '/dev/hdc',
fstype => 'ext3',
size => '20G',
}
```puppet
lvm::volume { 'mylv':
ensure => present,
vg => 'myvg',
pv => '/dev/hdc',
fstype => 'ext3',
size => '20G',
}
```

You can also describe your Volume Group like this:

```puppet
class { 'lvm':
volume_groups => {
'myvg' => {
physical_volumes => [ '/dev/sda2', '/dev/sda3', ],
logical_volumes => {
'opt' => {'size' => '20G'},
'tmp' => {'size' => '1G' },
'usr' => {'size' => '3G' },
'var' => {'size' => '15G'},
'home' => {'size' => '5G' },
'backup' => {
'size' => '5G',
'mountpath' => '/var/backups',
'mountpath_require' => true,
},
},
},
},
}
```

This could be really convenient when used with hiera:

```puppet
include ::lvm
```
and
```
---
lvm::volume_groups:
myvg:
physical_volumes:
- /dev/sda2
- /dev/sda3
logical_volumes:
opt:
size: 20G
tmp:
size: 1G
usr:
size: 3G
var:
size: 15G
home:
size: 5G
backup:
size: 5G
mountpath: /var/backups
mountpath_require: true
```

Except that in the latter case you cannot specify create options.
=======
Expand Down
7 changes: 7 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class lvm(
$volume_groups = {},
) {
validate_hash($volume_groups)

create_resources('lvm::volume_group', $volume_groups)
}
58 changes: 58 additions & 0 deletions manifests/logical_volume.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
define lvm::logical_volume(
$volume_group,
$size,
$ensure = present,
$options = 'defaults',
$fs_type = 'ext4',
$mountpath = "/${name}",
$mountpath_require = false,
) {
validate_bool($mountpath_require)

if $mountpath_require {
Mount {
require => File[$mountpath],
}
}

$mount_ensure = $ensure ? {
'absent' => absent,
default => mounted,
}

if $ensure == 'present' {
Logical_volume[$name] ->
Filesystem["/dev/${volume_group}/${name}"] ->
Mount[$mountpath]
} else {
Mount[$mountpath] ->
Filesystem["/dev/${volume_group}/${name}"] ->
Logical_volume[$name]
}

logical_volume { $name:
ensure => $ensure,
volume_group => $volume_group,
size => $size,
}

filesystem {"/dev/${volume_group}/${name}":
ensure => $ensure,
fs_type => $fs_type,
}

exec { "ensure mountpoint '${mountpath}' exists":
command => "mkdir -p ${mountpath}",
unless => "test -d ${mountpath}",
} ->
mount {$mountpath:
ensure => $mount_ensure,
device => "/dev/${volume_group}/${name}",
fstype => $fs_type,
options => $options,
pass => 2,
dump => 1,
atboot => true,
}

}
25 changes: 25 additions & 0 deletions manifests/volume_group.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define lvm::volume_group(
$physical_volumes,
$ensure = present,
$logical_volumes = {},
) {
validate_hash($logical_volumes)

physical_volume { $physical_volumes:
ensure => $ensure,
}

volume_group { $name:
ensure => $ensure,
physical_volumes => $physical_volumes,
}

create_resources(
'lvm::logical_volume',
$logical_volumes,
{
ensure => $ensure,
volume_group => $name,
}
)
}
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'pathname'
dir = Pathname.new(__FILE__).parent
$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
Expand Down
54 changes: 54 additions & 0 deletions spec/unit/classes/lvm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

describe 'lvm', :type => :class do

describe 'with no parameters' do
it { should compile.with_all_deps }
end

describe 'with volume groups' do
let(:params) do
{
:volume_groups => {
'myvg' => {
'physical_volumes' => [ '/dev/sda2', '/dev/sda3', ],
'logical_volumes' => {
'opt' => {'size' => '20G'},
'tmp' => {'size' => '1G' },
'usr' => {'size' => '3G' },
'var' => {'size' => '15G'},
'home' => {'size' => '5G' },
'backup' => {
'size' => '5G',
'mountpath' => '/var/backups',
'mountpath_require' => true
}
}
}
}
}
end

it { should contain_physical_volume('/dev/sda2') }
it { should contain_physical_volume('/dev/sda3') }
it { should contain_volume_group('myvg').with({
:ensure => 'present',
:physical_volumes => [ '/dev/sda2', '/dev/sda3', ]
}) }

it { should contain_logical_volume('opt').with( {
:volume_group => 'myvg',
:size => '20G'
}) }
it { should contain_filesystem('/dev/myvg/opt') }
it { should contain_mount('/opt') }

it { should contain_logical_volume('backup').with({
:volume_group => 'myvg',
:size => '5G'
}) }
it { should contain_filesystem('/dev/myvg/backup') }
it { should contain_mount('/var/backups') }
end

end

0 comments on commit f914213

Please sign in to comment.