|
| 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") |
0 commit comments