diff --git a/src/ResourceManager/Compute/ChangeLog.md b/src/ResourceManager/Compute/ChangeLog.md index e007434136a0..4e3f56652d0f 100644 --- a/src/ResourceManager/Compute/ChangeLog.md +++ b/src/ResourceManager/Compute/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Current Release +* `New-AzureRmVMSS` prints connection strings in verbose mode. * `New-AzureRmVmss` supports public IP address, load balancing rules, inbound NAT rules. * WriteAccelerator feature - Added WriteAccelerator switch parameter to the following cmdlets: diff --git a/src/ResourceManager/Compute/Commands.Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs b/src/ResourceManager/Compute/Commands.Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs index fbb5b18d65ba..f1662608f2bf 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs @@ -14,6 +14,7 @@ using Microsoft.Azure.Commands.Common.Strategies; using Microsoft.Azure.Commands.Compute.Automation.Models; +using Microsoft.Azure.Commands.Compute.Properties; using Microsoft.Azure.Commands.Compute.Strategies; using Microsoft.Azure.Commands.Compute.Strategies.ComputeRp; using Microsoft.Azure.Commands.Compute.Strategies.Network; @@ -190,7 +191,9 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet) NatBackendPort = imageAndOsType.OsType.UpdatePorts(NatBackendPort); var inboundNatPoolName = VMScaleSetName; - var portRangeStart = 50000; + const int FirstPortRangeStart = 50000; + var portRangeStart = FirstPortRangeStart; + var PortRangeSize = InstanceCount * 2; foreach (var natBackendPort in NatBackendPort) { inboundNatPools.Add( @@ -198,9 +201,9 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet) name: inboundNatPoolName + natBackendPort.ToString(), frontendIpConfiguration: frontendIpConfiguration, frontendPortRangeStart: portRangeStart, - frontendPortRangeEnd: portRangeStart + InstanceCount * 2, + frontendPortRangeEnd: portRangeStart + PortRangeSize, backendPort: natBackendPort)); - portRangeStart += 1000; + portRangeStart += 2000; } // generate a domain name label if it's not specified. @@ -234,6 +237,24 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet) var psObject = new PSVirtualMachineScaleSet(); ComputeAutomationAutoMapperProfile.Mapper.Map(result, psObject); psObject.FullyQualifiedDomainName = fqdn; + + var port = ""; + var connectionString = imageAndOsType.GetConnectionString( + fqdn, + Credential.UserName, + port); + var range = + FirstPortRangeStart.ToString() + + ".." + + (FirstPortRangeStart + PortRangeSize).ToString(); + + asyncCmdlet.WriteVerbose( + Resources.VmssUseConnectionString, + connectionString); + asyncCmdlet.WriteVerbose( + Resources.VmssPortRange, + port, + range); asyncCmdlet.WriteObject(psObject); } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs index 270cd7e5b324..24705e394632 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs @@ -1238,6 +1238,15 @@ internal static string VirtualMachineStoppingConfirmation { } } + /// + /// Looks up a localized string similar to Use '{0}' to connect to the VM.. + /// + internal static string VirtualMachineUseConnectionString { + get { + return ResourceManager.GetString("VirtualMachineUseConnectionString", resourceCulture); + } + } + /// /// Looks up a localized string similar to You have to specify either both of KeyEncryptionKeyVaultId and KeyEncryptionKeyUrl or none of them.. /// @@ -1246,5 +1255,23 @@ internal static string VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired { return ResourceManager.GetString("VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired", resourceCulture); } } + + /// + /// Looks up a localized string similar to Where {0} is in the range {1}.. + /// + internal static string VmssPortRange { + get { + return ResourceManager.GetString("VmssPortRange", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use '{0}' to connect to the VMSS instances.. + /// + internal static string VmssUseConnectionString { + get { + return ResourceManager.GetString("VmssUseConnectionString", resourceCulture); + } + } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx index bd3aef60e8fe..d10a29f0bd74 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx +++ b/src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx @@ -572,4 +572,15 @@ The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip) Invalid ImageName {0} {0} = ImageName + + Use '{0}' to connect to the VM. + + + Where {0} is in the range {1}. + {0} = port, {1} = range + + + Use '{0}' to connect to the VMSS instances. + {0} = connection string + \ No newline at end of file diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs index 816ac9ca51a4..5176a41970e6 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs @@ -22,6 +22,9 @@ namespace Microsoft.Azure.Commands.Compute.Strategies { static class AsyncCmdletExtensions { + public static void WriteVerbose(this IAsyncCmdlet cmdlet, string message, params object[] p) + => cmdlet.WriteVerbose(string.Format(message, p)); + /// /// Note: the function must be called in the main PowerShell thread. /// diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/AvailabilitySetStrategy.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/AvailabilitySetStrategy.cs index be84e5e902fb..d98dcaf146f4 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/AvailabilitySetStrategy.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/AvailabilitySetStrategy.cs @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.Compute.Strategies.ComputeRp static class AvailabilitySetStrategy { public static ResourceStrategy Strategy { get; } - = ComputePolicy.Create( + = ComputeStrategy.Create( provider: "availabilitySets", getOperations: client => client.AvailabilitySets, getAsync: (o, p) => o.GetAsync( diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ComputeStrategy.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ComputeStrategy.cs index 844b94f6df2d..28b29d80bcfd 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ComputeStrategy.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ComputeStrategy.cs @@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.Compute.Strategies.ComputeRp { - static class ComputePolicy + static class ComputeStrategy { public static ResourceStrategy Create( string provider, @@ -38,5 +38,14 @@ public static ResourceStrategy Create( setLocation: (config, location) => config.Location = location, createTime: createTime, compulsoryLocation: true); + + public static string GetConnectionString( + this ImageAndOsType imageAndOsType, string fqdn, string user, string port = null) + { + var url = fqdn + (port == null ? string.Empty : ":" + port); + return imageAndOsType.OsType == OperatingSystemTypes.Windows + ? "mstsc /v:" + url + : "ssh " + user + "@" + url; + } } } diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ManagedDiskStrategy.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ManagedDiskStrategy.cs index 3ce2f3e809c6..a6e002de5f24 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ManagedDiskStrategy.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/ManagedDiskStrategy.cs @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.Compute.Strategies.ComputeRp static class ManagedDiskStrategy { public static ResourceStrategy Strategy { get; } - = ComputePolicy.Create( + = ComputeStrategy.Create( provider: "disks", getOperations: client => client.Disks, getAsync: (o, p) => o.GetAsync( diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs index 307d9465ce34..9d5740f4e7e6 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Compute.Strategies.ComputeRp public static class VirtualMachineScaleSetStrategy { public static ResourceStrategy Strategy { get; } - = ComputePolicy.Create( + = ComputeStrategy.Create( provider: "virtualMachineScaleSets", getOperations: client => client.VirtualMachineScaleSets, getAsync: (o, p) => o.GetAsync( diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs index 7cf55accee27..4e563d7ff871 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.Compute.Strategies.ComputeRp static class VirtualMachineStrategy { public static ResourceStrategy Strategy { get; } - = ComputePolicy.Create( + = ComputeStrategy.Create( provider: "virtualMachines", getOperations: client => client.VirtualMachines, getAsync: (o, p) => o.GetAsync( diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs index 272838e85fb2..1956d4a9b013 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs @@ -18,6 +18,7 @@ using Microsoft.Azure.Commands.Common.Strategies; using Microsoft.Azure.Commands.Compute.Common; using Microsoft.Azure.Commands.Compute.Models; +using Microsoft.Azure.Commands.Compute.Properties; using Microsoft.Azure.Commands.Compute.StorageServices; using Microsoft.Azure.Commands.Compute.Strategies; using Microsoft.Azure.Commands.Compute.Strategies.ComputeRp; @@ -405,9 +406,12 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet) { var psResult = ComputeAutoMapperProfile.Mapper.Map(result); psResult.FullyQualifiedDomainName = fqdn; - asyncCmdlet.WriteVerbose(imageAndOsType.OsType == OperatingSystemTypes.Windows - ? "Use 'mstsc /v:" + fqdn + "' to connect to the VM." - : "Use 'ssh " + Credential.UserName + "@" + fqdn + "' to connect to the VM."); + var connectionString = imageAndOsType.GetConnectionString( + fqdn, + Credential.UserName); + asyncCmdlet.WriteVerbose( + Resources.VirtualMachineUseConnectionString, + connectionString); asyncCmdlet.WriteObject(psResult); } }