Skip to content

Commit a0aabba

Browse files
Check availability set.
1 parent 561679e commit a0aabba

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using Microsoft.Azure.Management.Compute.Models;
3030
using Microsoft.Azure.Management.Storage;
3131
using Microsoft.Azure.Management.Storage.Models;
32+
using Microsoft.Rest.Azure;
3233
using Microsoft.WindowsAzure.Commands.Sync.Download;
3334
using Microsoft.WindowsAzure.Commands.Tools.Vhd;
3435
using Microsoft.WindowsAzure.Commands.Tools.Vhd.Model;
@@ -335,24 +336,35 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
335336
Math.DivRem(filePath.Length, divisor, out rem);
336337
if (rem != 0)
337338
{
338-
throw new ArgumentOutOfRangeException("filePath", string.Format("Given vhd file '{0}' is a corrupted fixed vhd", filePath));
339+
throw new ArgumentOutOfRangeException(
340+
"filePath",
341+
string.Format("Given vhd file '{0}' is a corrupted fixed vhd", filePath));
339342
}
340343
}
341344
}
342345
var storageAccount = storageClient.StorageAccounts.GetProperties(ResourceGroupName, Name);
343346
BlobUri destinationUri = null;
344-
BlobUri.TryParseUri(new Uri(string.Format("{0}{1}/{2}{3}", storageAccount.PrimaryEndpoints.Blob, Name.ToLower(), Name.ToLower(), ".vhd")), out destinationUri);
347+
BlobUri.TryParseUri(
348+
new Uri(string.Format(
349+
"{0}{1}/{2}{3}",
350+
storageAccount.PrimaryEndpoints.Blob,
351+
Name.ToLower(),
352+
Name.ToLower(),
353+
".vhd")),
354+
out destinationUri);
345355
if (destinationUri == null || destinationUri.Uri == null)
346356
{
347357
throw new ArgumentNullException("destinationUri");
348358
}
349-
var storageCredentialsFactory = new StorageCredentialsFactory(this.ResourceGroupName, storageClient, DefaultContext.Subscription);
359+
var storageCredentialsFactory = new StorageCredentialsFactory(
360+
this.ResourceGroupName, storageClient, DefaultContext.Subscription);
350361
var parameters = new UploadParameters(destinationUri, null, filePath, true, 2)
351362
{
352363
Cmdlet = this,
353364
BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1))
354365
};
355-
if (!string.Equals(Environment.GetEnvironmentVariable("AZURE_TEST_MODE"), "Playback", StringComparison.OrdinalIgnoreCase))
366+
if (!string.Equals(
367+
Environment.GetEnvironmentVariable("AZURE_TEST_MODE"), "Playback", StringComparison.OrdinalIgnoreCase))
356368
{
357369
var st2 = VhdUploaderModel.Upload(parameters);
358370
}
@@ -386,7 +398,12 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
386398
var fqdn = DomainNameLabel + "." + Location + ".cloudapp.azure.com";
387399

388400
// create target state
389-
var target = virtualMachine.GetTargetState(current, client.SubscriptionId, Location);
401+
var target = virtualMachine.GetTargetState(current, client.SubscriptionId, Location);
402+
403+
if (target.Get(availabilitySet) != null)
404+
{
405+
throw new CloudException("Availability set doesn't exsist.");
406+
}
390407

391408
// apply target state
392409
var newState = await virtualMachine

0 commit comments

Comments
 (0)