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
Bridge-Domain name assigning case bridge-domain 100 name bd100.
- #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
- #default_fabric_control ⇒ Object
- #default_shutdown ⇒ Object
- #destroy ⇒ Object
-
#fabric_control ⇒ Object
Bridge-Domain type change to fabric-control bridge-domain 100 fabric-control 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
Bridge-Domain Shutdown case bridge-domain 100 shutdown.
- #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
Bridge-Domain name assigning case bridge-domain 100
name bd100
130 131 132 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 130 def bd_name config_get('bridge_domain', 'bd_name', bd: @bd_ids) end |
#bd_name=(str) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 134 def bd_name=(str) str = str.to_s 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
141 142 143 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 141 def default_bd_name config_get_default('bridge_domain', 'bd_name') end |
#default_fabric_control ⇒ Object
158 159 160 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 158 def default_fabric_control config_get_default('bridge_domain', 'fabric_control') end |
#default_shutdown ⇒ Object
174 175 176 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 174 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
Bridge-Domain type change to fabric-control bridge-domain 100
fabric-control
This type property can be defined only for one bd
149 150 151 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 149 def fabric_control config_get('bridge_domain', 'fabric_control', bd: @bd_ids) end |
#fabric_control=(val) ⇒ Object
153 154 155 156 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 153 def fabric_control=(val) state = (val) ? '' : 'no' config_set('bridge_domain', 'fabric_control', bd: @bd_ids, state: state) end |
#shutdown ⇒ Object
Bridge-Domain Shutdown case bridge-domain 100
shutdown
165 166 167 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 165 def shutdown config_get('bridge_domain', 'shutdown', bd: @bd_ids) end |
#shutdown=(val) ⇒ Object
169 170 171 172 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 169 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
179 180 181 |
# File 'lib/cisco_node_utils/bridge_domain.rb', line 179 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 |