Class: PuppetX::NetDev::EosApi

Inherits:
Object
  • Object
show all
Includes:
CommonMethods, SnmpMethods
Defined in:
lib/puppet_x/net_dev/eos_api.rb,
lib/puppet_x/net_dev/eos_api/version.rb,
lib/puppet_x/net_dev/eos_api/snmp_methods.rb,
lib/puppet_x/net_dev/eos_api/common_methods.rb

Overview

Eapi class

Defined Under Namespace

Modules: CommonMethods, SnmpMethods

Constant Summary collapse

VERSION =
'0.0.1'

Constants included from SnmpMethods

SnmpMethods::SNMP_USER_PARAM

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SnmpMethods

#parse_snmp_communities, #parse_snmp_enable, #parse_snmp_hosts, #parse_snmp_traps, #parse_snmp_users, #snmp_attributes, #snmp_communities, #snmp_community_destroy, #snmp_community_set, #snmp_contact, #snmp_contact=, #snmp_enable, #snmp_enable=, #snmp_location, #snmp_location=, #snmp_notification_receiver_remove, #snmp_notification_receiver_set, #snmp_notification_receivers, #snmp_notification_set, #snmp_notifications, #snmp_user_destroy, #snmp_user_password_hash, #snmp_user_set, #snmp_users

Methods included from CommonMethods

#running_config

Constructor Details

#initialize(opts = {}) ⇒ PuppetX::NetDev::EosApi

initialize an API instance. The API will communicate with the HTTP server over TCP or a Unix Domain Socket. If a unix domain socket is being used then the address parameter should be set to the socket path. The port, username, and password are not necessary.

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

Parameters:

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

    a customizable set of options

Options Hash (opts):

  • :address (String)

    The address to connect to the HTTP server. This can be a hostname, address or the full path to a unix domain socket in the form of ‘unix:///path/to/socket`.

  • :port (Fixnum)

    The TCP port for an IP connection to the HTTP API server.

  • :username (String) — default: 'admin'

    The username to log into the API server when using TCP/IP HTTP API connections. This option is not necessary when using a unix:// socket connection.

  • :password (String)

    The password to use to log into the API server.



65
66
67
68
69
70
# File 'lib/puppet_x/net_dev/eos_api.rb', line 65

def initialize(opts = {})
  @address = opts[:address] || ENV['EOS_HOSTNAME'] || 'unix:///var/run/command-api.sock'
  @port = opts[:port] || ENV['EOS_PORT'] || 80
  @username = opts[:username] || ENV['EOS_USERNAME'] || 'admin'
  @password = opts[:password] || ENV['EOS_PASSWORD'] || 'puppet'
end

Instance Attribute Details

#addressObject (readonly)

IP address or hostname of the REST api



29
30
31
# File 'lib/puppet_x/net_dev/eos_api.rb', line 29

def address
  @address
end

#passwordObject (readonly)

API password



35
36
37
# File 'lib/puppet_x/net_dev/eos_api.rb', line 35

def password
  @password
end

#portObject (readonly)

TCP port of the REST api



31
32
33
# File 'lib/puppet_x/net_dev/eos_api.rb', line 31

def port
  @port
end

#usernameObject (readonly)

API username



33
34
35
# File 'lib/puppet_x/net_dev/eos_api.rb', line 33

def username
  @username
end

Instance Method Details

#all_interfacesHash<String,Hash>

all_interfaces returns a hash of all interfaces

Returns:

  • (Hash<String,Hash>)

    where the key is the interface name, e.g. ‘Management1’



508
509
510
511
# File 'lib/puppet_x/net_dev/eos_api.rb', line 508

def all_interfaces
  result = eapi_action('show interfaces', 'list all interfaces')
  result.first['interfaces']
end

#all_portchannel_modesHash<String,Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

all_portchannel_modes returns a hash of each of the port channel LACP modes. This method could be merged with the data from the all_portchannels method.

Returns:

  • (Hash<String,Hash>)

    where the key is the port channel name, e.g. ‘Port-Channel10’



372
373
374
375
376
377
378
# File 'lib/puppet_x/net_dev/eos_api.rb', line 372

def all_portchannel_modes
  # JSON format is not supported in EOS 4.13.7M so use text format
  result = eapi_action('show port-channel summary', 'get lag modes',
                       format: 'text')
  text = result.first['output']
  parse_portchannel_modes(text)
end

#all_portchannelsHash<String,Hash>

all_portchannels returns a hash of all port channels based on multiple sources of data from the API.

Returns:

  • (Hash<String,Hash>)

    where the key is the port channel name, e.g. ‘Port-Channel10’



281
282
283
284
285
286
287
288
289
# File 'lib/puppet_x/net_dev/eos_api.rb', line 281

def all_portchannels
  detailed = all_portchannels_detailed
  modes = all_portchannel_modes
  # Merge the two
  detailed.each_with_object(Hash.new) do |(name, attr), hsh|
    hsh[name] = modes[name] ? attr.merge(modes[name]) : attr
    hsh[name]['minimum_links'] = portchannel_min_links(name)
  end
end

#all_portchannels_detailedHash<String,Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

all_portchannels_detailed returns a hash of all port channels based on the ‘show etherchannel detailed` command.

Returns:

  • (Hash<String,Hash>)

    where the key is the port channel name, e.g. ‘Port-Channel10’



355
356
357
358
359
360
361
# File 'lib/puppet_x/net_dev/eos_api.rb', line 355

def all_portchannels_detailed
  # JSON format is not supported in EOS 4.13.7M so use text format
  result = eapi_action('show etherchannel detailed', 'list port channels',
                       format: 'text')
  text = result.first['output']
  parse_portchannels(text)
end

#all_vlansHash<String,Hash>

all_vlans returns a hash of all vlans

Examples:

List all vlans

api.all_vlans
=> {
"1"=>{
  "status"=>"active",
  "name"=>"default",
  "interfaces"=>{
    "Ethernet2"=>{"privatePromoted"=>false},
    "Ethernet3"=>{"privatePromoted"=>false},
    "Ethernet1"=>{"privatePromoted"=>false},
    "Ethernet4"=>{"privatePromoted"=>false}},
  "dynamic"=>false},
"3110"=>{
  "status"=>"active",
  "name"=>"VLAN3110",
  "interfaces"=>{},
  "dynamic"=>false}}

Returns:

  • (Hash<String,Hash>)


268
269
270
271
# File 'lib/puppet_x/net_dev/eos_api.rb', line 268

def all_vlans
  result = eapi_action('show vlan', 'list all vlans')
  result.first['vlans']
end

#channel_group_create(name, opts) ⇒ Object

channel_group_create creates a channel group and associated port channel interface if the interface does not already exist.

Parameters:

  • name (String)

    The name of the port channel interface, e.g. ‘Port-Channel3’.

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :mode (Symbol) — default: :active, :passive, :disabled

    The LACP operating mode of the interface. Note, the only way to change the LACP mode is to delete the channel group and re-create the channel group.

  • :interfaces (Symbol) — default: ['Ethernet1', 'Ethernet2']

    The member interfaces of the channel group.



205
206
207
208
209
210
211
212
213
214
215
# File 'lib/puppet_x/net_dev/eos_api.rb', line 205

def channel_group_create(name, opts)
  channel_group = name.scan(/\d+/).first.to_i
  interfaces = [*opts[:interfaces]]
  if interfaces.empty?
    fail ArgumentError, 'Cannot create a channel group with no interfaces'
  end
  interfaces.each do |interface|
    set_opts = { mode: opts[:mode], group: channel_group }
    interface_set_channel_group(interface, set_opts)
  end
end

#channel_group_destroy(name) ⇒ Object

channel_group_destroy destroys a port channel group.

Parameters:

  • name (String)

    The port channel name, e.g ‘Port-Channel3’



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/puppet_x/net_dev/eos_api.rb', line 120

def channel_group_destroy(name)
  # Need to remove all interfaces from the channel group.
  port_channels = all_portchannels_detailed
  channel_group = port_channels[name]
  unless channel_group
    msg = "#{name} is not in #{port_channels.keys.inspect}"
    fail ArgumentError, msg
  end
  interfaces = channel_group['ports']
  interfaces.each { |iface| interface_unset_channel_group(iface) }
end

#format_error(data) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

format_error takes the value of the ‘error’ key from the EOS API response and formats the error strings into a string suitable for error messages.

Parameters:

  • data (Array<Hash>)

    Array of data from the API response, this will be lcoated in the sub-key api_response[‘data’]

Returns:

  • (String)

    the human readable error message



582
583
584
585
586
587
588
589
590
# File 'lib/puppet_x/net_dev/eos_api.rb', line 582

def format_error(data)
  if data
    data.each_with_object([]) do |i, ary|
      ary.push(*i['errors']) if i['errors']
    end.join(', ')
  else
    'unknown error'
  end
end

#get_flowcontrol(name) ⇒ Hash<Symbol,String>

get_flowcontrol obtains the configured flow_control send and receive values from the target device.

Parameters:

  • name (String)

    The interface name, e.g. ‘Ethernet1’

Returns:

  • (Hash<Symbol,String>)

    e.g. { send: ‘on’, receive: ‘off’ }



437
438
439
440
441
442
# File 'lib/puppet_x/net_dev/eos_api.rb', line 437

def get_flowcontrol(name)
  cmd = "show flowcontrol interface #{name}"
  result = eapi_action(cmd, 'get flowcontrol config', format: 'text')
  text = result.first['output']
  parse_flowcontrol_single(text)
end

#httpNetX::HttpUnix

http returns a memoized HTTP client instance conforming to the Net::HTTP interface.

Returns:

  • (NetX::HttpUnix)


599
600
601
# File 'lib/puppet_x/net_dev/eos_api.rb', line 599

def http
  @http ||= NetX::HTTPUnix.new(address, port)
end

#interface_set_channel_group(interface, opts) ⇒ Object

interface_set_channel_group configures an interface to be a member of a specified channel group ID.

Parameters:

  • interface (String)

    The interface name to add to the channel group, e.g. ‘Ethernet1’.

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :group (Fixnum)

    The group ID the interface will become a member of, e.g. 3.

  • :mode (Symbol) — default: :active, :passive, :disabled

    The LACP operating mode of the interface. Note, the only way to change the LACP mode is to delete the channel group and re-create the channel group.



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/puppet_x/net_dev/eos_api.rb', line 162

def interface_set_channel_group(interface, opts)
  channel_group = opts[:group]
  mode = case opts[:mode]
         when :active, :passive then opts[:mode]
         when :disabled then :on
         else fail ArgumentError, "Unknown LACP mode #{opts[:mode]}"
         end

  cmd = %w(enable configure) << "interface #{interface}"
  cmd << "channel-group #{channel_group} mode #{mode}"
  msg = "join #{interface} to channel group #{channel_group}"
  eapi_action(cmd, msg)
end

#interface_unset_channel_group(interface) ⇒ Object

interface_unset_channel_group removes a specific interface from all channel groups.

Parameters:

  • interface (String)

    The interface name to remove from its associated channel group, e.g. ‘Ethernet1’



140
141
142
143
144
# File 'lib/puppet_x/net_dev/eos_api.rb', line 140

def interface_unset_channel_group(interface)
  cmds = %w(enable configure) << "interface #{interface}"
  cmds << 'no channel-group'
  eapi_action(cmds, "remove #{interface} from channel group")
end

#parse_flowcontrol_single(text) ⇒ Hash<Symbol,String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

parse_flowcontrol_single parses the text output of the ‘show flowcontrol <interface>` command where there is a single entry for the named interface.

