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) ⇒ InterfaceChannelGroup


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

def initialize(name)
  validate_args(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

Class Method Details

.interfacesObject


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 34

def self.interfaces
  hash = {}
  all = config_get('interface_channel_group', 'all_interfaces')
  return hash if all.nil?

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

Instance Method Details

#channel_groupObject


90
91
92
93
94
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 90

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 #


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

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


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 71

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


96
97
98
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 96

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

#default_channel_group_modeObject


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

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

#default_descriptionObject


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

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

#default_shutdownObject


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

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

#descriptionObject



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

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

#description=(desc) ⇒ Object


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

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


55
56
57
58
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 55

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

#shutdownObject



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

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

#shutdown=(state) ⇒ Object


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

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) ⇒ Object


46
47
48
49
50
51
52
53
# File 'lib/cisco_node_utils/interface_channel_group.rb', line 46

def validate_args(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
  set_args_keys
end