Skip to content

Commit 8dcfc83

Browse files
committed
Merge pull request #31 from huangpf/dev
Fix Start/Stop/Update-AzureVM
2 parents 8564936 + 5b31531 commit 8dcfc83

File tree

7 files changed

+52
-40
lines changed

7 files changed

+52
-40
lines changed

src/ResourceManager/Network/Commands.Network/Models/PSVirtualNetworkGatewayConnection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public class PSVirtualNetworkGatewayConnection : PSTopLevelResource
3535
[JsonIgnore]
3636
public string VirtualNetworkGateway1Text
3737
{
38-
get { return JsonConvert.SerializeObject(VirtualNetworkGateway1, Formatting.Indented); }
38+
get { return JsonConvert.SerializeObject(VirtualNetworkGateway1.Id, Formatting.Indented); }
3939
}
4040

4141
[JsonIgnore]
4242
public string VirtualNetworkGateway2Text
4343
{
44-
get { return JsonConvert.SerializeObject(VirtualNetworkGateway2, Formatting.Indented); }
44+
get { return JsonConvert.SerializeObject(VirtualNetworkGateway2.Id, Formatting.Indented); }
4545
}
4646

4747
[JsonIgnore]
4848
public string LocalNetworkGateway2Text
4949
{
50-
get { return JsonConvert.SerializeObject(LocalNetworkGateway2, Formatting.Indented); }
50+
get { return JsonConvert.SerializeObject(LocalNetworkGateway2.Id, Formatting.Indented); }
5151
}
5252
}
5353
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Helpers/PersistentVMHelper.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ public static RoleNamesCollection GetRoleNames(IList<RoleInstance> roleInstanceL
117117
return roleNamesCollection;
118118
}
119119

120+
// Return the list of role names that match any of the given query.
121+
public static RoleNamesCollection GetRoleNames(IList<RoleInstance> roleInstanceList, string[] roleNameQueries)
122+
{
123+
List<string> distinctRoleNameList = new List<string>();
124+
125+
foreach (var roleNameQuery in roleNameQueries)
126+
{
127+
var unionResult = distinctRoleNameList.Union(GetRoleNames(roleInstanceList, roleNameQuery));
128+
distinctRoleNameList = unionResult.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
129+
}
130+
131+
var roleNamesCollection = new RoleNamesCollection();
132+
133+
foreach (var roleName in distinctRoleNameList)
134+
{
135+
roleNamesCollection.Add(roleName);
136+
}
137+
138+
return roleNamesCollection;
139+
}
140+
120141
public static Collection<ConfigurationSet> MapConfigurationSets(IList<Management.Compute.Models.ConfigurationSet> configurationSets)
121142
{
122143
var result = new Collection<ConfigurationSet>();

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/StartAzureVM.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public class StartAzureVMCommand : IaaSDeploymentManagementCmdletBase
2929
{
3030
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the Virtual Machine to start.", ParameterSetName = "ByName")]
3131
[ValidateNotNullOrEmpty]
32-
public string Name { get; set; }
32+
public string[] Name { get; set; }
3333

3434
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The Virtual Machine to restart.", ParameterSetName = "Input")]
3535
[ValidateNotNullOrEmpty]
3636
[Alias("InputObject")]
37-
public PersistentVM VM { get; set; }
37+
public PersistentVM[] VM { get; set; }
3838

3939
protected override void ExecuteCommand()
4040
{
@@ -47,11 +47,11 @@ protected override void ExecuteCommand()
4747
return;
4848
}
4949

50-
string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName;
51-
50+
string[] inputRoleNames = (this.ParameterSetName == "ByName") ? this.Name : this.VM.Select(vm => vm.RoleName).ToArray();
51+
5252
// Generate a list of role names matching wildcard patterns or
5353
// the exact name specified in the -Name parameter.
54-
var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, roleName);
54+
var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, inputRoleNames);
5555

5656
// Insure at least one of the role name instances can be found.
5757
if ((roleNames == null) || (!roleNames.Any()))

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/StopAzureVM.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Globalization;
17-
using System.Linq;
18-
using System.Management.Automation;
15+
using Microsoft.Azure;
1916
using Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers;
2017
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
2118
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2219
using Microsoft.WindowsAzure.Management.Compute;
2320
using Microsoft.WindowsAzure.Management.Compute.Models;
24-
using Microsoft.Azure;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Globalization;
24+
using System.Linq;
25+
using System.Management.Automation;
2526

2627
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
2728
{
@@ -30,12 +31,12 @@ public class StopAzureVMCommand : IaaSDeploymentManagementCmdletBase
3031
{
3132
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the Virtual Machine to stop.", ParameterSetName = "ByName")]
3233
[ValidateNotNullOrEmpty]
33-
public string Name { get; set; }
34+
public string[] Name { get; set; }
3435

3536
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The Virtual Machine to restart.", ParameterSetName = "Input")]
3637
[ValidateNotNullOrEmpty]
3738
[Alias("InputObject")]
38-
public Model.PersistentVM VM { get; set; }
39+
public Model.PersistentVM[] VM { get; set; }
3940

4041
[Parameter(Position = 2, HelpMessage = "Keeps the VM provisioned")]
4142
public SwitchParameter StayProvisioned { get; set; }
@@ -53,11 +54,11 @@ protected override void ExecuteCommand()
5354
return;
5455
}
5556

56-
string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName;
57+
string[] inputRoleNames = (this.ParameterSetName == "ByName") ? this.Name : this.VM.Select(vm => vm.RoleName).ToArray();
5758

5859
// Generate a list of role names matching regular expressions or
5960
// the exact name specified in the -Name parameter.
60-
var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, roleName);
61+
var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, inputRoleNames);
6162

