You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "mlsorensen (via GitHub)" <gi...@apache.org> on 2023/05/03 17:02:46 UTC
[GitHub] [cloudstack] mlsorensen commented on a diff in pull request #7482: Qemu migration hook: check for source length before using element 0
mlsorensen commented on code in PR #7482:
URL: https://github.com/apache/cloudstack/pull/7482#discussion_r1183971710
##########
agent/bindir/libvirtqemuhook.in:
##########
@@ -61,21 +61,23 @@ def handleMigrateBegin():
try:
domain = parse(sys.stdin)
for interface in domain.getElementsByTagName("interface"):
- source = interface.getElementsByTagName("source")[0]
- bridge = source.getAttribute("bridge")
- if isOldStyleBridge(bridge):
- vlanId = bridge.replace("cloudVirBr", "")
- phyDev = getGuestNetworkDevice()
- elif isNewStyleBridge(bridge):
- vlanId = re.sub(r"br(\w+)-", "", bridge)
- phyDev = re.sub(r"-(\d+)$", "" , re.sub(r"^br", "" ,bridge))
- netlib = networkConfig()
- if not netlib.isNetworkDev(phyDev):
+ sources = interface.getElementsByTagName("source")
+ if sources.length > 0:
+ source = interface.getElementsByTagName("source")[0]
+ bridge = source.getAttribute("bridge")
+ if isOldStyleBridge(bridge):
+ vlanId = bridge.replace("cloudVirBr", "")
phyDev = getGuestNetworkDevice()
- else:
- continue
- newBrName = "br" + phyDev + "-" + vlanId
- source.setAttribute("bridge", newBrName)
+ elif isNewStyleBridge(bridge):
+ vlanId = re.sub(r"br(\w+)-", "", bridge)
+ phyDev = re.sub(r"-(\d+)$", "" , re.sub(r"^br", "" ,bridge))
+ netlib = networkConfig()
+ if not netlib.isNetworkDev(phyDev):
+ phyDev = getGuestNetworkDevice()
+ else:
+ continue
+ newBrName = "br" + phyDev + "-" + vlanId
+ source.setAttribute("bridge", newBrName)
print(domain.toxml())
Review Comment:
Print is what returns the domain XML back to libvirt - unless you are asking me to refactor this in some way?
The only addition I have made is to check the array length:
```
sources = interface.getElementsByTagName("source")
if sources.length > 0:
```
The rest is pre-existing code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org