Lavaburn / puppet-mikrotik

Puppet Module for managing Mikrotik Devices
Apache License 2.0
9 stars 2 forks source link

Not compatible with recent puppet version #4

Closed timboven closed 3 years ago

timboven commented 5 years ago

I tried to use this code with a recent version of puppet but couldn't get it working (with the code as is). My Ruby is very limited but looks like something changed to the API related to the autoloader used in device.rb

I commented all the code related to the autoloader and let it just create the transport:

  def initialize(url, options = {})
    #@autoloader = Puppet::Util::Autoload.new(
    #  self,
    #  'puppet/util/network_device/transport'
    #)
    #if @autoloader.load('mikrotik', 'production')
      @transport = Puppet::Util::NetworkDevice::Transport::Mikrotik.new(url, options[:debug])
    #end
  end

With this modified version I was able to use this code with a recent version of puppet.

jimirocks commented 5 years ago

Hello, any plans to support puppet > 6 ?

Lavaburn commented 5 years ago

You can use the "puppet6" branch. I'll keep it in sync for now until I have time to look at correct implementation to support both.

philomory commented 5 years ago

I haven't tested this code to check for edge cases, but I believe something like the following will get you approximately the behavior of choosing the right branch based on what version of Puppet is being used:

def initialize(url, options = {})
  if Gem::Version.new(Puppet.version) >= Gem::Version.new("6.0.0")
    should_proceed = true
  else
    @autoloader = Puppet::Util::Autoload.new(
      self,
      'puppet/util/network_device/transport'
    )
    should_proceed = @autoloader.load('mikrotik', 'production')
  end
  if should_proceed
    @transport = Puppet::Util::NetworkDevice::Transport::Mikrotik.new(url, options[:debug])
  end
end
Lavaburn commented 3 years ago

I have added this code for backwards-compatibility, but not tested on Puppet 5.