Class: PuppetX::Eos::Mlag

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

Overview

The Mlag class provides a base class instance for working with the global mlag configuration

Instance Method Summary collapse

Constructor Details

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

Initialize instance of Snmp

Parameters:



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

def initialize(api)
  @api = api
end

Instance Method Details

#add_interface(name, id) ⇒ Boolean

Adds a new interface to the MLAG domain with specified Mlag id

Parameters:

  • name (String)

    The name of the interface to add

  • id (String)

    The MLAG ID to assign to the interface

Returns:

  • (Boolean)

    True if the command succeeds otherwise False



120
121
122
# File 'lib/puppet_x/eos/modules/mlag.rb', line 120

def add_interface(name, id)
  @api.config(["interface #{name}", "mlag #{id}"]) == [{}, {}]
end

#create(name) ⇒ Boolean

Creates a new mlag instance

Parameters:

  • name (String)

    The domain id of the mlag instance

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



85
86
87
# File 'lib/puppet_x/eos/modules/mlag.rb', line 85

def create(name)
  @api.config(['mlag configuration', "domain-id #{name}"]) == [{}, {}]
end

#defaultBoolean

Defaults the current mlag configuration

Returns:

  • (Boolean)

    True if the command succeeds otherwise False



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

def default
  @api.config('default mlag configuration') == [{}]
end

#deleteBoolean

Deletes the current mlag configuration from the running-config

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



93
94
95
# File 'lib/puppet_x/eos/modules/mlag.rb', line 93

def delete
  @api.config('no mlag configuration') == [{}]
end

#getArray<Hash>

Returns the Mlag hash representing global snmp configuration

Example

{
  "domain_id": <String>,
  "local_interface": <String>,
  "peer_address": <String>,
  "peer_link": <String>,
  "enable": [true, false]
}

Returns:

  • (Array<Hash>)

    returns a Hash of attributes derived from eAPI



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/puppet_x/eos/modules/mlag.rb', line 67

def get
  result = @api.enable('show mlag')
  attr_hash = {
    domain_id: result[0]['domainId'],
    peer_link: result[0]['peerLink'],
    local_interface: result[0]['localInterface'],
    peer_address: result[0]['peerAddress'],
    enable: result[0]['state'] == 'disabled' ? :false : :true
  }
  attr_hash
end

#get_interfacesArray<Hash>

Retrieves the interfaces that are mlag enabled from the running-config

Returns:

  • (Array<Hash>)

    returns an Array of Hashes keyed by the mlag id



109
110
111
# File 'lib/puppet_x/eos/modules/mlag.rb', line 109

def get_interfaces
  @api.enable('show mlag interfaces')
end

#remove_interface(name) ⇒ Boolean

Removes a previously configured interface from the Mlag domain

Parameters:

  • name (String)

    The name of the interface to remove

Returns:

  • (Boolean)

    True if the command succeeds otherwise False



130
131
132
# File 'lib/puppet_x/eos/modules/mlag.rb', line 130

def remove_interface(name)
  @api.config(["interface #{name}", 'no mlag']) == [{},  {}]
end

#set_domain_id(opts = {}) ⇒ Boolean

Configures the mlag domain_id

Parameters:

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

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the domain-id to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/puppet_x/eos/modules/mlag.rb', line 165

def set_domain_id(opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

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

#set_local_interface(opts = {}) ⇒ Boolean

Configures the mlag local_interface

Parameters:

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

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the local-interface to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/puppet_x/eos/modules/mlag.rb', line 231

def set_local_interface(opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

  cmds = ['mlag configuration']
  case default
  when true
    cmds << 'default local-interface'
  when false
    cmds << (value ? "local-interface #{value}" : 'no local-interface')
  end
  @api.config(cmds) == [{}, {}]
end

#set_mlag_id(name, opts = {}) ⇒ Boolean

Configures the mlag id for an interface

Parameters:

  • name (String)

    The interface to configure

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

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the interface mlag id

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/puppet_x/eos/modules/mlag.rb', line 143

def set_mlag_id(name, opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

  cmds = ["interface #{name}"]
  case default
  when true
    cmds << 'default mlag'
  when false
    cmds << (value ? "mlag #{value}" : 'no mlag')
  end
  @api.config(cmds) == [{}, {}]
end

#set_peer_address(opts = {}) ⇒ Boolean

Configures the mlag peer_address

Parameters:

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

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the peer-address to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/puppet_x/eos/modules/mlag.rb', line 209

def set_peer_address(opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

  cmds = ['mlag configuration']
  case default
  when true
    cmds << 'default peer-address'
  when false
    cmds << (value ? "peer-address #{value}" : 'no peer-address')
  end
  @api.config(cmds) == [{}, {}]
end

Configures the mlag peer_link

Parameters:

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

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the peer-link to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/puppet_x/eos/modules/mlag.rb', line 187

def set_peer_link(opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

  cmds = ['mlag configuration']
  case default
  when true
    cmds << 'default peer-link'
  when false
    cmds << (value ? "peer-link #{value}" : 'no peer-link')
  end
  @api.config(cmds) == [{}, {}]
end

#set_shutdown(opts = {}) ⇒ Boolean

Configures the mlag operational state

Parameters:

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

    The configuration parameters for mlag

Options Hash (opts):

  • :value (string)

    The value to set the state to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/puppet_x/eos/modules/mlag.rb', line 253

def set_shutdown(opts = {})
  value = opts[:value] || false
  default = opts[:default] || false

  cmds = ['mlag configuration']
  case default
  when true
    cmds << 'default shutdown'
  when false
    cmds << (value ? 'shutdown' : 'no shutdown')
  end
  @api.config(cmds) == [{}, {}]
end