Skip to content

Commit 7b4f846

Browse files
sudisonustcweizhou
authored andcommitted
CLOUDSTACK-4405: add a tool: cloudstack-agent-upgrade to upgrade bridge name on kvm host
(cherry picked from commit 0ef6084) Signed-off-by: Wei Zhou <[email protected]>
1 parent 87dde70 commit 7b4f846

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
from cloudutils.networkConfig import networkConfig
19+
from cloudutils.utilities import bash
20+
def isOldStyleBridge(brName):
21+
if brName.find("cloudVirBr") == 0:
22+
return True
23+
else:
24+
return False
25+
def upgradeBridgeName(brName, enslavedDev):
26+
print("upgrade bridge: %s, %s"%(brName, enslavedDev))
27+
vlanId = brName.replace("cloudVirBr", "")
28+
print("find vlan Id: %s"%vlanId)
29+
phyDev = enslavedDev.split(".")[0]
30+
print("find physical device %s"%phyDev)
31+
newBrName = "br" + phyDev + "-" + vlanId
32+
print("new bridge name %s"%newBrName)
33+
bash("ip link set %s down"%brName)
34+
bash("ip link set %s name %s"%(brName, newBrName))
35+
bash("ip link set %s up" %newBrName)
36+
if __name__ == '__main__':
37+
netlib = networkConfig()
38+
bridges = netlib.listNetworks()
39+
bridges = filter(isOldStyleBridge, bridges)
40+
for br in bridges:
41+
enslavedDev = netlib.getEnslavedDev(br, 1)
42+
if enslavedDev is not None:
43+
upgradeBridgeName(br, enslavedDev)
44+
45+
bridges = netlib.listNetworks()
46+
bridges = filter(isOldStyleBridge, bridges)
47+
if len(bridges) > 0:
48+
print("Warning: upgrade is not finished, still some bridges have the old style name:" + str(bridges))
49+
else:
50+
print("Upgrade succeed")

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/agent.properties ${RPM_BUILD_ROOT}%{_sysconf
287287
install -D agent/target/transformed/environment.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/environment.properties
288288
install -D agent/target/transformed/log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/log4j-cloud.xml
289289
install -D agent/target/transformed/cloud-setup-agent ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-agent
290+
install -D agent/target/transformed/cloudstack-agent-upgrade ${RPM_BUILD_ROOT}%{_bindir}/%{name}-agent-upgrade
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
@@ -548,6 +549,7 @@ fi
548549

549550
%files agent
550551
%attr(0755,root,root) %{_bindir}/%{name}-setup-agent
552+
%attr(0755,root,root) %{_bindir}/%{name}-agent-upgrade
551553
%attr(0755,root,root) %{_bindir}/%{name}-ssh
552554
%attr(0755,root,root) %{_sysconfdir}/init.d/%{name}-agent
553555
%attr(0755,root,root) %{_datadir}/%{name}-common/scripts/network/cisco

python/lib/cloudutils/networkConfig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def __init__(self, macAddr, ipAddr, netmask, gateway, type, name):
3535
self.method = None
3636

3737
@staticmethod
38+
def listNetworks():
39+
devs = os.listdir("/sys/class/net/")
40+
devs = filter(networkConfig.isBridge, devs)
41+
return devs
42+
@staticmethod
3843
def getDefaultNetwork():
3944
cmd = bash("route -n|awk \'/^0.0.0.0/ {print $2,$8}\'")
4045
if not cmd.isSuccess():

0 commit comments

Comments
 (0)