Class: Cisco::FabricpathTopo

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/fabricpath_topology.rb

Overview

node_utils class for fabricpath_topology

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(topo_id, instantiate = true) ⇒ FabricpathTopo

Returns a new instance of FabricpathTopo.



27
28
29
30
31
32
33
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 27

def initialize(topo_id, instantiate=true)
  @topo_id = topo_id.to_s
  fail ArgumentError, "Invalid value(non-numeric
                      Topo id #{@topo_id})" unless @topo_id[/^\d+$/]

  create if instantiate
end

Instance Attribute Details

#topo_idObject (readonly)

Returns the value of attribute topo_id.



25
26
27
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 25

def topo_id
  @topo_id
end

Class Method Details

.toposObject



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

def self.topos
  hash = {}
  feature = config_get('fabricpath', 'feature')
  return hash if feature.nil? || feature.to_sym != :enabled
  topo_list = config_get('fabricpath_topology', 'all_topos')
  return hash if topo_list.nil?

  topo_list.each do |id|
    hash[id] = FabricpathTopo.new(id, false)
  end
  hash
rescue Cisco::CliError => e
  # cmd will syntax reject when feature is not enabled
  raise unless e.clierror =~ /Syntax error/
  return {}
end

Instance Method Details

#createObject



52
53
54
55
56
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 52

def create
  fabricpath_feature_set(:enabled) unless :enabled == fabricpath_feature
  config_set('fabricpath_topology', 'create',
             topo_id: @topo_id) unless @topo_id == '0'
end

#default_member_vlansObject



90
91
92
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 90

def default_member_vlans
  config_get_default('fabricpath_topology', 'member_vlans')
end

#default_member_vnisObject



112
113
114
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 112

def default_member_vnis
  config_get_default('fabricpath_topology', 'member_vlans')
end

#default_topo_nameObject



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

def default_topo_name
  config_get_default('fabricpath_topology', 'description')
end

#destroyObject



58
59
60
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 58

def destroy
  config_set('fabricpath_topology', 'destroy', topo_id: @topo_id)
end

#fabricpath_featureObject



62
63
64
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 62

def fabricpath_feature
  FabricpathGlobal.fabricpath_feature
end

#fabricpath_feature_set(fabricpath_set) ⇒ Object



66
67
68
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 66

def fabricpath_feature_set(fabricpath_set)
  FabricpathGlobal.fabricpath_feature_set(fabricpath_set)
end

#member_vlansObject



70
71
72
73
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 70

def member_vlans
  config_get('fabricpath_topology', 'member_vlans',
             @topo_id).gsub(/\s+/, '')
end

#member_vlans=(str) ⇒ Object



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

def member_vlans=(str)
  if str.empty?
    state = 'no'
    range = ''
  else
    state = ''
    range = str
    # reset existing range since we don't want incremental sets
    config_set('fabricpath_topology', 'member_vlans', topo_id: @topo_id,
               state: 'no', vlan_range: '') if member_vlans != ''
  end
  config_set('fabricpath_topology', 'member_vlans', topo_id: @topo_id,
             state: state, vlan_range: range)
end

#member_vnisObject



94
95
96
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 94

def member_vnis
  config_get('fabricpath_topology', 'member_vnis', @topo_id).gsub(/\s+/, '')
end

#member_vnis=(str) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 98

def member_vnis=(str)
  debug "str is #{str} whose class is #{str.class}"
  str = str.join(',') unless str.empty?
  if str.empty?
    state = 'no'
    range = ''
  else
    state = ''
    range = str
  end
  config_set('fabricpath_topology', 'member_vnis', topo_id: @topo_id,
             state: state, vni_range: range)
end

#topo_nameObject



116
117
118
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 116

def topo_name
  config_get('fabricpath_topology', 'description', @topo_id)
end

#topo_name=(desc) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 120

def topo_name=(desc)
  fail TypeError unless desc.is_a?(String)
  if desc.empty?
    state = 'no'
    name = ''
  else
    state = ''
    name = desc
  end
  config_set('fabricpath_topology', 'description', topo_id: @topo_id,
             state: state, name: name)
end