Port        Send FlowControl  Receive FlowControl  RxPause       TxPause
            admin    oper     admin    oper
----------  -------- -------- -------- --------    ------------- -------------
Et1         off      unknown  off      unknown     0             0

Parameters:

  • text (String)

    The text to parse

Returns:

  • (Hash<Symbol,String>)

    e.g. { send: ‘on’, receive: ‘off’ }



459
460
461
462
463
464
465
466
467
# File 'lib/puppet_x/net_dev/eos_api.rb', line 459

def parse_flowcontrol_single(text)
  re = /----\n(.*?)\s+(.*?)\s+.*?\s+(.*?)\s+.*\n/m
  mdata = re.match(text)
  if mdata
    { send: mdata[2], receive: mdata[3] }
  else
    fail ArgumentError, 'could not parse flowcontrol'
  end
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

parse_min_links takes the text from the ‘show running-config interfaces Port-ChannelX` API command and parses out the currently configured number of minimum links. If there is no min-links value we (safely) assume it is configured to 0. Example output is:

interface Port-Channel4
  description Office Backbone
  port-channel min-links 2

Parameters:

  • text (String)

    The raw text output from the API.

Returns:

  • (Fixnum)

    the number of minimum links



341
342
343
344
345
# File 'lib/puppet_x/net_dev/eos_api.rb', line 341

def parse_min_links(text)
  re = /min-links\s+(\d+)/m
  mdata = re.match(text)
  mdata ? mdata[1].to_i : 0
end

#parse_portchannel_active_ports(group_lines) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

parse_portchannel_active_ports takes a portchannel section from ‘show port-channel detailed` and parses all of the active ports from the section.

