Created
June 2, 2016 18:26
-
-
Save mattraykowski/3754f99270b9d3c8d985bceb6c8b040b to your computer and use it in GitHub Desktop.
Infoblox fetching related objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def something(connection) | |
addresses = Infoblox::Ipv4address.find(connection,{"network" => "172.16.1.1/25"}); | |
addresses.each do |address| | |
if address.objects.empty? | |
puts "No objects" | |
else | |
# Get all of the related objects. | |
objects = address.objects | |
# Loop over each related object. | |
objects.each do |object| | |
# The object is actually a _ref, the first part of this is the wapi object type, get that. | |
wapi_object = object.split("/")[0] | |
# Using the wapi_object fetch the resource class for it and create a new one in order to fetch the ref. | |
related_resource = Infoblox.Resource.resource_map[wapi_object].new(connection: connection, _ref: object) | |
# Check to see if the related resource that was fetched was an A record. | |
if related_resource.instance_of? Infoblox::Arecord | |
# Do something here. | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`addresses = Infoblox::Ipv4address.find(connection,{"network" => "208.42.128.128/25"});
addresses.each do |address|
puts "------"
puts "ip_address #{address.ip_address} has types #{address.types}"
#puts "objects #{address.objects}"
if address.objects.empty?
puts "No objects"
else
objects = address.objects
objects.each do |object|
puts object
wapi_object = object.split("/")[0]
puts "wapi_object #{wapi_object}"
puts Infoblox::Resource.resource_map[wapi_object].new(:connection => connection, :_ref => object).get
puts Infoblox::Resource.resource_map[object.split("/"[0])].new(:connection => connection, :_ref => object).get
end
#puts address.to_s
end`