CLOUDSTACK-4405: fix vm migration during the upgrade to 4.2

Signed-off-by: Wei Zhou <w.zhou@leaseweb.com>
This commit is contained in:
Edison Su 2013-08-29 16:37:45 -07:00 committed by Wei Zhou
parent 7b4f846220
commit e325fb66ab
3 changed files with 68 additions and 8 deletions

53
agent/bindir/libvirtqemuhook.in Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# 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
from xml.dom.minidom import parse
from cloudutils.configFileOps import configFileOps
from cloudutils.networkConfig import networkConfig
def isOldStyleBridge(brName):
if brName.find("cloudVirBr") == 0:
return True
else:
return False
def getGuestNetworkDevice():
netlib = networkConfig()
cfo = configFileOps("/etc/cloudstack/agent/agent.properties")
guestDev = cfo.getEntry("guest.network.device")
enslavedDev = netlib.getEnslavedDev(guestDev, 1)
return enslavedDev
def handleMigrateBegin():
try:
domain = parse(sys.stdin)
for interface in domain.getElementsByTagName("interface"):
source = interface.getElementsByTagName("source")[0]
bridge = source.getAttribute("bridge")
if not isOldStyleBridge(bridge):
continue
vlanId = bridge.replace("cloudVirBr","")
phyDev = getGuestNetworkDevice()
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()

View File

@ -288,6 +288,7 @@ install -D agent/target/transformed/environment.properties ${RPM_BUILD_ROOT}%{_s
install -D agent/target/transformed/log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/log4j-cloud.xml
install -D agent/target/transformed/cloud-setup-agent ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-agent
install -D agent/target/transformed/cloudstack-agent-upgrade ${RPM_BUILD_ROOT}%{_bindir}/%{name}-agent-upgrade
install -D agent/target/transformed/libvirtqemuhook ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook
install -D agent/target/transformed/cloud-ssh ${RPM_BUILD_ROOT}%{_bindir}/%{name}-ssh
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
cp plugins/hypervisors/kvm/target/dependencies/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib
@ -556,6 +557,7 @@ fi
%config(noreplace) %{_sysconfdir}/%{name}/agent
%dir %{_localstatedir}/log/%{name}/agent
%attr(0644,root,root) %{_datadir}/%{name}-agent/lib/*.jar
%attr(0755,root,root) %{_datadir}/%{name}-agent/lib/libvirtqemuhook
%dir %{_datadir}/%{name}-agent/plugins
%{_defaultdocdir}/%{name}-agent-%{version}/LICENSE
%{_defaultdocdir}/%{name}-agent-%{version}/NOTICE

View File

@ -45,6 +45,7 @@ public class BridgeVifDriver extends VifDriverBase {
private static final Object _vnetBridgeMonitor = new Object();
private String _modifyVlanPath;
private String bridgeNameSchema;
@Override
public void configure(Map<String, Object> params) throws ConfigurationException {
@ -59,7 +60,9 @@ public class BridgeVifDriver extends VifDriverBase {
networkScriptsDir = "scripts/vm/network/vnet";
}
String value = (String)params.get("scripts.timeout");
bridgeNameSchema = (String) params.get("network.bridge.name.schema");
String value = (String) params.get("scripts.timeout");
_timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000;
_modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh");
@ -142,13 +145,15 @@ public class BridgeVifDriver extends VifDriverBase {
}
private String setVnetBrName(String pifName, String vnetId) {
String brName = "br" + pifName + "-" + vnetId;
String oldStyleBrName = "cloudVirBr" + vnetId;
String cmdout = Script.runSimpleBashScript("brctl show | grep " + oldStyleBrName);
if (cmdout != null && cmdout.contains(oldStyleBrName)) {
s_logger.info("Using old style bridge name for vlan " + vnetId + " because existing bridge " + oldStyleBrName + " was found");
brName = oldStyleBrName;
String brName = null;
if (bridgeNameSchema != null) {
if (bridgeNameSchema.equalsIgnoreCase("3.0")) {
brName = "cloudVirBr" + vnetId;
} else if (bridgeNameSchema.equalsIgnoreCase("4.0")) {
brName = "br" + pifName + "-"+ vnetId;
}
} else {
brName = "br" + pifName + "-"+ vnetId;
}
return brName;