Replies: 1 comment 1 reply
-
The /dcim/virtual-chassis record only returns a reference to the main/master device (which is the one you log into over the network to manage the stack) but you can query /dcim/devices to get the device data for all the members by filtering on the virtual-chassis ID, eg. /dcim/devices/?virtual_chassis_id=1234
You can also get the virtual_chassis id from one of the member device records in the REST API to look up all the partner devices.
It works the way you describe, and you need to design your queries to take into account the way the db records are organized.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: nokutaces ***@***.***>
Sent: Monday, September 25, 2023 8:35 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Get menbers from virtual chassis (Discussion #13882)
Hello,
I'm try to get all member switches from a virtual_chassis
I get the master device in the virtual chassis but not the second or third device.
for example:
vc_s = nb.dcim.virtual_chassis.get(2)
pprint.pprint(dict(vc_s))
result:
{'comments': '',
'created': '2023-09-23T18:06:22.507185+02:00',
'custom_fields': {},
'description': '',
'display': 'sw-we-VC',
'domain': '123',
'id': 2,
'last_updated': '2023-09-24T12:48:23.331332+02:00',
'master': {'display': 'sw-we',
'id': 11,
'name': 'sw-we',
'url': 'http://netbox.xxx.local/api/dcim/devices/11/'}<http://netbox.xxx.local/api/dcim/devices/11/'%7D>,
'member_count': 2,
'name': 'sw-we-VC',
'tags': [],
'url': 'http://netbox.xxx.local/api/dcim/virtual-chassis/2/'
}
the goal ist to print the mebers and later there interfaces:
I have to itterate over all devices to find all switches
Is there is a better way to find the devices fron a virtual device?
Could someone put me to the right track.
x = nb.dcim.devices.all()
for dev in x:
if dev.virtual_chassis:
vchassi = dev.virtual_chassis.name
if vchassi.startswith('sw-ee-as-203'):
print(dev.name)
print(vchassi)
Result:
sw-ee-as-203
sw-ee-as-203-VC
sw-ee-as-203-2
sw-ee-as-203-VC
sw-ee-as-203-3
sw-ee-as-203-VC
sw-ee-as-203-4
sw-ee-as-203-VC
sw-ee-as-203-5
sw-ee-as-203-VC
—
Reply to this email directly, view it on GitHub<#13882>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM7LK4ZAUMTY553AC7DX4GCCXANCNFSM6AAAAAA5GDQ7LQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nokutaces
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm try to get all member switches from a virtual_chassis
I get the master device in the virtual chassis but not the second or third device.
for example:
vc_s = nb.dcim.virtual_chassis.get(2)
pprint.pprint(dict(vc_s))
result:
{'comments': '',
'created': '2023-09-23T18:06:22.507185+02:00',
'custom_fields': {},
'description': '',
'display': 'sw-we-VC',
'domain': '123',
'id': 2,
'last_updated': '2023-09-24T12:48:23.331332+02:00',
'master': {'display': 'sw-we',
'id': 11,
'name': 'sw-we',
'url': 'http://netbox.xxx.local/api/dcim/devices/11/'},
'member_count': 2,
'name': 'sw-we-VC',
'tags': [],
'url': 'http://netbox.xxx.local/api/dcim/virtual-chassis/2/'
}
the goal ist to print the mebers and later there interfaces:
I have to itterate over all devices to find all switches
Is there is a better way to find the devices fron a virtual device?
Could someone put me to the right track.
x = nb.dcim.devices.all()
for dev in x:
if dev.virtual_chassis:
vchassi = dev.virtual_chassis.name
if vchassi.startswith('sw-ee-as-203'):
print(dev.name)
print(vchassi)
Result:
sw-ee-as-203
sw-ee-as-203-VC
sw-ee-as-203-2
sw-ee-as-203-VC
sw-ee-as-203-3
sw-ee-as-203-VC
sw-ee-as-203-4
sw-ee-as-203-VC
sw-ee-as-203-5
sw-ee-as-203-VC
Beta Was this translation helpful? Give feedback.
All reactions