Comments (11)
Mac.get_all()
should retrieve a dictionary with all the Macs in the system, keyed by the Mac index ("type,eui"). Also, note that get_all()
calls from_uri()
to instantiate the Mac, but it hasn't been materialized. You'll have to call get()
to retrieve the internal data of the entry (that's why the port is not there).
This should work:
macs = Mac.get_all()
for idx,mac in macs.items():
mac.get()
print(idx, mac.port)
from pyaoscx.
Two commas in dynamic,,00%.. ? But when I make direct call to the API it accepts also two ",,".
That's definitely an issue. It has to be fixed in the code.
from pyaoscx.
Hello,
thanks for your time :)
Mac.get_all() should retrieve a dictionary with all the Macs in the system,
But it wants a parent_vlan 1 ; so I'm thinking it will only get MACs of one VLANs?
It feels like I'm still missing something, still don't get any Mac objects with port attribute even after calling mac.get() before trying to get mac.port
allvlans = Vlan.get_all(sessio)
for vlan in allvlans:
vlanobject = Vlan(sessio, vlan)
macs = Mac.get_all(session=sessio, parent_vlan=vlanobject)
for idx,mac in macs.items():
macget = mac.get()
mac.get()
mac.port
from pyaoscx.
You don't need to retrieve all the VLANs, just use the parent_vlan
argument when retrieving the MACs:
vlan_id = 1 # This is the VLAN you're interested in
vlan = VLAN(session, vlan_id) # Create an unmaterialized VLAN
macs = MAC.get_all(session, vlan)
for idx,mac in macs.items();
mac.get() # Materialize the object from the device
print("%s -> %s" % (idx, mac))
It should really work. I don't see any reason why this is failing. Please, make sure to trace the log messages to validate that everything works as expected.
from pyaoscx.
Gotcha, I just looped over the VLANs because I didn't want to hard code in the VLAN ID. But for figuring this out good idea to reduce :)
Unfortunately using a single VLAN did not work either (fixed some minor things that looked like typos? in your reply (VLAN vs Vlan etc).
Below I kept some notes. But to me it looks like the extra payload like &selector=writable
that's being sent to the /macs/ endpoint is making the endpoint return an empty string (200 2).
In my direct urllib calls to "/macs/dynamic,MAC" I haven't set depth= and selector= at all. If I set ?selector=writable
it also returns "HTTP 200 2".
I tried to see if there was a way in _get_data to remove the selector but that led me down a rabbit hole I think.
But setting payload = {}
on objects with attribute mac_address resulted in a 404. I'm confused :)
I also made sure that this wasn't some issue with a specific MAC address and had it continue the loop over all MAC addresses. None of them had the port
attribute.
I've used the REST API version 10.08 and 10.04 same issue. Tried with pyaoscx 2.2.0 and 2.1.0 - did not print there either.
from pyaoscx.session import Session
from pyaoscx.vlan import Vlan
from pyaoscx.mac import Mac
switch_name = "CX6100.example.org"
sessio = Session(switch_name, "10.08")
password = "censored"
sessio.open("read-only-user-censored", password)
vlan_id = 1 # This is the VLAN you're interested in
vlan = Vlan(sessio, vlan_id) # Create an unmaterialized VLAN
macs = Mac.get_all(sessio, vlan)
for idx,mac in macs.items():
mac.get() # Materialize the object from the device
print("%s -> %s" % (idx, mac))
print("%s -> %s" % (idx, mac.port))
Prints
{'dynamic,00%3AAA%3ABB%3ACC%3ADD%3AEE': <pyaoscx.mac.Mac object at 0x7f3624f26100>, 'dynamic,1c... }
dynamic,00%3AAA%3ABB%3ACC%3ADD%3AEE -> 00:AA:BB:CC:DD:EE
Ran into exception: 'Mac' object has no attribute 'port'. Closing session.
Traceback (most recent call last):
File "example_mac.py", line 45, in get_aruba_macs
print("%s -> %s" % (idx, mac.port))
AttributeError: 'Mac' object has no attribute 'port'
Thanks for the idea of using the logging!
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): cx6100.example.org:443
DEBUG:urllib3.connectionpool:https://cx6100.example.org:443 "POST /rest/v10.08/login HTTP/1.1" 200 0
INFO:root:SUCCESS: Login succeeded
INFO:root:Retrieving all Mac data from switch
DEBUG:urllib3.connectionpool:https://cx6100.example.org:443 "GET /rest/v10.08/system/vlans/1/macs HTTP/1.1" 200 1458
INFO:root:Retrieving 00:AA:BB:CC:DD:EE from switch
DEBUG:urllib3.connectionpool:https://cx6100.example.org:443 "GET /rest/v10.08/system/vlans/1/macs/dynamic,,00%3AAA%3ABB%3ACC%3ADD%3AEE?depth=1&selector=writable HTTP/1.1" 200 2
DEBUG:urllib3.connectionpool:https://cx6100.example.org:443 "POST /rest/v10.08/logout HTTP/1.1" 200 0
INFO:root:SUCCESS: Logout succeeded
Something that stood out to me was:
- Two commas in
dynamic,,00%..
? But when I make direct call to the API it accepts also two ",,". depth=1
on what looks like themac.get()
call - but changing tomac.get(depth=2)
did not help.- setting depth=2 on the Vlan() did not help either but that was more of a long shot :)
- also materializing the Vlan did not help
- the HTTP status & size is
200 2
so it's accepted but it returns almost nothing? selector=writable
- maybe changing that.. But not sure to what.- configuration, status, statistics or writable didn't help either
- looks like it's just returning
{}
- if I change my workaround direct API call to call "vlans/1/macs/dynamic,00%3AAA%3ABB%3ACC%3ADD%3AEE?depth=1&selector=writable" it also doesn't print anything
from pyaoscx.
I have the same use case, and the same problem with the 'port' attribute now being available after mac.get()
:-)
from pyaoscx.
I have the same use case, and the same problem with the 'port' attribute now being available after mac.get()
Is that a typo? Now/Not?
from pyaoscx.
Two commas in dynamic,,00%.. ? But when I make direct call to the API it accepts also two ",,".
That's definitely an issue. It has to be fixed in the code.
Sorry I have not been able to reproduce this bit about double ",,".
I was however able to make the pyaoscx print ports!! See the changes in #19 (not really proposing them, just trying to show what made it work). The change sure feels ugly :)
Some other interesting things in the debug logs:
- even if we only call one VLAN, there are API calls to every VLAN/macs. Maybe this is somehow related to the Interface module. It happens also when using
Vlan.macs
from a materialized VLAN object. Maybe one reason why digging this data out can take a very long time with many MAC addresses?
from pyaoscx.
Hi, you can use selector='status' in the mac.get()
call to get the port information of the mac, the library was initially intended for configuration, so the default selector is 'writable', as you pointed out earlier, that does result in some gotchas for the modules that can't configure anything, I think the default selector for the module could be made into 'status'
instead of 'writable'
as a solution to the issue with the port, if you can reproduce the issue with the commas it'd be helpful to see where the issue lies, from the information you've provided it seem to me you're using a 6100, what version of the firmware does it have?
from pyaoscx.
Hello @dcorderohpe !
Cool!
With selector='status'
on the Mac.get() call I can make #19 work without setting the depth or selector to None.
Still need to set the Mac address to lower-case though.
if "macs" in self.path:
self.path = self.path.lower()
This CX6100 I'm using has ArubaOS-CX PL.10.09.0010
from pyaoscx.
Thanks @herodrig !
I tested out latest master branch that had the fix of d5c30e8 and I could get the ports nicely :) Thanks!
from pyaoscx.
Related Issues (20)
- please push 2.1 to pypi
- can't update vlan info HOT 2
- other objects, such as lldp ? HOT 1
- Unable to create a Loopback HOT 1
- Add TACACS/RADIUS Server Support
- aoscx_l3_interface fails on 6200 tries to fetch BGP details from sw that doesn't support BGP
- Connection via IPv6 using IP-Address fails HOT 1
- Extra slash in system.py functions HOT 3
- PoeInterface does not work HOT 5
- Firmware update fails HOT 7
- pyaoscx.mac.get_all not working when a VRRP is configured HOT 4
- Feature request: support for autocheckpoint
- API call functions don't have timeouts HOT 3
- Checkpoint support HOT 3
- Implement Ruff
- Reduce the amount of data retrieved to get C&Cs
- docs are not readable. HOT 1
- Push to PyPi HOT 1
- Interface configuration fails when Interface is attached to an VRF other than default HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyaoscx.