My first type/provider - does nothing...

20 views
Skip to first unread message

Daniel Kerwin

unread,
Feb 15, 2010, 12:30:04 PM2/15/10
to Puppet Users
Hi list,

i tried to write my first type and provider that should create logical
volumes. Seems like i'm missing something as i get nothing when i use
it: No errors and no logical volume :-(

type/logicalvolume.rb:
=================

Puppet::Type.newtype(:logicalvolume) do
@doc = "Manage logical volumes"

ensurable

newparam(:lvname) do
desc "The logcal volume's name"

validate do |value|
unless value =~ /^[a-z0-9]+/
raise ArgumentError , "%s is not a valid lv name" %
value
end
end

isnamevar

end

newparam(:size) do
desc "The size in M or G"

validate do |value|
unless value =~ /^[0-9]+[MG]/
raise ArgumentError , "%s is not a valid lv size" %
value
end
end
end

newparam(:vg) do
desc "The volumevg to create the volume in"

validate do |value|
unless value =~ /^[a-z0-9]+/
raise ArgumentError , "%s is not a valid lv name" %
value
end
end
end
end

provider/logicalvolume/logicalvolume.rb
===============================

Puppet::Type.type(:logicalvolume).provide(:logicalvolume) do
desc "LogicalVolume management"

commands :lvcreate => "lvcreate"

def create
lvcreate "-L", resource[:size], "-n", resource[:name],
resource[:vg]
end

def destroy
return true
end

def exists?
return nil
end
end

Test class Bozo
=============

class bozo {

logicalvolume { "test01lv":
size => "100M",
vg => "datavg",
#provider => "logicalvolume",
}

file { "/tmp/lvtest":
content => "aaa",
}
}

The file is created and no notice about the volume. I checken my type
and provider and it seems to be ok:

ruby -rpuppet type/logicalvolume.rb
ruby -rpuppet provider/logicalvolume/logicalvolume.rb

It's my first try and it may be obvious to you but i just don't get
it.

Thanks,

Daniel

Nigel Kersten

unread,
Feb 16, 2010, 10:55:37 AM2/16/10
to puppet...@googlegroups.com
On Mon, Feb 15, 2010 at 9:30 AM, Daniel Kerwin <d.k3...@googlemail.com> wrote:
> Hi list,
>
> i tried to write my first type and provider that should create logical
> volumes. Seems like i'm missing something as i get nothing when i use
> it: No errors and no logical volume :-(

This might be better for puppet-dev.

It looks to me like you need to provide some properties, not just
parameters, in your type.

So this should return true or false.

If exists? is false and ensure is present, then create will be called.
If exists? is true and ensure is absent, then destroy will be called.

if you make size and vg properties rather than parameters, then:

a method called 'size' will be called to determine the current size
a method called 'size=' will be called to set the current size if the
desired and current size values differ.
a method called 'vg' will be called to determine the current vg
a method called 'vg=' will be called to set the current vg if the
desired and current vg values differ.

Does that make more sense?

> end
>
> Test class Bozo
> =============
>
> class bozo {
>
>    logicalvolume { "test01lv":
>        size => "100M",
>        vg   => "datavg",
>        #provider => "logicalvolume",
>    }
>
>    file { "/tmp/lvtest":
>        content => "aaa",
>    }
> }
>
> The file is created and no notice about the volume. I checken my type
> and provider and it seems to be ok:
>
> ruby -rpuppet type/logicalvolume.rb
> ruby -rpuppet provider/logicalvolume/logicalvolume.rb
>
> It's my first try and it may be obvious to you but i just don't get
> it.
>
> Thanks,
>
> Daniel
>

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
>

--
nigel

Marcin Owsiany

unread,
Feb 17, 2010, 12:50:26 PM2/17/10
to Puppet Users
Hello,

On Mon, Feb 15, 2010 at 09:30:04AM -0800, Daniel Kerwin wrote:
> i tried to write my first type and provider that should create logical
> volumes. Seems like i'm missing something as i get nothing when i use
> it: No errors and no logical volume :-(

This is not exactly what you're looking for, but I've written a simple
LVM type and an associated provider a long time ago, I'm attaching it
here together with a somewhat related "filesystem" type and provider.

I've been meaning to clean them up, write tests and properly contribute
to the project for literally years now. I guess if I don't take the
opportunity to send it out now, the code might never see daylight.

I hope someone finds it useful, and perhaps even give it some love.
It's been quite a while since I used them, so I'm not sure if they work
with modern puppet.

--
Marcin Owsiany <mar...@owsiany.pl> http://marcin.owsiany.pl/
GnuPG: 1024D/60F41216 FE67 DA2D 0ACA FC5E 3F75 D6F6 3A0D 8AA0 60F4 1216

"Every program in development at MIT expands until it can read mail."
-- Unknown

lv.rb
lvm2.rb
filesystem.rb
mkfs.rb

Daniel

unread,
Feb 17, 2010, 1:46:46 PM2/17/10
to puppet...@googlegroups.com
Thanks for your code. I'll have a look at it. i still need a mkfs
provider and your code may be the starting point.

My code actually works now (ensure was required!) and i'll post it to
the dev list to get some suggestions. These are the currently working
operations:

- Create volume
- Extend volume (Extend size is verified)
- Delete volume

The only missing feature (so far) is to verify that enough space in
the VG is left to actually extend the volume.

--

Cheers,

Daniel

Reply all
Reply to author
Forward
0 new messages