Class: PuppetX::Eos::Ospf

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/eos/modules/ospf.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ PuppetX::Eos::Ospf

Initialize instance of Ospf

Parameters:



50
51
52
# File 'lib/puppet_x/eos/modules/ospf.rb', line 50

def initialize(api)
  @api = api
end

Instance Method Details

#create(inst) ⇒ Boolean

Creates a new instance of OSPF routing

Parameters:

  • inst (String)

    The instance id to create

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



81
82
83
# File 'lib/puppet_x/eos/modules/ospf.rb', line 81

def create(inst)
  @api.config("router ospf #{inst}") == [{}]
end

#default(inst) ⇒ Boolean

Defaults an instance of OSPF routing

Parameters:

  • inst (String)

    The instance id to delete

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



101
102
103
# File 'lib/puppet_x/eos/modules/ospf.rb', line 101

def default(inst)
  @api.config("default router ospf #{inst}") == [{}]
end

#delete(inst) ⇒ Boolean

Deletes an instance of OSPF routing

Parameters:

  • inst (String)

    The instance id to delete

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



91
92
93
# File 'lib/puppet_x/eos/modules/ospf.rb', line 91

def delete(inst)
  @api.config("no router ospf #{inst}") == [{}]
end

#getallHash

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

Example

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

Returns:

  • (Hash)

    returns an Hash



66
67
68
69
70
71
72
73
# 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 = {}) ⇒ Boolean

Configures the OSPF process router-id

Parameters:

  • inst (String)

    The instance of ospf to configure

  • opts (Hash) (defaults to: {})

    The configuration parameters

Options Hash (opts):

  • :value (string)

    The value to set the router-id to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



114
115
116
117
118
119
120
121
122
123
124
125
126
# 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