Skip to content

Commit 808183f

Browse files
author
Sateesh Chodapuneedi
committed
CLOUDSTACK-4443 [VMWARE]Failed to deploy VM's on VMWARE Standard vSwitch Legacy Zone after upgrade
While upgrading to 4.2 to support existing clusters working over standard vswitch or nexus dvswitch should be supported as is. To ensure this while upgrading to 4.2, existing cluster's vswitch configuration needs to be persisted to database. If zone level traffic label is empty then default vswitch name would be used. Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
1 parent 93b40b0 commit 808183f

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import com.cloud.deploy.DeploymentPlanner;
4141
import com.cloud.hypervisor.Hypervisor.HypervisorType;
42+
import com.cloud.network.Networks.TrafficType;
4243
import com.cloud.network.vpc.NetworkACL;
4344
import com.cloud.utils.Pair;
4445
import com.cloud.utils.exception.CloudRuntimeException;
@@ -147,6 +148,10 @@ private void persistVswitchConfiguration(Connection conn) {
147148
boolean nexusEnabled = false;
148149
String publicVswitchType = VMWARE_STANDARD_VSWITCH;
149150
String guestVswitchType = VMWARE_STANDARD_VSWITCH;
151+
String defaultPublicVswitchName = "vSwitch0";
152+
String defaultGuestVswitchName = "vSwitch0";
153+
String publicVswitchName = null;
154+
String guestVswitchName = null;
150155
Map<Long, List<Pair<String, String>>> detailsMap = new HashMap<Long, List<Pair<String, String>>>();
151156
List<Pair<String, String>> detailsList;
152157

@@ -163,13 +168,27 @@ private void persistVswitchConfiguration(Connection conn) {
163168
nexusEnabled = true;
164169
}
165170
}
171+
// Set default values if cloud level setting is turned on for nexus 1000v.
166172
if (nexusEnabled) {
167173
publicVswitchType = NEXUS_1000V_DVSWITCH;
168174
guestVswitchType = NEXUS_1000V_DVSWITCH;
175+
defaultPublicVswitchName = "publicEthernetPortProfile";
176+
defaultGuestVswitchName = "guestEthernetPortProfile";
177+
}
178+
// Read zone level settings from zone wide traffic labels for guest traffic and public traffic
179+
guestVswitchName = getDefaultTrafficLabel(conn, TrafficType.Guest.toString());
180+
publicVswitchName = getDefaultTrafficLabel(conn, TrafficType.Public.toString());
181+
if (guestVswitchName == null) {
182+
guestVswitchName = defaultGuestVswitchName;
183+
}
184+
if (publicVswitchName == null) {
185+
publicVswitchName = defaultPublicVswitchName;
169186
}
170187
detailsList = new ArrayList<Pair<String, String>>();
171188
detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, guestVswitchType));
189+
detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, guestVswitchName));
172190
detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, publicVswitchType));
191+
detailsList.add(new Pair<String, String>(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, publicVswitchName));
173192
detailsMap.put(clusterId, detailsList);
174193

175194
updateClusterDetails(conn, detailsMap);
@@ -237,6 +256,34 @@ private void updateClusterDetails(Connection conn, Map<Long, List<Pair<String, S
237256
}
238257
}
239258

259+
private String getDefaultTrafficLabel(Connection conn, String trafficType) {
260+
ResultSet rs = null;
261+
PreparedStatement pstmt = null;
262+
try {
263+
pstmt = conn.prepareStatement("select vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';");
264+
rs = pstmt.executeQuery();
265+
266+
while (rs.next()) {
267+
String label = rs.getString("vmware_network_label");
268+
// Handle case of label specified as [vswitch_name,vlan_id]
269+
return label.split(",")[0];
270+
}
271+
} catch (SQLException e) {
272+
throw new CloudRuntimeException("Unable read default traffic label for " + trafficType + ". ", e);
273+
} finally {
274+
try {
275+
if (rs != null) {
276+
rs.close();
277+
}
278+
if (pstmt != null) {
279+
pstmt.close();
280+
}
281+
} catch (SQLException e) {
282+
}
283+
}
284+
return null;
285+
}
286+
240287
private String getConfigurationParameter(Connection conn, String category, String paramName) {
241288
ResultSet rs = null;
242289
PreparedStatement pstmt = null;

0 commit comments

Comments
 (0)