Parameters:

  • lines (Array<String>)

    Array of string lines for the section,

Returns:

  • (Array<String>)

    Array of string port names, e.g. [‘Ethernet1’, ‘Ethernet2’]



672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/puppet_x/net_dev/eos_api.rb', line 672

def parse_portchannel_active_ports(group_lines)
  lines = group_lines.dup
  # Check if there are no active ports
  mdata = /(No)? Active Ports/.match(lines.shift)
  return [] if mdata[1] # return if there are none
  lines.shift until /^\s*Port /.match(lines.first) || lines.empty?
  lines.shift(2) # heading line and ---- line
  # Read interfaces until the first blank line
  lines.each_with_object([]) do |l, a|
    l.chomp!
    break a if l.empty?
    a << l.split.first
  end
end

#parse_portchannel_configured_ports(group_lines) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

parse_portchannel_configured_ports takes a portchannel section from ‘show port-channel detailed` and parses all of the active ports from the section.

Parameters:

  • lines (Array<String>)

    Array of string lines for the section,

Returns:

  • (Array<String>)

    Array of string port names, e.g. [‘Ethernet1’, ‘Ethernet2’]



698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/puppet_x/net_dev/eos_api.rb', line 698

def parse_portchannel_configured_ports(group_lines)
  lines = group_lines.dup
  # Check if there are no active ports
  lines.shift until /inactive ports/.match(lines.first) || lines.empty?
  return [] if lines.empty?
  lines.shift(3)
  lines.each_with_object([]) do |l, a|
    l.chomp!
    break a if l.empty?
    a << l.split.first
  end
end

#parse_portchannel_modes(text) ⇒ Hash<String,Hash>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse the portchannel modes from the text of the ‘show port-channel summary` command. The following is an example of two channel groups, one static, one active.

rubocop:disable Metrics/LineLength, Metrics/MethodLength, Style/TrailingWhitespace

                 Flags
------------------------ ---------------------------- -------------------------
  a - LACP Active          p - LACP Passive           * - static fallback
  F - Fallback enabled     f - Fallback configured    ^ - individual fallback
  U - In Use               D - Down
  + - In-Sync              - - Out-of-Sync            i - incompatible with agg
  P - bundled in Po        s - suspended              G - Aggregable
  I - Individual           S - ShortTimeout           w - wait for agg

Number of channels in use: 1
Number of aggregators:1

   Port-Channel       Protocol    Ports
------------------ -------------- ----------------
   Po3(U)             Static       Et1(D) Et2(P)
   Po4(D)             LACP(a)      Et3(G-) Et4(G-)

Returns:

  • (Hash<String,Hash>)

    where the key is the port channel name, e.g. ‘Port-Channel10’



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/puppet_x/net_dev/eos_api.rb', line 408

def parse_portchannel_modes(text)
  lines = text.lines.each_with_object(Array.new) do |v, ary|
    ary << v.chomp if /^\s*Po\d/.match(v)
  end
  lines.each_with_object(Hash.new) do |line, hsh|
    mdata = /^\s+Po(\d+).*?\s+([a-zA-Z()0-9_-]+)/.match(line)
    idx = mdata[1]
    protocol = mdata[2]
    mode = case protocol
           when 'Static' then :disabled
           when /LACP/
             flags = /\((.*?)\)/.match(protocol)[1]
             if flags.include? 'p' then :passive
             elsif flags.include? 'a' then :active
             end
           end
    hsh["Port-Channel#{idx}"] = { 'mode' => mode }
  end
