From 808183fdcc24fd6417d7bb806ee58a84b84868f4 Mon Sep 17 00:00:00 2001 From: Sateesh Chodapuneedi Date: Tue, 27 Aug 2013 16:54:29 +0530 Subject: [PATCH] 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 --- .../cloud/upgrade/dao/Upgrade410to420.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index 81f11f00bc4..5db64200a9e 100755 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -39,6 +39,7 @@ import org.apache.log4j.Logger; import com.cloud.deploy.DeploymentPlanner; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.Networks.TrafficType; import com.cloud.network.vpc.NetworkACL; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; @@ -147,6 +148,10 @@ public class Upgrade410to420 implements DbUpgrade { boolean nexusEnabled = false; String publicVswitchType = VMWARE_STANDARD_VSWITCH; String guestVswitchType = VMWARE_STANDARD_VSWITCH; + String defaultPublicVswitchName = "vSwitch0"; + String defaultGuestVswitchName = "vSwitch0"; + String publicVswitchName = null; + String guestVswitchName = null; Map>> detailsMap = new HashMap>>(); List> detailsList; @@ -163,13 +168,27 @@ public class Upgrade410to420 implements DbUpgrade { nexusEnabled = true; } } + // Set default values if cloud level setting is turned on for nexus 1000v. if (nexusEnabled) { publicVswitchType = NEXUS_1000V_DVSWITCH; guestVswitchType = NEXUS_1000V_DVSWITCH; + defaultPublicVswitchName = "publicEthernetPortProfile"; + defaultGuestVswitchName = "guestEthernetPortProfile"; + } + // Read zone level settings from zone wide traffic labels for guest traffic and public traffic + guestVswitchName = getDefaultTrafficLabel(conn, TrafficType.Guest.toString()); + publicVswitchName = getDefaultTrafficLabel(conn, TrafficType.Public.toString()); + if (guestVswitchName == null) { + guestVswitchName = defaultGuestVswitchName; + } + if (publicVswitchName == null) { + publicVswitchName = defaultPublicVswitchName; } detailsList = new ArrayList>(); detailsList.add(new Pair(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, guestVswitchType)); + detailsList.add(new Pair(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, guestVswitchName)); detailsList.add(new Pair(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, publicVswitchType)); + detailsList.add(new Pair(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, publicVswitchName)); detailsMap.put(clusterId, detailsList); updateClusterDetails(conn, detailsMap); @@ -237,6 +256,34 @@ public class Upgrade410to420 implements DbUpgrade { } } + private String getDefaultTrafficLabel(Connection conn, String trafficType) { + ResultSet rs = null; + PreparedStatement pstmt = null; + try { + pstmt = conn.prepareStatement("select vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';"); + rs = pstmt.executeQuery(); + + while (rs.next()) { + String label = rs.getString("vmware_network_label"); + // Handle case of label specified as [vswitch_name,vlan_id] + return label.split(",")[0]; + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable read default traffic label for " + trafficType + ". ", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + return null; + } + private String getConfigurationParameter(Connection conn, String category, String paramName) { ResultSet rs = null; PreparedStatement pstmt = null;