class PuppetX::Eos::Ospf

The Ospf class provides a base class instance for working with instances of OSPF

Public Class Methods

new(api) click to toggle source

Initialize instance of Ospf

@param [PuppetX::Eos::Eapi] api An instance of Eapi

@return [PuppetX::Eos::Ospf]

# File lib/puppet_x/eos/modules/ospf.rb, line 50
def initialize(api)
  @api = api
end

Public Instance Methods

create(inst) click to toggle source

Creates a new instance of OSPF routing

@param [String] inst The instance id to create

@return [Boolean] True if the commands succeed otherwise False

# File lib/puppet_x/eos/modules/ospf.rb, line 81
def create(inst)
  @api.config("router ospf #{inst}") == [{}]
end
default(inst) click to toggle source

Defaults an instance of OSPF routing

@param [String] inst The instance id to delete

@return [Boolean] True if the commands succeed otherwise False

# File lib/puppet_x/eos/modules/ospf.rb, line 101
def default(inst)
  @api.config("default router ospf #{inst}") == [{}]
end
delete(inst) click to toggle source

Deletes an instance of OSPF routing

@param [String] inst The instance id to delete

@return [Boolean] True if the commands succeed otherwise False

# File lib/puppet_x/eos/modules/ospf.rb, line 91
def delete(inst)
  @api.config("no router ospf #{inst}") == [{}]
end
getall() click to toggle source

Returns the base interface hash representing physical and logical interfaces in EOS using eAPI

Example

{
  "instances": {
    "1": { "router_id": <String> }
  }
}

@return [Hash] returns an Hash

# File lib/puppet_x/eos/modules/ospf.rb, line 66
def getall
  result = @api.enable('show ip ospf')
  instances = {}
  result[0]['vrfs']['default']['instList'].map do |inst, attrs|
    instances[inst] = { router_id: attrs['routerId'] }
  end
  { instances: instances }
end
set_router_id(inst, opts = {}) click to toggle source

Configures the OSPF process router-id

@param [String] inst The instance of ospf to configure @param [Hash] opts The configuration parameters @option opts [string] :value The value to set the router-id to @option opts [Boolean] :default The value should be set to default

@return [Boolean] True if the commands succeed otherwise False

# File lib/puppet_x/eos/modules/ospf.rb, line 114
def set_router_id(inst, opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

  cmds = ["router ospf #{inst}"]
  case default
  when true
    cmds << 'default router-id'
  when false
    cmds << (value ? "router-id #{value}" : 'no router-id')
  end
  @api.config(cmds) == [{}, {}]
end