mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
agent: Add logging to libvirt qemu hook (#2554)
This allows logging to the default libvirt qemu hook Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
b69c37862c
commit
156dbf466c
@ -15,16 +15,27 @@
|
|||||||
# KIND, either express or implied. See the License for the
|
# KIND, either express or implied. See the License for the
|
||||||
# specific language governing permissions and limitations
|
# specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import sys
|
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
from cloudutils.configFileOps import configFileOps
|
from cloudutils.configFileOps import configFileOps
|
||||||
from cloudutils.networkConfig import networkConfig
|
from cloudutils.networkConfig import networkConfig
|
||||||
|
|
||||||
|
logging.basicConfig(filename='/var/log/libvirt/qemu-hook.log',
|
||||||
|
filemode='a',
|
||||||
|
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
|
||||||
|
datefmt='%H:%M:%S',
|
||||||
|
level=logging.INFO)
|
||||||
|
logger = logging.getLogger('qemu-hook')
|
||||||
|
|
||||||
def isOldStyleBridge(brName):
|
def isOldStyleBridge(brName):
|
||||||
if brName.find("cloudVirBr") == 0:
|
if brName.find("cloudVirBr") == 0:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isNewStyleBridge(brName):
|
def isNewStyleBridge(brName):
|
||||||
if brName.startswith('brvx-'):
|
if brName.startswith('brvx-'):
|
||||||
return False
|
return False
|
||||||
@ -32,12 +43,14 @@ def isNewStyleBridge(brName):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getGuestNetworkDevice():
|
def getGuestNetworkDevice():
|
||||||
netlib = networkConfig()
|
netlib = networkConfig()
|
||||||
cfo = configFileOps("/etc/cloudstack/agent/agent.properties")
|
cfo = configFileOps("/etc/cloudstack/agent/agent.properties")
|
||||||
guestDev = cfo.getEntry("guest.network.device")
|
guestDev = cfo.getEntry("guest.network.device")
|
||||||
enslavedDev = netlib.getEnslavedDev(guestDev, 1)
|
enslavedDev = netlib.getEnslavedDev(guestDev, 1)
|
||||||
return enslavedDev.split(".")[0]
|
return enslavedDev.split(".")[0]
|
||||||
|
|
||||||
def handleMigrateBegin():
|
def handleMigrateBegin():
|
||||||
try:
|
try:
|
||||||
domain = parse(sys.stdin)
|
domain = parse(sys.stdin)
|
||||||
@ -56,9 +69,15 @@ def handleMigrateBegin():
|
|||||||
print(domain.toxml())
|
print(domain.toxml())
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 5:
|
if len(sys.argv) != 5:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if sys.argv[2] == "migrate" and sys.argv[3] == "begin":
|
# For docs refer https://libvirt.org/hooks.html#qemu
|
||||||
|
logger.debug("Executing qemu hook with args: %s" % sys.argv)
|
||||||
|
action, status = sys.argv[2:4]
|
||||||
|
|
||||||
|
if action == "migrate" and status == "begin":
|
||||||
handleMigrateBegin()
|
handleMigrateBegin()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user