6263
// Insure at least one of the role name instances can be found.
6364
if ((roleNames == null) || (!roleNames.Any()))
@@ -66,7 +67,7 @@ protected override void ExecuteCommand()
6667
}
6768

6869
// Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified.
69-
if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent))
70+
if (roleNames.Any(r => WildcardPattern.ContainsWildcardCharacters(r)) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent))
7071
{
7172
throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards);
7273
}
@@ -93,7 +94,7 @@ protected override void ExecuteCommand()
9394
{
9495
this.ConfirmAction(false,
9596
Resources.DeploymentVIPLossWarning,
96-
string.Format(Resources.DeprovisioningVM, roleName),
97+
string.Format(Resources.DeprovisioningVM, string.Join(", ", roleNames)),
9798
String.Empty,
9899
() => this.ExecuteClientActionNewSM(
99100
null,
@@ -149,7 +150,7 @@ protected override void ExecuteCommand()
149150
{
150151
this.ConfirmAction(false,
151152
Resources.DeploymentVIPLossWarning,
152-
string.Format(Resources.DeprovisioningVM, roleName),
153+
string.Format(Resources.DeprovisioningVM, string.Join(", ", roleNames)),
153154
String.Empty,
154155
() => this.ExecuteClientActionNewSM(
155156
null,

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/UpdateAzureVM.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
17-
using System.Linq;
18-
using System.Management.Automation;
1915
using AutoMapper;
16+
using Hyak.Common;
2017
using Microsoft.Azure.Common.Authentication.Models;
2118
using Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers;
19+
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs;
2220
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
2321
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2422
using Microsoft.WindowsAzure.Management.Compute;
2523
using Microsoft.WindowsAzure.Management.Compute.Models;
2624
using Microsoft.WindowsAzure.Storage;
27-
using Hyak.Common;
25+
using System;
26+
using System.Collections.Generic;
27+
using System.Linq;
28+
using System.Management.Automation;
2829

2930
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
3031
{
@@ -71,23 +72,14 @@ internal void ExecuteCommandNewSM()
7172
throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible);
7273
}
7374

74-
DateTime dateTimeCreated = DateTime.Now;
7575
string diskPartName = VM.RoleName;
76-
7776
if (datadisk.DiskLabel != null)
7877
{
7978
diskPartName += "-" + datadisk.DiskLabel;
8079
}
8180

82-
string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", ServiceName, diskPartName, dateTimeCreated.Year, dateTimeCreated.Month, dateTimeCreated.Day, dateTimeCreated.Millisecond);
83-
string blobEndpoint = currentStorage.BlobEndpoint.AbsoluteUri;
84-
85-
if (blobEndpoint.EndsWith("/") == false)
86-
{
87-
blobEndpoint += "/";
88-
}
89-
90-
datadisk.MediaLink = new Uri(blobEndpoint + "vhds/" + vhdname);
81+
var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, diskPartName);
82+
datadisk.MediaLink = mediaLinkFactory.Create();
9183
}
9284

9385
if (VM.DataVirtualHardDisks.Count > 1)

src/ServiceManagement/Network/Commands.Network/Gateway/GetAzureVNetGatewayIPsecParameters.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Gateway
2222
public class GetAzureVNetGatewayIPsecParameters : NetworkCmdletBase
2323
{
2424
[Parameter(Position = 0, Mandatory = true, HelpMessage = "The virtual network name.")]
25-
[ValidateGuid]
2625
[ValidateNotNullOrEmpty]
2726
public string VNetName
2827
{
2928
get; set;
3029
}
3130

3231
[Parameter(Position = 1, Mandatory = true, HelpMessage = "The local network site name.")]
33-
[ValidateGuid]
3432
[ValidateNotNullOrEmpty]
3533
public string LocalNetworkSiteName
3634
{

src/ServiceManagement/Services/Commands.Utilities/ServiceManagementStartup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15-
$aliases = @{
15+
$script:aliases = @{
1616
# Profile aliases
1717
"Get-WAPackPublishSettingsFile" = "Get-AzurePublishSettingsFile";
1818
"Get-WAPackSubscription" = "Get-AzureSubscription";
@@ -113,4 +113,4 @@ $aliases = @{
113113
"Start-SSLegacyVolumeContainerMigrationPlan" = "Start-AzureStorSimpleLegacyVolumeContainerMigrationPlan";
114114
}
115115

116-
$aliases.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"
116+
$aliases.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"

0 commit comments

Comments
 (0)