Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit eefa219

Browse files
committed
add build_port_mac
1 parent d7fbbd0 commit eefa219

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/junos-ez/l1_ports.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ def build_list
5454
ifs.text.strip
5555
end
5656
end
57+
58+
def build_port_mac
59+
@port_mac = {}
60+
interfaces = @ndev.rpc.get_interface_information({
61+
:media => true,
62+
:terse => true,
63+
:interface_name => Junos::Ez::L1ports::IFS_NAME_FILTER
64+
})
65+
66+
interfaces.xpath('physical-interface').each do |interface|
67+
name= interface.xpath("name").text.strip
68+
mac_addr = interface.xpath("current-physical-address").text.strip
69+
@port_mac[name] = mac_addr
70+
end
71+
return @port_mac
72+
end
5773

5874
def build_catalog
5975
@catalog = {}

lib/junos-ez/provider.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def initialize( p_obj, name = nil, opts = {} )
8989

9090
@list = [] # array list of item names
9191
@catalog = {} # hash catalog of named items
92+
@port_mac = {} # hash of ports and its mac address
9293

9394
return unless @name
9495
# resources only from here ...
@@ -192,6 +193,15 @@ def catalog!
192193
@catalog.clear
193194
@catalog = build_catalog
194195
end
196+
197+
def port_mac
198+
@port_mac.empty? ? port_mac! : @port_mac
199+
end
200+
201+
def port_mac!
202+
@port_mac.clear
203+
@port_mac = build_port_mac
204+
end
195205

196206
### ---------------------------------------------------------------
197207
### CREATE methods

0 commit comments

Comments
 (0)