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
config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show
Constructor Details
#initialize(topo_id, instantiate = true) ⇒ FabricpathTopo
Returns a new instance of FabricpathTopo.
27
28
29
30
31
32
33
34
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 27
def initialize(topo_id, instantiate=true)
@topo_id = topo_id.to_s
@set_params = {}
fail ArgumentError, "Invalid value(non-numeric
Topo id #{@topo_id})" unless @topo_id[/^\d+$/]
create if instantiate
end
|
Instance Attribute Details
#topo_id ⇒ Object
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
.topos ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 36
def self.topos
hash = {}
fabricpath = config_get('fabricpath', 'feature')
return hash if (:enabled != fabricpath.to_sym)
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
end
|
Instance Method Details
#cli_error_check(result) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 55
def cli_error_check(result)
fail result[2]['body'] unless result[2]['body'].empty?
end
|
#create ⇒ Object
49
50
51
52
53
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 49
def create
fabricpath_feature_set(:enabled) unless :enabled == fabricpath_feature
config_set('fabricpath_topology', 'create',
topo: @topo_id) unless @topo_id == '0'
end
|
#default_member_vlans ⇒ Object
121
122
123
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 121
def default_member_vlans
[]
end
|
#default_state ⇒ Object
86
87
88
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 86
def default_state
config_get_default('fabricpath_topology', 'state')
end
|
#default_topo_name ⇒ Object
146
147
148
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 146
def default_topo_name
config_get_default('fabricpath_topology', 'description')
end
|
#destroy ⇒ Object
63
64
65
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 63
def destroy
config_set('fabricpath_topology', 'destroy', topo: @topo_id)
end
|
#fabricpath_feature ⇒ Object
67
68
69
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 67
def fabricpath_feature
FabricpathGlobal.fabricpath_feature
end
|
#fabricpath_feature_set(fabricpath_set) ⇒ Object
71
72
73
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 71
def fabricpath_feature_set(fabricpath_set)
FabricpathGlobal.fabricpath_feature_set(fabricpath_set)
end
|
#member_vlans ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 90
def member_vlans
str = config_get('fabricpath_topology', 'member_vlans', @topo_id)
return [] if str == '--'
str.gsub!('-', '..')
if /,/.match(str)
str.split(/\s*,\s*/)
else
str.lines.to_a
end
end
|
#member_vlans=(str) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 101
def member_vlans=(str)
debug "str is #{str} whose class is #{str.class}"
@set_params = {}
str = str.join(',') unless str.empty?
if str.empty?
@set_params[:topo] = @topo_id
@set_params[:state] = 'no'
@set_params[:vlan_range] = ''
else
str.gsub!('..', '-')
@set_params[:topo] = @topo_id
@set_params[:state] = ''
@set_params[:vlan_range] = str
end
result = config_set('fabricpath_topology', 'member_vlans', @set_params)
cli_error_check(result)
rescue CliError => e
raise "[topo #{@topo_id}] '#{e.command}' : #{e.clierror}"
end
|
#state ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 75
def state
result = config_get('fabricpath_topology', 'state', @topo_id)
return default_state if result.nil?
case result
when /Up/
return 'up'
when /Down/
return 'default'
end
end
|
#topo_name ⇒ Object
125
126
127
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 125
def topo_name
config_get('fabricpath_topology', 'description', @topo_id)
end
|
#topo_name=(desc) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/cisco_node_utils/fabricpath_topology.rb', line 129
def topo_name=(desc)
fail TypeError unless desc.is_a?(String)
@set_params = {}
if desc.empty?
@set_params[:topo] = @topo_id
@set_params[:state] = 'no'
@set_params[:name] = ''
else
@set_params[:topo] = @topo_id
@set_params[:state] = ''
@set_params[:name] = desc
end
config_set('fabricpath_topology', 'description', @set_params)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|