Skip to content

Fix Start/Stop/Update-AzureVM #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public class PSVirtualNetworkGatewayConnection : PSTopLevelResource
[JsonIgnore]
public string VirtualNetworkGateway1Text
{
get { return JsonConvert.SerializeObject(VirtualNetworkGateway1, Formatting.Indented); }
get { return JsonConvert.SerializeObject(VirtualNetworkGateway1.Id, Formatting.Indented); }
}

[JsonIgnore]
public string VirtualNetworkGateway2Text
{
get { return JsonConvert.SerializeObject(VirtualNetworkGateway2, Formatting.Indented); }
get { return JsonConvert.SerializeObject(VirtualNetworkGateway2.Id, Formatting.Indented); }
}

[JsonIgnore]
public string LocalNetworkGateway2Text
{
get { return JsonConvert.SerializeObject(LocalNetworkGateway2, Formatting.Indented); }
get { return JsonConvert.SerializeObject(LocalNetworkGateway2.Id, Formatting.Indented); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ public static RoleNamesCollection GetRoleNames(IList<RoleInstance> roleInstanceL
return roleNamesCollection;
}

// Return the list of role names that match any of the given query.
public static RoleNamesCollection GetRoleNames(IList<RoleInstance> roleInstanceList, string[] roleNameQueries)
{
List<string> distinctRoleNameList = new List<string>();

foreach (var roleNameQuery in roleNameQueries)
{
var unionResult = distinctRoleNameList.Union(GetRoleNames(roleInstanceList, roleNameQuery));
distinctRoleNameList = unionResult.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
}

var roleNamesCollection = new RoleNamesCollection();

foreach (var roleName in distinctRoleNameList)
{
roleNamesCollection.Add(roleName);
}

return roleNamesCollection;
}

public static Collection<ConfigurationSet> MapConfigurationSets(IList<Management.Compute.Models.ConfigurationSet> configurationSets)
{
var result = new Collection<ConfigurationSet>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class StartAzureVMCommand : IaaSDeploymentManagementCmdletBase
{
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the Virtual Machine to start.", ParameterSetName = "ByName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }
public string[] Name { get; set; }

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

protected override void ExecuteCommand()
{
Expand All @@ -47,11 +47,11 @@ protected override void ExecuteCommand()
return;
}

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

// Generate a list of role names matching wildcard patterns or
// the exact name specified in the -Name parameter.
var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, roleName);
var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, inputRoleNames);

// Insure at least one of the role name instances can be found.
if ((roleNames == null) || (!roleNames.Any()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Management.Compute;
using Microsoft.WindowsAzure.Management.Compute.Models;
using Microsoft.Azure;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Management.Automation;

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

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

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

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

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

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

// Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified.
if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent))
if (roleNames.Any(r => WildcardPattern.ContainsWildcardCharacters(r)) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent))
{
throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards);
}
Expand All @@ -93,7 +94,7 @@ protected override void ExecuteCommand()
{
this.ConfirmAction(false,
Resources.DeploymentVIPLossWarning,
string.Format(Resources.DeprovisioningVM, roleName),
string.Format(Resources.DeprovisioningVM, string.Join(", ", roleNames)),
String.Empty,
() => this.ExecuteClientActionNewSM(
null,
Expand Down Expand Up @@ -149,7 +150,7 @@ protected override void ExecuteCommand()
{
this.ConfirmAction(false,
Resources.DeploymentVIPLossWarning,
string.Format(Resources.DeprovisioningVM, roleName),
string.Format(Resources.DeprovisioningVM, string.Join(", ", roleNames)),
String.Empty,
() => this.ExecuteClientActionNewSM(
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using AutoMapper;
using Hyak.Common;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Helpers;
using Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Management.Compute;
using Microsoft.WindowsAzure.Management.Compute.Models;
using Microsoft.WindowsAzure.Storage;
using Hyak.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS
{
Expand Down Expand Up @@ -71,23 +72,14 @@ internal void ExecuteCommandNewSM()
throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible);
}

DateTime dateTimeCreated = DateTime.Now;
string diskPartName = VM.RoleName;

if (datadisk.DiskLabel != null)
{
diskPartName += "-" + datadisk.DiskLabel;
}

string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", ServiceName, diskPartName, dateTimeCreated.Year, dateTimeCreated.Month, dateTimeCreated.Day, dateTimeCreated.Millisecond);
string blobEndpoint = currentStorage.BlobEndpoint.AbsoluteUri;

if (blobEndpoint.EndsWith("/") == false)
{
blobEndpoint += "/";
}

datadisk.MediaLink = new Uri(blobEndpoint + "vhds/" + vhdname);
var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, diskPartName);
datadisk.MediaLink = mediaLinkFactory.Create();
}

if (VM.DataVirtualHardDisks.Count > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Gateway
public class GetAzureVNetGatewayIPsecParameters : NetworkCmdletBase
{
[Parameter(Position = 0, Mandatory = true, HelpMessage = "The virtual network name.")]
[ValidateGuid]
[ValidateNotNullOrEmpty]
public string VNetName
{
get; set;
}

[Parameter(Position = 1, Mandatory = true, HelpMessage = "The local network site name.")]
[ValidateGuid]
[ValidateNotNullOrEmpty]
public string LocalNetworkSiteName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

$aliases = @{
$script:aliases = @{
# Profile aliases
"Get-WAPackPublishSettingsFile" = "Get-AzurePublishSettingsFile";
"Get-WAPackSubscription" = "Get-AzureSubscription";
Expand Down Expand Up @@ -113,4 +113,4 @@ $aliases = @{
"Start-SSLegacyVolumeContainerMigrationPlan" = "Start-AzureStorSimpleLegacyVolumeContainerMigrationPlan";
}

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