[Puppet Users] [ANN] Resource API v1.6.0 Release

2018-09-25 Thread David Schmitt
Hi all,

We're pleased to announce that version 1.6.0 of the Resource API is being
released today.

The Resource API provides a simple way to create new native resources in
the form of types and providers for Puppet. Using a little bit of ruby, you
can finally get rid of that brittle exec, or manage that one API that
eluded you until now.

It is provided as a Ruby gem to be referenced within modules. Support for
it has been included as an experimental feature in the Puppet Development
Kit (see pdk new provider --help). Use the resource_api module
 or the puppet 6 packages
 to deploy it in your
infrastructure.

The new release of the Resource API provides the following enhancements:

   - Allow SimpleProvider to handle composite namevars.
   - Implement allowances for device-specific providers.

The new release also contains the following notable changes:

   - Updates to the README
   - Add testing for supported puppet version branches

See the CHANGELOG

for a full list of changes.

We encourage all module developers to review the Resource API and use it
when creating types and providers. The README

gets you going quickly. To see some example code see this simple Philips
Hue type  or the Palo Alto firewall
module .

Please let us know of your experiences with the Resource API, either here,
on Slack  (#forge-modules), or on the github repo
.

Thanks, David Schmitt
-- 
Cheers, David

https://twitter.com/dev_el_ops

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CALF7fHa_j181LUf155HUyDzm%2BJ2cyb5LvZwipkGtdc25WZUAkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Custom type and provider

2018-09-25 Thread Rafael Tomelin
Hi,

Thanks, solved!

Em seg, 24 de set de 2018 às 04:40, David Schmitt 
escreveu:

> Hi Rafael,
>
> on puppet versions prior to puppet6, you need to install the
> puppet-resource_api gem to support the provider. You can use the
> puppetlabs-resource_api 
> module for that.
>
> Cheers, David
>
> On Sun, Sep 23, 2018 at 3:19 AM Rafael Tomelin 
> wrote:
>
>> Hi David Schmitt,
>>
>> I create de new module, class and provider with pdk the according this
>> site puppet.  My puppet is version 'puppet --version . 5.5.6'.
>>
>> But, the return error: *Could not autoload puppet/type/foo: no such file
>> to load -- puppet/resource_api *
>>
>>
>> *My type is:*
>>
>> *cat lib/puppet/type/foo.rb *
>>
>> require 'puppet/resource_api'
>>
>>
>> Puppet::ResourceApi.register_type(
>>
>>   name: 'foo',
>>
>>   docs: <<-EOS,
>>
>>   This type provides Puppet with the capabilities to manage ...
>>
>> EOS
>>
>>   features: [],
>>
>>   attributes:   {
>>
>> ensure:  {
>>
>>   type:'Enum[present, absent]',
>>
>>   desc:'Whether this resource should be present or absent on the
>> target system.',
>>
>>   default: 'present',
>>
>> },
>>
>> name:{
>>
>>   type:  'String',
>>
>>   desc:  'The name of the resource you want to manage.',
>>
>>   behaviour: :namevar,
>>
>> },
>>
>>   },
>>
>> )
>>
>>
>> *My provider:*
>>
>> *cat lib/puppet/provider/foo/foo.rb *
>>
>> require 'puppet/resource_api/simple_provider'
>>
>>
>> # Implementation for the foo type using the Resource API.
>>
>> class Puppet::Provider::Foo::Foo < Puppet::ResourceApi::SimpleProvider
>>
>>   def get(_context)
>>
>> [
>>
>>   {
>>
>> name: 'foo',
>>
>> ensure: 'present',
>>
>>   },
>>
>>   {
>>
>> name: 'bar',
>>
>> ensure: 'present',
>>
>>   },
>>
>> ]
>>
>>   end
>>
>>
>>   def create(context, name, should)
>>
>> context.notice("Creating '#{name}' with #{should.inspect}")
>>
>>   end
>>
>>
>>   def update(context, name, should)
>>
>> context.notice("Updating '#{name}' with #{should.inspect}")
>>
>>   end
>>
>>
>>   def delete(context, name)
>>
>> context.notice("Deleting '#{name}'")
>>
>>   end
>>
>> end
>>
>>
>> *My init.pp*
>>
>> *class first_type {*
>>
>>   foo{ 'my_type':
>>
>> ensure => present,
>>
>>   }
>>
>> }
>>
>>
>> What`s problem : *Could not autoload puppet/type/foo: no such file to
>> load -- puppet/resource_api *
>>
>> The provider write the ruby, is possible create provider with python? If
>> yes, is change ruby to python?
>>
>>
>>
>> Em sáb, 22 de set de 2018 às 05:29, David Schmitt <
>> david.schm...@puppet.com> escreveu:
>>
>>> Hi Rafael,
>>>
>>> if you are just starting out with this, I'd highly recommend looking
>>> into the Resource API. It makes the development of types much easier, is a
>>> supported part of this week's puppet 6 release, and available as a separate
>>> download for previous puppet versions. The PDK also has support for getting
>>> you started with a ready to go skeleton using 'pdk new provider'.
>>>
>>> See https://puppet.com/docs/puppet/6.0/custom_resources.html for all
>>> the details.
>>>
>>> Cheers, David
>>>
>>> On Fri, Sep 21, 2018 at 9:34 PM Rafael Tomelin 
>>> wrote:
>>>
 Hi guys,

 I am creating a type in custom provider, but I am not able to
 understand the following question.

 I created a basic type to understand the concept of things, as follows:
 Puppet::Type.newtype(:mydir) do
 @doc = "First custom type."

 ensurable do
 defaultvalues
 defaultto :present
 end

 newparam(:name, :namevar => true) do
 end

 newparam(:install_location) do
 end
 end


 After creating the provider, but does not recognize the same and
 displays the following error:
 Error: Could not find a suitable provider for mydir
 Notice: Applied catalog in 0.63 seconds

 Puppet::Type.type(:mydir).provide(:linux) do

 defaultfor :operatingsystem => :linux
 confine:operatingsystem => :linux

 commands :mkdir => "mkdir"
 commands :rm => "rm"

 def exists?
 Puppet.info("checking if is already deployed")
 deploy_dir = "#{resource[:install_location]}/#{resource[:name]}"

 File.directory?(deploy_dir) and Dir.entries(deploy_dir).size > 2
 end

 def create
 Puppet.info("Deploying the appliction")
 deploy_dir = "#{resource[:install_location]}/#{resource[:name]}"

 mkdir('-p', deploy_dir)
 end

 def destroy
 Puppet.info("Removing the appliction")
 deploy_dir = "#{resource[:install_location]}/#{resource[:name]}"
 rm('-rf',deploy_dir)
 end
 end

   What I did not envisage is how Puppet