Hi Team , I am reaching out to you seeking your help for one of my KVM hook script. I am using /etc/libvirt/hooks/network file to trigger an event when a network is created or deleted ( https://www.libvirt.org/hooks.html ). Basically I using a rest call to create the same network in my Infoblox appliance for the network monitoring.
However every time I create a network only $2== start or $2==started gets invoked, i have tried pretty much every combination and permutation but did not get any success. I checked the libvirtd.log and found that only $2== start or $2==started gets invoked. In my case i would like to get network created in infoblox appliance as and when it gets created in the KVM and should get deleted as and when it gets deleted from the KVM. Here is snippet of my script #!/bin/bash network_name=`xml_grep --text_only hookData/network/name /etc/libvirt/hooks/net_details` network=`xmllint --xpath hookData/network/ip/@address /etc/libvirt/hooks/net_details|cut -d "=" -f2|tr -d '"'` network_mask=`ipcalc $network |awk '/Network/{print$2}'` if [[ $2=="begin" ]] || [[ $2=="start" ]] || [[ $2=="started" ]]; then curl -k -u admin:infoblox -H "content-type: application/json" -X POST " https://10.196.200.63/wapi/v2.10/network?_return_fields%2B=network&_return_as_object=1" -d '{"network": "'$network_mask'"}' network_ref=`curl -k -s -u admin:infoblox -H 'content-type: application/json' -X GET ' https://10.196.200.63/wapi/v2.10/network?_return_fields%2B=network&_return_as_object=1 '| grep $network_mask| awk -v RS=" " '/_ref/{getline;print$1}' |cut -d "/" -f2-3` else curl -k -u admin:infoblox -H 'content-type: application/json' -X DELETE "https://10.196.200.63/wapi/v2.10/network/$network_ref/default" fi ----------------------------------------------------------------------------------------------------------------------- This script works perfectly fine and creates the network however when i delete the network it does not get deleted from the infoblox appliance. As i mentioned when tailed the libvirtd.log I found that the API to create network gets executed when the network is stopped. Attaching libvirted.log snippet [image: image.png] In this screen shot, stopped hook is triggered but still network creation API is fired which has errored out. Any guidance or help is highly appreciated. -Aditya