You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2018/04/16 11:50:51 UTC
[cloudstack] branch 4.11 updated: agent: Add logging to libvirt
qemu hook (#2554)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch 4.11
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.11 by this push:
new 156dbf4 agent: Add logging to libvirt qemu hook (#2554)
156dbf4 is described below
commit 156dbf466c1307b66706e1133dad33d97096cc5b
Author: Rohit Yadav <ro...@apache.org>
AuthorDate: Mon Apr 16 17:20:48 2018 +0530
agent: Add logging to libvirt qemu hook (#2554)
This allows logging to the default libvirt qemu hook
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
---
agent/bindir/libvirtqemuhook.in | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/agent/bindir/libvirtqemuhook.in b/agent/bindir/libvirtqemuhook.in
index 9fbe037..55ab3e6 100755
--- a/agent/bindir/libvirtqemuhook.in
+++ b/agent/bindir/libvirtqemuhook.in
@@ -6,25 +6,36 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-import sys
+
+import logging
import re
+import sys
from xml.dom.minidom import parse
from cloudutils.configFileOps import configFileOps
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):
if brName.find("cloudVirBr") == 0:
return True
else:
return False
+
def isNewStyleBridge(brName):
if brName.startswith('brvx-'):
return False
@@ -32,12 +43,14 @@ def isNewStyleBridge(brName):
return False
else:
return True
+
def getGuestNetworkDevice():
- netlib = networkConfig()
+ netlib = networkConfig()
cfo = configFileOps("/etc/cloudstack/agent/agent.properties")
guestDev = cfo.getEntry("guest.network.device")
enslavedDev = netlib.getEnslavedDev(guestDev, 1)
return enslavedDev.split(".")[0]
+
def handleMigrateBegin():
try:
domain = parse(sys.stdin)
@@ -45,20 +58,26 @@ def handleMigrateBegin():
source = interface.getElementsByTagName("source")[0]
bridge = source.getAttribute("bridge")
if isOldStyleBridge(bridge):
- vlanId = bridge.replace("cloudVirBr","")
+ vlanId = bridge.replace("cloudVirBr", "")
elif isNewStyleBridge(bridge):
- vlanId = re.sub(r"br(\w+)-","",bridge)
+ vlanId = re.sub(r"br(\w+)-", "", bridge)
else:
continue
phyDev = getGuestNetworkDevice()
- newBrName="br" + phyDev + "-" + vlanId
+ newBrName = "br" + phyDev + "-" + vlanId
source.setAttribute("bridge", newBrName)
print(domain.toxml())
except:
pass
+
+
if __name__ == '__main__':
if len(sys.argv) != 5:
sys.exit(0)
- if sys.argv[2] == "migrate" and sys.argv[3] == "begin":
- handleMigrateBegin()
+ # 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()
--
To stop receiving notification emails like this one, please contact
dahn@apache.org.