diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 2a09de8d3d8..a26b4683a3a 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -360,7 +360,10 @@ public class ApiConstants { public static final String CUSTOM_DISK_OFF_MAX_SIZE = "customdiskofferingmaxsize"; public static final String DEFAULT_ZONE_ID = "defaultzoneid"; public static final String GUID = "guid"; - + public static final String VSWITCH_TYPE_GUEST_TRAFFIC = "guestvswitchtype"; + public static final String VSWITCH_TYPE_PUBLIC_TRAFFIC = "publicvswitchtype"; + public static final String VSWITCH_NAME_GUEST_TRAFFIC = "guestvswitchname"; + public static final String VSWITCH_NAME_PUBLIC_TRAFFIC = "publicvswitchname"; public static final String EXTERNAL_SWITCH_MGMT_DEVICE_ID = "vsmdeviceid"; public static final String EXTERNAL_SWITCH_MGMT_DEVICE_NAME = "vsmdevicename"; public static final String EXTERNAL_SWITCH_MGMT_DEVICE_STATE = "vsmdevicestate"; diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java index 7b1cd067eb1..d55ccd7dd11 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java @@ -91,6 +91,34 @@ public class AddClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.MEMORY_OVERCOMMIT_RATIO, type = CommandType.STRING, required = false ,description = "value of the default ram overcommit ratio, defaults to 1") private String memoryovercommitratio; + @Parameter(name = ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, type = CommandType.STRING, required = false, description = "Type of virtual switch used for guest traffic in the cluster. Allowed values are, vmwaresvs (for VMware standard vSwitch) and vmwaredvs (for VMware distributed vSwitch)") + private String vSwitchTypeGuestTraffic; + + @Parameter(name = ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, type = CommandType.STRING, required = false, description = "Type of virtual switch used for public traffic in the cluster. Allowed values are, vmwaresvs (for VMware standard vSwitch) and vmwaredvs (for VMware distributed vSwitch)") + private String vSwitchTypePublicTraffic; + + @Parameter(name = ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, type = CommandType.STRING, required = false, description = "Name of virtual switch used for guest traffic in the cluster. This would override zone wide traffic label setting.") + private String vSwitchNameGuestTraffic; + + @Parameter(name = ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, type = CommandType.STRING, required = false, description = "Name of virtual switch used for public traffic in the cluster. This would override zone wide traffic label setting.") + private String vSwitchNamePublicTraffic; + + public String getVSwitchTypeGuestTraffic() { + return vSwitchTypeGuestTraffic; + } + + public String getVSwitchTypePublicTraffic() { + return vSwitchTypePublicTraffic; + } + + public String getVSwitchNameGuestTraffic() { + return vSwitchNameGuestTraffic; + } + + public String getVSwitchNamePublicTraffic() { + return vSwitchNamePublicTraffic; + } + public String getVSMIpaddress() { return vsmipaddress; } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index b6d49bcc5c5..8a75a96845a 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -252,11 +252,10 @@ public enum Config { XenGuestNetwork("Hidden", ManagementServer.class, String.class, "xen.guest.network.device", null, "Specify for guest network name label", null), XenMaxNics("Advanced", AgentManager.class, Integer.class, "xen.nics.max", "7", "Maximum allowed nics for Vms created on Xen", null), // VMware - VmwarePrivateNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.private.vswitch", null, "Specify the vSwitch on host for private network", null), - VmwarePublicNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null), - VmwareGuestNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null), VmwareUseNexusVSwitch("Network", ManagementServer.class, Boolean.class, "vmware.use.nexus.vswitch", "false", "Enable/Disable Cisco Nexus 1000v vSwitch in VMware environment", null), - VmwareCreateFullClone("Advanced", ManagementServer.class, Boolean.class, "vmware.create.full.clone", "false", "If set to true, creates guest VMs as full clones on ESX", null), + VmwareUseDVSwitch("Network", ManagementServer.class, Boolean.class, "vmware.use.dvswitch", "false", "Enable/Disable Nexus/Vmware dvSwitch in VMware environment", null), + VmwarePortsPerDVPortGroup("Network", ManagementServer.class, Integer.class, "vmware.ports.per.dvportgroup", "256", "Default number of ports per Vmware dvPortGroup in VMware environment", null), + VmwareCreateFullClone("Advanced", ManagementServer.class, Boolean.class, "vmware.create.full.clone", "false", "If set to true, creates guest VMs as full clones on ESX", null), VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null), VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null), VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null), diff --git a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java index 9000e15f7aa..db562b1c17a 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -59,10 +59,11 @@ public class Upgrade410to420 implements DbUpgrade { @Override public void performDataMigration(Connection conn) { - PreparedStatement sql = null; - try { - sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'"); - sql.executeUpdate(); + upgradeVmwareLabels(conn); + PreparedStatement sql = null; + try { + sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'"); + sql.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString()); } finally { @@ -73,7 +74,7 @@ public class Upgrade410to420 implements DbUpgrade { } } } - } + } @Override public File[] getCleanupScripts() { @@ -83,5 +84,78 @@ public class Upgrade410to420 implements DbUpgrade { } return new File[] { new File(script) }; - } - } \ No newline at end of file + } + + private String getNewLabel(ResultSet rs, String oldParamValue) { + int separatorIndex; + String oldGuestLabel; + String newGuestLabel = oldParamValue; + try { + // No need to iterate because the global param setting applies to all physical networks irrespective of traffic type + if (rs.next()) { + oldGuestLabel = rs.getString("vmware_network_label"); + // guestLabel is in format [[],VLANID] + separatorIndex = oldGuestLabel.indexOf(","); + if(separatorIndex > -1) { + newGuestLabel += oldGuestLabel.substring(separatorIndex); + } + } + } catch (SQLException e) { + s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e)); + } finally { + try { + if (rs != null) { + rs.close(); + } + } catch (SQLException e) { + } + } + return newGuestLabel; + } + + private void upgradeVmwareLabels(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rsParams = null; + ResultSet rsLabel = null; + String newLabel; + String trafficType = null; + String trafficTypeVswitchParam; + String trafficTypeVswitchParamValue; + + try { + // update the existing vmware traffic labels + pstmt = conn.prepareStatement("select name,value from `cloud`.`configuration` where category='Hidden' and value is not NULL and name REGEXP 'vmware\\.*\\.vswitch';"); + rsParams = pstmt.executeQuery(); + while (rsParams.next()) { + trafficTypeVswitchParam = rsParams.getString("name"); + trafficTypeVswitchParamValue = rsParams.getString("value"); + // When upgraded from 4.0 to 4.1 update physical network traffic label with trafficTypeVswitchParam + if (trafficTypeVswitchParam.equals("vmware.private.vswitch")) { + trafficType = "Management"; //TODO(sateesh): Ignore storage traffic, as required physical network already implemented, anything else tobe done? + } else if (trafficTypeVswitchParam.equals("vmware.public.vswitch")) { + trafficType = "Public"; + } else if (trafficTypeVswitchParam.equals("vmware.guest.vswitch")) { + trafficType = "Guest"; + } + s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt); + pstmt = conn.prepareStatement("select physical_network_id, traffic_type, vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';"); + rsLabel = pstmt.executeQuery(); + newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue); + pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = " + newLabel + " where traffic_type = '" + trafficType + "' and vmware_network_label is not NULL;"); + pstmt.executeUpdate(); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to set vmware traffic labels ", e); + } finally { + try { + if (rsParams != null) { + rsParams.close(); + } + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + } +}