Closed bleything closed 6 years ago
Might've found a clue! If I look at the IP Address object:
pp $nb.ipam.ip_addresses.first
#<NetboxClientRuby::IPAM::IpAddress:0x00007fa05b802480
@data=
{"id"=>311,
"family"=>4,
"address"=>"[REDACTED]/24",
"vrf"=>
{"id"=>1,
"url"=>"http://[REDACTED]/api/ipam/vrfs/1.json",
"name"=>"[REDACTED]",
"rd"=>"[REDACTED]"},
"tenant"=>nil,
"status"=>{"label"=>"Active", "value"=>1},
"role"=>nil,
"interface"=>
{"id"=>1408,
"url"=>
"http://[REDACTED]/api/virtualization/interfaces/1408/",
"device"=>nil,
"virtual_machine"=>
{"id"=>62,
"url"=>
"http://[REDACTED]/api/virtualization/virtual-machines/62.json",
"name"=>"[REDACTED]"},
"name"=>"eth0"},
"description"=>"",
"nat_inside"=>nil,
"nat_outside"=>nil,
"custom_fields"=>{},
"created"=>"2017-10-17",
"last_updated"=>"2017-10-17T00:17:08.804666Z"},
@id=311>
I see that interface
has a virtual_machine
. If I look at that object's #raw_data!
I see the same thing. But if I do $nb.ipam.ip_addresses.first.interface.raw_data!
the virtual_machine
is not in there. If I fetch the interface directly from the API, the info is there. Same if I get the IP address.
The problem is that interfaces of virtual machines are different from interfaces of physical devices in the API:
http://netbox/api/dcim/interfaces/ vs. http://netbox/api/virtualization/interfaces/
I'm working on an improved implementation that detects whether it's the interface of a VM or one of a physical device.
Thank you for raising the issue!
ah ha! That makes a lot of sense and thanks for fixing it!
For various reason I'm iterating over IP address's interfaces and trying to find their related devices or VMs. Devices work okay, but VMs don't:
I tried editing
lib/netbox_client_ruby/api/dcim/interface.rb
:and that makes the
NoMethodError
go away but it returnsnil
, even when there's avirtual_machine
attached. I assume that I'm just doing something wrong but I don't understand the code well enough to figure out how to resolve it.