end

#port_channel_destroy(name) ⇒ Object

port_channel_destroy destroys a port channel interface and removes all interfaces from the channel group.

Parameters:

  • name (String)

    The name of the port channel interface, e.g ‘Port-Channel3’



184
185
186
187
# File 'lib/puppet_x/net_dev/eos_api.rb', line 184

def port_channel_destroy(name)
  cmds = %w(enable configure) << "no interface #{name}"
  eapi_action(cmds, "remove #{name}")
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

portchannel_min_links takes the name of a Port Channel interface and obtains the currently configured min-links value by parsing the text of the running configuration.

Returns:

  • (Fixnum)

    the minimum number of links for the channel group to become active.



300
301
302
303
304
305
306
307
# File 'lib/puppet_x/net_dev/eos_api.rb', line 300

def portchannel_min_links(name)
  api_commands = ['enable', "show running-config interfaces #{name}"]
  result = eapi_action(api_commands,
                       'obtain port channel min links value',
                       format: 'text')
  text = result[1]['output'] # skip over the enable command output.
  parse_min_links(text)
end

#set_flowcontrol_recv(name, value) ⇒ Object

set_flowcontrol_recv Configures a specific interface’s flow control

receive value.

Parameters:

  • name (String)

    The name of the interface to configure, e.g. ‘Ethernet1’

  • value (Symbol)

    the value to configure, e.g. ‘:on`, `:off`



495
496
497
498
499
# File 'lib/puppet_x/net_dev/eos_api.rb', line 495

def set_flowcontrol_recv(name, value)
  cmd = %w(enable configure) << "interface #{name}"
  cmd << "flowcontrol receive #{value}"
  eapi_action(cmd, 'configure flowcontrol receive')
end

#set_flowcontrol_send(name, value) ⇒ Object

set_flowcontrol_send Configures a specific interface’s flow control

send value.

Parameters:

  • name (String)

    The name of the interface to configure, e.g. ‘Ethernet1’

  • value (Symbol)

    the value to configure, e.g. ‘:on`, `:off`



479
480
481
482
483
# File 'lib/puppet_x/net_dev/eos_api.rb', line 479

def set_flowcontrol_send(name, value)
  cmd = %w(enable configure) << "interface #{name}"
  cmd << "flowcontrol send #{value}"
  eapi_action(cmd, 'configure flowcontrol send')
end

#set_interface_description(name, description) ⇒ Object

set_interface_description configures the description string for an interface.

Parameters:

  • name (String)

    The interface name, e.g. ‘Ethernet1’

  • description (String)

    The description to assign the interface.



536
537
538
539
540
# File 'lib/puppet_x/net_dev/eos_api.rb', line 536

def set_interface_description(name, description)
  cmd = %w(enable configure) << "interface #{name}"
  cmd << "description #{description}"
  eapi_action(cmd, "set interface #{name} description to #{description}")
end

#set_interface_mtu(name, mtu) ⇒ Object

set_interface_mtu configures the interface MTU

Parameters:

  • name (String)

    The interface name, e.g. ‘Ethernet1’

  • mtu (Fixnum)

    The interface mtu, e.g. 9000



565
566
567
568
569
# File 'lib/puppet_x/net_dev/eos_api.rb', line 565

def set_interface_mtu(name, mtu)
  cmd = %w(enable configure) << "interface #{name}"
  cmd << "mtu #{mtu}"
  eapi_action(cmd, "set interface #{name} mtu to #{mtu}")
end

#set_interface_speed(name, speed) ⇒ Object

set_interface_speed enable a network interface

Parameters:

  • name (String)

    The interface name, e.g. ‘Ethernet1’

  • speed (String)

    The interface state, e.g. ‘1000full’ or ‘40gfull’



551
552
553
554
555
# File 'lib/puppet_x/net_dev/eos_api.rb', line 551

def set_interface_speed(name, speed)
  cmd = %w(enable configure) << "interface #{name}"
  cmd << "speed forced #{speed}"
  eapi_action(cmd, "set interface #{name} speed to #{speed}")
