Skip to content

Commit 3cca650

Browse files
committed
CLOUDSTACK-4405: fix vm migration during the upgrade to 4.2
1 parent 2848af8 commit 3cca650

3 files changed

Lines changed: 67 additions & 7 deletions

File tree

‎agent/bindir/libvirtqemuhook.in‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/python
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
import sys
19+
from xml.dom.minidom import parse
20+
from cloudutils.configFileOps import configFileOps
21+
from cloudutils.networkConfig import networkConfig
22+
def isOldStyleBridge(brName):
23+
if brName.find("cloudVirBr") == 0:
24+
return True
25+
else:
26+
return False
27+
def getGuestNetworkDevice():
28+
netlib = networkConfig()
29+
cfo = configFileOps("/etc/cloudstack/agent/agent.properties")
30+
guestDev = cfo.getEntry("guest.network.device")
31+
enslavedDev = netlib.getEnslavedDev(guestDev, 1)
32+
return enslavedDev
33+
def handleMigrateBegin():
34+
try:
35+
domain = parse(sys.stdin)
36+
for interface in domain.getElementsByTagName("interface"):
37+
source = interface.getElementsByTagName("source")[0]
38+
bridge = source.getAttribute("bridge")
39+
if not isOldStyleBridge(bridge):
40+
continue
41+
vlanId = bridge.replace("cloudVirBr","")
42+
phyDev = getGuestNetworkDevice()
43+
newBrName="br" + phyDev + "-" + vlanId
44+
source.setAttribute("bridge", newBrName)
45+
print(domain.toxml())
46+
except:
47+
pass
48+
if __name__ == '__main__':
49+
if len(sys.argv) != 5:
50+
sys.exit(0)
51+
52+
if sys.argv[2] == "migrate" and sys.argv[3] == "begin":
53+
handleMigrateBegin()

‎packaging/centos63/cloud.spec‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ install -D agent/target/transformed/environment.properties ${RPM_BUILD_ROOT}%{_s
287287
install -D agent/target/transformed/log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/log4j-cloud.xml
288288
install -D agent/target/transformed/cloud-setup-agent ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-agent
289289
install -D agent/target/transformed/cloudstack-agent-upgrade ${RPM_BUILD_ROOT}%{_bindir}/%{name}-agent-upgrade
290+
install -D agent/target/transformed/libvirtqemuhook ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook
290291
install -D agent/target/transformed/cloud-ssh ${RPM_BUILD_ROOT}%{_bindir}/%{name}-ssh
291292
install -D plugins/hypervisors/kvm/target/cloud-plugin-hypervisor-kvm-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir}/%name-agent/lib/cloud-plugin-hypervisor-kvm-%{_maventag}.jar
292293
cp plugins/hypervisors/kvm/target/dependencies/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib
@@ -555,6 +556,7 @@ fi
555556
%config(noreplace) %{_sysconfdir}/%{name}/agent
556557
%dir %{_localstatedir}/log/%{name}/agent
557558
%attr(0644,root,root) %{_datadir}/%{name}-agent/lib/*.jar
559+
%attr(0755,root,root) %{_datadir}/%{name}-agent/lib/libvirtqemuhook
558560
%dir %{_datadir}/%{name}-agent/plugins
559561
%{_defaultdocdir}/%{name}-agent-%{version}/LICENSE
560562
%{_defaultdocdir}/%{name}-agent-%{version}/NOTICE

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class BridgeVifDriver extends VifDriverBase {
4545

4646
private static final Object _vnetBridgeMonitor = new Object();
4747
private String _modifyVlanPath;
48+
private String bridgeNameSchema;
4849

4950
@Override
5051
public void configure(Map<String, Object> params) throws ConfigurationException {
@@ -60,6 +61,8 @@ public void configure(Map<String, Object> params) throws ConfigurationException
6061
networkScriptsDir = "scripts/vm/network/vnet";
6162
}
6263

64+
bridgeNameSchema = (String) params.get("network.bridge.name.schema");
65+
6366
String value = (String) params.get("scripts.timeout");
6467
_timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
6568

@@ -144,13 +147,15 @@ public void unplug(LibvirtVMDef.InterfaceDef iface) {
144147
}
145148

146149
private String setVnetBrName(String pifName, String vnetId) {
147-
String brName = "br" + pifName + "-"+ vnetId;
148-
String oldStyleBrName = "cloudVirBr" + vnetId;
149-
150-
String cmdout = Script.runSimpleBashScript("brctl show | grep " + oldStyleBrName);
151-
if (cmdout != null && cmdout.contains(oldStyleBrName)) {
152-
s_logger.info("Using old style bridge name for vlan " + vnetId + " because existing bridge " + oldStyleBrName + " was found");
153-
brName = oldStyleBrName;
150+
String brName = null;
151+
if (bridgeNameSchema != null) {
152+
if (bridgeNameSchema.equalsIgnoreCase("3.0")) {
153+
brName = "cloudVirBr" + vnetId;
154+
} else if (bridgeNameSchema.equalsIgnoreCase("4.0")) {
155+
brName = "br" + pifName + "-"+ vnetId;
156+
}
157+
} else {
158+
brName = "br" + pifName + "-"+ vnetId;
154159
}
155160

156161
return brName;

0 commit comments

Comments
 (0)