<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr"><div>Hi Team , <br></div><div><br></div><div>I am reaching out to you seeking your help for one of my KVM hook script. <br></div><div>I am using /etc/libvirt/hooks/network file to trigger an event when a network is created or deleted (

<a href="https://www.libvirt.org/hooks.html" target="_blank">https://www.libvirt.org/hooks.html</a>

). Basically I using a rest call to create the same network in my Infoblox appliance for the network monitoring. <br></div><div><br></div><div>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.</div><div><br></div><div>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. <br></div><div>Here is snippet of my script</div><div><br></div><div>#!/bin/bash<br><br><br>network_name=`xml_grep --text_only  hookData/network/name  /etc/libvirt/hooks/net_details`<br>network=`xmllint --xpath hookData/network/ip/@address /etc/libvirt/hooks/net_details|cut -d "=" -f2|tr -d '"'`<br>network_mask=`ipcalc $network |awk '/Network/{print$2}'`<br><br><br>if [[ $2=="begin" ]] || [[ $2=="start" ]] || [[ $2=="started" ]]; then<br>        curl -k -u admin:infoblox -H "content-type: application/json" -X POST "<a href="https://10.196.200.63/wapi/v2.10/network?_return_fields%2B=network&_return_as_object=1" target="_blank">https://10.196.200.63/wapi/v2.10/network?_return_fields%2B=network&_return_as_object=1</a>" -d '{"network": "'$network_mask'"}'<br><br><br>        network_ref=`curl -k -s -u admin:infoblox -H 'content-type: application/json' -X GET '<a href="https://10.196.200.63/wapi/v2.10/network?_return_fields%2B=network&_return_as_object=1" target="_blank">https://10.196.200.63/wapi/v2.10/network?_return_fields%2B=network&_return_as_object=1</a> '| grep $network_mask| awk -v RS=" " '/_ref/{getline;print$1}' |cut -d "/" -f2-3`<br><br>else<br><br>        curl -k -u admin:infoblox -H 'content-type: application/json' -X DELETE "<a href="https://10.196.200.63/wapi/v2.10/network/$network_ref/default" target="_blank">https://10.196.200.63/wapi/v2.10/network/$network_ref/default</a>"<br><br>fi<br></div><div><br></div><div>-----------------------------------------------------------------------------------------------------------------------<br></div><div>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. <br></div><div><br></div><div><br></div><div>Attaching libvirted.log snippet</div><div><br></div><div><div><img src="cid:ii_k81xq3ro0" alt="image.png" width="471" height="79"><br></div><div>In this screen shot,  stopped hook is triggered but still network creation API is fired which has errored out.</div><div><br></div><div>Any guidance or help is highly appreciated. <br></div><div><br></div><div>-Aditya<br></div><div><br></div></div><div><br></div><div><br></div><div>

<h5 style="font-weight:bold;margin:0.75em 0px 0.25em;padding:0px;font-size:1em;color:rgb(0,0,0);font-family:LibvirtOverpass;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></h5>

</div></div>
</div></div>