end

#set_interface_state(name, state) ⇒ Object

set_interface_state enables or disables a network interface

Parameters:

  • name (String)

    The interface name, e.g. ‘Ethernet1’

  • state (String)

    The interface state, e.g. ‘no shutdown’ or ‘shutdown’



522
523
524
525
# File 'lib/puppet_x/net_dev/eos_api.rb', line 522

def set_interface_state(name, state)
  cmd = %w(enable configure) << "interface #{name}" << state
  eapi_action(cmd, "set interface #{name} state to #{state}")
end

set_portchannel_min_links Configures the minimum links value for a channel group.

Parameters:

  • name (String)

    The port channel name, e.g ‘Port-Channel4’.

  • min_links (Fixnum)

    The minimum number of active links for the channel group to be active.



319
320
321
322
323
324
# File 'lib/puppet_x/net_dev/eos_api.rb', line 319

def set_portchannel_min_links(name, min_links)
  cmd = %w(enable configure)
  cmd << "interface #{name}"
  cmd << "port-channel min-links #{min_links}"
  eapi_action(cmd, 'set port-channel min links')
end

#set_vlan_name(id, name) ⇒ Object

set_vlan_name assigns a name to a vlan

Parameters:

  • id (Integer)

    The vlan ID

  • name (String)

    The vlan name



225
226
227
228
# File 'lib/puppet_x/net_dev/eos_api.rb', line 225

def set_vlan_name(id, name)
  cmds = ['enable', 'configure', "vlan #{id}"] << "name #{name}"
  eapi_action(cmds, "set vlan #{id} name to #{name}")
end

#set_vlan_state(id, state) ⇒ Object

set_vlan_state set a vlan to the state specified

Parameters:

  • id (Integer)

    The vlan ID

  • state (String)

    The state of the vlan, e.g. ‘active’ or ‘suspend’



239
240
241
242
# File 'lib/puppet_x/net_dev/eos_api.rb', line 239

def set_vlan_state(id, state)
  cmds = ['enable', 'configure', "vlan #{id}"] << "state #{state}"
  eapi_action(cmds, "set vlan #{id} state to #{state}")
end

#uriURI

Returns the URI of the server.

Returns:

  • (URI)

    the URI of the server



825
826
827
828
829
830
831
832
# File 'lib/puppet_x/net_dev/eos_api.rb', line 825

def uri
  return @uri if @uri
  if username && password
    @uri = URI("http://#{username}:#{password}@#{address}:#{port}")
  else
    @uri = URI("http://#{address}:#{port}")
  end
end

#vlan(id) ⇒ nil, Hash<String,Hash>

vlan returns data about a specific VLAN identified by the VLAN ID number. This API call maps roughly to the ‘show vlan <id>` command. This method returns nil if no VLAN was found matching the ID provided.

Parameters:

  • id (Fixnum)

    The VLAN id to obtain information about.

Returns:

  • (nil, Hash<String,Hash>)

    Hash describing the VLAN attributes, or nil if no vlan was found matching the id provided. The format of this hash matches the format of #all_vlans



84
85
86
87
# File 'lib/puppet_x/net_dev/eos_api.rb', line 84

def vlan(id)
  result = eapi_action("show vlan #{id}", 'list vlans')
  result.first['vlans'] if result
end

#vlan_create(id) ⇒ Boolean

vlan_create creates a VLAN that does not yet exist on the target device.

Parameters:

  • id (Fixnum)

    The VLAN id to create

Returns:

  • (Boolean)

    true if the vlan was created



98
99
100
101
# File 'lib/puppet_x/net_dev/eos_api.rb', line 98

def vlan_create(id)
  cmds = ['enable', 'configure', "vlan #{id}"]
  eapi_action(cmds, "create vlan #{id}")
end

#vlan_destroy(id) ⇒ Object

vlan_destroy destroys a vlan

Parameters:

  • id (Integer)

    The VLAN ID to destroy



109
110
111
112
# File 'lib/puppet_x/net_dev/eos_api.rb', line 109

def vlan_destroy(id)
  cmds = ['enable', 'configure', "no vlan #{id}"]
  eapi_action(cmds, "destroy vlan #{id}")
end