module PuppetX::Eos::EapiProviderMixin

EapiProviderMixin module

Public Instance Methods

node() click to toggle source

Instance of Rbeapi::Client::Node used to sending and receiving eAPI messages. In addition, the node object provides access to Ruby Client for eAPI API modules used to configure EOS resources.

@return [Node] An instance of Rbeapi::Client::Node used to send

and receive eAPI messages
# File lib/puppet_x/eos/provider.rb, line 60
def node
  return @node if @node
  Rbeapi::Client.load_config(ENV['RBEAPI_CONF']) if ENV['RBEAPI_CONF']
  connection_name = ENV['RBEAPI_CONNECTION'] || 'localhost'
  @node = Rbeapi::Client.connect_to(connection_name)
end
prefetch(resources) click to toggle source
# File lib/puppet_x/eos/provider.rb, line 43
def prefetch(resources)
  provider_hash = instances.each_with_object({}) do |provider, hsh|
    hsh[provider.name] = provider
  end

  resources.each_pair do |name, resource|
    resource.provider = provider_hash[name] if provider_hash[name]
  end
end

Private Instance Methods

validate(req, opts = {}) click to toggle source

validate checkes the set of opts that have been configured for a resource against the required options. If any of the required options are missing, this method will fail.

@api private

@param [Hash] :opts The set of options configured on the resource

@param [Array] :req The set of required option keys

# File lib/puppet_x/eos/provider.rb, line 77
def validate(req, opts = {})
  missing = req.reject { |k| opts[k] }
  errors = !missing.empty?
  msg = "Invalid options #{opts.inspect} missing: #{missing.join(', ')}"
  fail Puppet::Error, msg if errors
end