Class: Cisco::BridgeDomain
- Defined in:
- lib/cisco_node_utils/bridge_domain.rb
Overview
node_utils class for bridge_domain
Instance Attribute Summary collapse
-
#bd_ids ⇒ Object
readonly
Returns the value of attribute bd_ids.
Class Method Summary collapse
-
.bd_ids_to_array(bdid_string) ⇒ Object
This will expand the string to a list of bds as integers.
-
.bd_list_to_string(bd_list) ⇒ Object
This method will generate a batched string if a list is passed as argument Input would be as [1,2,3,4,5,10,11,12,7,30,100,31,32] output will be 1-5,10-12,7,30,100,31-32.
- .bds ⇒ Object
Instance Method Summary collapse
-
#bd_name ⇒ Object
PROPERTIES #.
- #bd_name=(str) ⇒ Object
-
#create ⇒ Object
This function will first add bds to the system bridge-domain and then create the bds.
-
#default_bd_name ⇒ Object
This default getter is a bit different them most.
- #default_fabric_control ⇒ Object
- #default_shutdown ⇒ Object
- #destroy ⇒ Object
-
#fabric_control ⇒ Object
This type property can be defined only for one bd.
- #fabric_control=(val) ⇒ Object
-
#initialize(bds, instantiate = true) ⇒ BridgeDomain
constructor
A new instance of BridgeDomain.
- #shutdown ⇒ Object
- #shutdown=(val) ⇒ Object
-
#system_bridge_domain ⇒ Object
getter for system bridge-domain.
- #to_s ⇒ Object
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(bds, instantiate = true) ⇒ BridgeDomain
Returns a new instance of BridgeDomain.
27 28 29 30 31 32 33 34 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 27 def initialize(bds, instantiate=true) # Spaces are removed as bridge-domain cli doesn't accept value with # space @bd_ids = bds.to_s.gsub(/\s+/, '') fail 'bridge-domain value is empty' if @bd_ids.empty? # no empty strings create if instantiate end |
Instance Attribute Details
#bd_ids ⇒ Object (readonly)
Returns the value of attribute bd_ids.
25 26 27 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 25 def bd_ids @bd_ids end |
Class Method Details
.bd_ids_to_array(bdid_string) ⇒ Object
This will expand the string to a list of bds as integers
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 41 def self.bd_ids_to_array(bdid_string) list = [] narray = bdid_string.split(',') narray.each do |elem| if elem.include?('-') es = elem.gsub('-', '..') ea = es.split('..').map { |d| Integer(d) } er = ea[0]..ea[1] list << er.to_a else list << elem.to_i end end list.flatten end |
.bd_list_to_string(bd_list) ⇒ Object
This method will generate a batched string if a list is passed as argument Input would be as [1,2,3,4,5,10,11,12,7,30,100,31,32] output will be 1-5,10-12,7,30,100,31-32
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 61 def self.bd_list_to_string(bd_list) farray = bd_list.compact lranges = [] unless farray.empty? left = bd_list.first right = nil farray.each do |aelem| if right && aelem != right.succ if left == right lranges << left else lranges << Range.new(left, right) end left = aelem end right = aelem end if left == right lranges << left else lranges << Range.new(left, right) end end lranges.to_s.gsub('..', '-').delete('[').delete(']').delete(' ') end |
.bds ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 87 def self.bds hash = {} bd_list = config_get('bridge_domain', 'all_bds') return hash if bd_list.nil? final_bd_list = bd_list.map { |elem| BridgeDomain.bd_ids_to_array(elem) } .flatten.uniq.sort final_bd_list.each do |id| hash[id.to_s] = BridgeDomain.new(id, false) end hash end |
Instance Method Details
#bd_name ⇒ Object
PROPERTIES #
127 128 129 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 127 def bd_name config_get('bridge_domain', 'bd_name', bd: @bd_ids) end |
#bd_name=(str) ⇒ Object
131 132 133 134 135 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 131 def bd_name=(str) state = str.empty? ? 'no' : '' config_set('bridge_domain', 'bd_name', bd: @bd_ids, state: state, name: str) end |
#create ⇒ Object
This function will first add bds to the system bridge-domain and then create the bds. If bds already existing then just create. Else add the non added bds to system range first then create all. This is to avoid the idempotency issue as system add command throws error if a bd is already present in the system range.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 106 def create sys_bds_array = BridgeDomain.bd_ids_to_array(system_bridge_domain) inp_bds_array = BridgeDomain.bd_ids_to_array(@bd_ids) if (inp_bds_array - sys_bds_array).any? add_bds = BridgeDomain.bd_list_to_string(inp_bds_array - sys_bds_array) config_set('bridge_domain', 'system_bridge_domain', oper: 'add', bd: add_bds) end config_set('bridge_domain', 'create', bd: @bd_ids) end |
#default_bd_name ⇒ Object
This default getter is a bit different them most. When a brige-domain gets created it gets a default name assigned that follows the pattern ‘Bridge-DomainX’ where X is the bridge domain id (@bd_ids).
140 141 142 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 140 def default_bd_name 'Bridge-Domain' + @bd_ids end |
#default_fabric_control ⇒ Object
155 156 157 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 155 def default_fabric_control config_get_default('bridge_domain', 'fabric_control') end |
#default_shutdown ⇒ Object
169 170 171 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 169 def default_shutdown config_get_default('bridge_domain', 'shutdown') end |
#destroy ⇒ Object
117 118 119 120 121 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 117 def destroy config_set('bridge_domain', 'destroy', bd: @bd_ids) config_set('bridge_domain', 'system_bridge_domain', oper: 'remove', bd: @bd_ids) end |
#fabric_control ⇒ Object
This type property can be defined only for one bd
145 146 147 148 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 145 def fabric_control match = config_get('bridge_domain', 'fabric_control', bd: @bd_ids) match.to_s == @bd_ids ? true : false end |
#fabric_control=(val) ⇒ Object
150 151 152 153 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 150 def fabric_control=(val) state = (val) ? '' : 'no' config_set('bridge_domain', 'fabric_control', bd: @bd_ids, state: state) end |
#shutdown ⇒ Object
159 160 161 162 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 159 def shutdown match = config_get('bridge_domain', 'shutdown', bd: @bd_ids) match == 'Noshutdown' ? false : true end |
#shutdown=(val) ⇒ Object
164 165 166 167 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 164 def shutdown=(val) state = (val) ? '' : 'no' config_set('bridge_domain', 'shutdown', bd: @bd_ids, state: state) end |
#system_bridge_domain ⇒ Object
getter for system bridge-domain
174 175 176 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 174 def system_bridge_domain config_get('bridge_domain', 'system_bridge_domain') end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 36 def to_s "Bridge Domain #{bd_ids}" end |