Class: Cisco::InterfaceChannelGroup

Inherits:
NodeUtil
  • Object
show all
Defined in:
lib/cisco_node_utils/interface_channel_group.rb

Overview

Interface - node utility class for general interface config management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(name, show_name = nil) ⇒ InterfaceChannelGroup

Returns a new instance of InterfaceChannelGroup.



26
27
28
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 26

def initialize(name, show_name=nil)
  validate_args(name, show_name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 24

def name
  @name
end

#show_nameObject (readonly)

Returns the value of attribute show_name.



24
25
26
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 24

def show_name
  @show_name
end

Class Method Details

.interfaces(show_name = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 34

def self.interfaces(show_name=nil)
  hash = {}
  show_name = Utils.normalize_intf_pattern(show_name)
  begin
    all = config_get('interface_channel_group', 'all_interfaces',
                     show_name: show_name)
  rescue CliError => e
    raise unless show_name
    # ignore logical interfaces that do not exist
    debug 'InterfaceChannelGroup.interfaces ignoring CliError => ' + e.to_s
  end
  return hash if all.nil?

  all.each do |id|
    id = id.downcase
    hash[id] = InterfaceChannelGroup.new(id, show_name)
  end
  hash
end

Instance Method Details

#channel_groupObject



99
100
101
102
103
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 99

def channel_group
  match = config_get('interface_channel_group', 'channel_group', @get_args)
  return match unless match
  match[0].to_i
end

#channel_group_modeObject

PROPERTIES #



73
74
75
76
77
78
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 73

def channel_group_mode
  match = config_get('interface_channel_group', 'channel_group', @get_args)
  return match unless match
  mode = match[1].nil? ? default_channel_group_mode : match[1]
  mode
end

#channel_group_mode_set(group, mode = false) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 80

def channel_group_mode_set(group, mode=false)
  cgroup = channel_group
  set_args_keys(state: 'no', group: cgroup, force: '', mode: '', val: '')
  config_set('interface_channel_group', 'channel_group', @set_args) if
    cgroup
  return unless group
  mode = false if mode && mode.to_str == 'on'
  if mode
    Cisco::Feature.lacp_enable
    set_args_keys(state: '', group: group, force: 'force',
                  mode: 'mode', val: mode)
    config_set('interface_channel_group', 'channel_group', @set_args)
  else
    set_args_keys(state: '', group: group, force: 'force',
                  mode: '', val: '')
    config_set('interface_channel_group', 'channel_group', @set_args)
  end
end

#default_channel_groupObject



105
106
107
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 105

def default_channel_group
  config_get_default('interface_channel_group', 'channel_group')
end

#default_channel_group_modeObject



109
110
111
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 109

def default_channel_group_mode
  config_get_default('interface_channel_group', 'channel_group_mode')
end

#default_descriptionObject



124
125
126
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 124

def default_description
  config_get_default('interface_channel_group', 'description')
end

#default_shutdownObject



138
139
140
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 138

def default_shutdown
  config_get_default('interface_channel_group', 'shutdown')
end

#descriptionObject




114
115
116
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 114

def description
  config_get('interface_channel_group', 'description', @get_args)
end

#description=(desc) ⇒ Object



118
119
120
121
122
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 118

def description=(desc)
  state = desc.strip.empty? ? 'no' : ''
  config_set('interface_channel_group', 'description',
             set_args_keys(state: state, desc: desc))
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName



64
65
66
67
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 64

def set_args_keys(hash={}) # rubocop:disable Style/AccessorMethodName
  @get_args = { name: @name, show_name: @show_name }
  @set_args = @get_args.merge!(hash) unless hash.empty?
end

#shutdownObject




129
130
131
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 129

def shutdown
  config_get('interface_channel_group', 'shutdown', @get_args)
end

#shutdown=(state) ⇒ Object



133
134
135
136
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 133

def shutdown=(state)
  config_set('interface_channel_group', 'shutdown',
             set_args_keys(state: state ? '' : 'no'))
end

#to_sObject



30
31
32
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 30

def to_s
  "interface_channel_group #{name}"
end

#validate_args(name, show_name) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 54

def validate_args(name, show_name)
  fail TypeError unless name.is_a?(String)
  fail ArgumentError unless name.length > 0
  fail "channel_group is not supported on #{name}" unless
    name[/Ethernet/i]
  @name = name.downcase
  @show_name = show_name.nil? ? '' : Utils.normalize_intf_pattern(show_name)
  set_args_keys
end