public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { var avSetParams = new AvailabilitySet { Location = this.Location, PlatformUpdateDomainCount = this.PlatformUpdateDomainCount, PlatformFaultDomainCount = this.PlatformFaultDomainCount }; var result = this.AvailabilitySetClient.CreateOrUpdateWithHttpMessagesAsync( this.ResourceGroupName, this.Name, avSetParams).GetAwaiter().GetResult(); var psResult = Mapper.Map<PSAvailabilitySet>(result); if (result.Body != null) { psResult = Mapper.Map(result.Body, psResult); } WriteObject(psResult); }); }
/// <summary> /// The operation to create or update the availability set. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Compute.IAvailabilitySetOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the Create Availability Set /// operation. /// </param> /// <returns> /// The Create Availability Set operation response. /// </returns> public static AvailabilitySetCreateOrUpdateResponse CreateOrUpdate(this IAvailabilitySetOperations operations, string resourceGroupName, AvailabilitySet parameters) { return Task.Factory.StartNew((object s) => { return ((IAvailabilitySetOperations)s).CreateOrUpdateAsync(resourceGroupName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); var avSetParams = new AvailabilitySet { Name = this.Name, Location = this.Location, PlatformUpdateDomainCount = this.PlatformUpdateDomainCount, PlatformFaultDomainCount = this.PlatformFaultDomainCount }; var op = this.AvailabilitySetClient.CreateOrUpdate( this.ResourceGroupName, avSetParams); WriteObject(op); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); var avSetParams = new AvailabilitySet { Name = this.Name, Location = this.Location, PlatformUpdateDomainCount = this.PlatformUpdateDomainCount, PlatformFaultDomainCount = this.PlatformFaultDomainCount }; var result = this.AvailabilitySetClient.CreateOrUpdate( this.ResourceGroupName, avSetParams); var psResult = Mapper.Map<PSAvailabilitySet>(result.AvailabilitySet); psResult = Mapper.Map<AzureOperationResponse, PSAvailabilitySet>(result, psResult); WriteObject(psResult); }
protected string CreateAvailabilitySet(string rgName, string asName) { // Setup availability set var inputAvailabilitySet = new AvailabilitySet { Location = m_location, Name = asName, Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"} } }; // Create an Availability Set and then create a VM inside this availability set var asCreateOrUpdateResponse = m_CrpClient.AvailabilitySets.CreateOrUpdate( rgName, inputAvailabilitySet ); var asetId = Helpers.GetAvailabilitySetRef(m_subId, rgName, asCreateOrUpdateResponse.AvailabilitySet.Name); Assert.True(asCreateOrUpdateResponse.StatusCode == HttpStatusCode.OK); return asetId; }
/// <summary> /// The operation to create or update the availability set. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Compute.IAvailabilitySetOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the Create Availability Set /// operation. /// </param> /// <returns> /// The Create Availability Set operation response. /// </returns> public static Task<AvailabilitySetCreateOrUpdateResponse> CreateOrUpdateAsync(this IAvailabilitySetOperations operations, string resourceGroupName, AvailabilitySet parameters) { return operations.CreateOrUpdateAsync(resourceGroupName, parameters, CancellationToken.None); }
private void ValidateAvailabilitySet(AvailabilitySet inputAvailabilitySet, AvailabilitySet outputAvailabilitySet, string expectedAvailabilitySetId, int expectedFD, int expectedUD) { Assert.True(inputAvailabilitySet.Name == outputAvailabilitySet.Name); Assert.True(outputAvailabilitySet.Type == ApiConstants.ResourceProviderNamespace + "/" + ApiConstants.AvailabilitySets); Assert.True(outputAvailabilitySet != null); Assert.True(outputAvailabilitySet.PlatformFaultDomainCount == expectedFD); Assert.True(outputAvailabilitySet.PlatformUpdateDomainCount == expectedUD); Assert.NotNull(inputAvailabilitySet.Tags); Assert.NotNull(outputAvailabilitySet.Tags); foreach (var tag in inputAvailabilitySet.Tags) { string key = tag.Key; Assert.True(inputAvailabilitySet.Tags[key] == outputAvailabilitySet.Tags[key]); } // TODO: Dev work corresponding to setting status is not yet checked in. //Assert.NotNull(outputAvailabilitySet.Properties.Id); //Assert.True(expectedAvailabilitySetIds.ToLowerInvariant() == outputAvailabilitySet.Properties.Id.ToLowerInvariant()); }
private void ValidateResults(AvailabilitySetCreateOrUpdateResponse createOrUpdateResponse, AvailabilitySet inputAvailabilitySet, int expectedFD, int expectedUD) { string expectedAvailabilitySetId = Helpers.GetAvailabilitySetRef(subId, resourceGroupName, inputAvailabilitySet.Name); Assert.True(createOrUpdateResponse.StatusCode == HttpStatusCode.OK); Assert.True(createOrUpdateResponse.AvailabilitySet.Name == inputAvailabilitySet.Name); Assert.True(createOrUpdateResponse.AvailabilitySet.Location.ToLower() == this.location.ToLower() || createOrUpdateResponse.AvailabilitySet.Location.ToLower() == inputAvailabilitySet.Location.ToLower()); ValidateAvailabilitySet(inputAvailabilitySet, createOrUpdateResponse.AvailabilitySet, expectedAvailabilitySetId, expectedFD, expectedUD); // GET AvailabilitySet var getResponse = computeClient.AvailabilitySets.Get(resourceGroupName, inputAvailabilitySet.Name); Assert.True(getResponse.StatusCode == HttpStatusCode.OK); ValidateAvailabilitySet(inputAvailabilitySet, getResponse.AvailabilitySet, expectedAvailabilitySetId, expectedFD, expectedUD); // List AvailabilitySets var listResponse = computeClient.AvailabilitySets.List(resourceGroupName); Assert.True(listResponse.StatusCode == HttpStatusCode.OK); ValidateAvailabilitySet(inputAvailabilitySet, listResponse.AvailabilitySets.FirstOrDefault(x => x.Name == inputAvailabilitySet.Name), expectedAvailabilitySetId, expectedFD, expectedUD); var listVMSizesResponse = computeClient.AvailabilitySets.ListAvailableSizes(resourceGroupName, inputAvailabilitySet.Name); Assert.True(listVMSizesResponse.StatusCode == HttpStatusCode.OK); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse); // Delete AvailabilitySet var deleteOperationResponse = computeClient.AvailabilitySets.Delete(resourceGroupName, inputAvailabilitySet.Name); Assert.True(deleteOperationResponse.StatusCode == HttpStatusCode.OK); }
private void VerifyInvalidFDUDValuesFail() { var inputAvailabilitySet = new AvailabilitySet { Location = location, Name = TestUtilities.GenerateName("invalidfdud"), Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"}, }, }; // function to test the limits available. inputAvailabilitySet.PlatformFaultDomainCount = FDTooLow; AvailabilitySetCreateOrUpdateResponse createOrUpdateResponse = null; try { createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate( resourceGroupName, inputAvailabilitySet); } catch (Hyak.Common.CloudException ex) { Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest); Assert.True(ex.Error.Code == "InvalidParameter"); } Assert.True(createOrUpdateResponse == null); inputAvailabilitySet.PlatformFaultDomainCount = FDTooHi; try { createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate( resourceGroupName, inputAvailabilitySet); } catch (Hyak.Common.CloudException ex) { Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest); Assert.True(ex.Error.Code == "InvalidParameter"); } Assert.True(createOrUpdateResponse == null); inputAvailabilitySet.PlatformUpdateDomainCount = UDTooLow; try { createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate( resourceGroupName, inputAvailabilitySet); } catch (Hyak.Common.CloudException ex) { Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest); Assert.True(ex.Error.Code == "InvalidParameter"); } Assert.True(createOrUpdateResponse == null); inputAvailabilitySet.PlatformUpdateDomainCount = UDTooHi; try { createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate( resourceGroupName, inputAvailabilitySet); } catch (Hyak.Common.CloudException ex) { Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest); Assert.True(ex.Error.Code == "InvalidParameter"); } Assert.True(createOrUpdateResponse == null); }
private void VerifyDefaultValuesSucceed() { var inputAvailabilitySet = new AvailabilitySet { Location = location, Name = TestUtilities.GenerateName("asdefaultvalues"), Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"}, }, }; var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate( resourceGroupName, inputAvailabilitySet); // This call will also delete the Availability Set ValidateResults(createOrUpdateResponse, inputAvailabilitySet, defaultFD, defaultUD); }
private void VerifyNonDefaultValuesSucceed() { // Negative tests for a bug in 5.0.0 that read-only fields have side-effect on the request body var testStatus = new InstanceViewStatus { Code = "test", DisplayStatus = "test", Message = "test" }; var inputAvailabilitySet = new AvailabilitySet { Location = location, Name = TestUtilities.GenerateName("asnondefault"), Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"}, }, PlatformFaultDomainCount = nonDefaultFD, PlatformUpdateDomainCount = nonDefaultUD, Statuses = new List<InstanceViewStatus>() { testStatus } }; var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate( resourceGroupName, inputAvailabilitySet); // This call will also delete the Availability Set ValidateResults(createOrUpdateResponse, inputAvailabilitySet, nonDefaultFD, nonDefaultUD); }
private void VerifyUpdateFails() { var availabilitySetName = TestUtilities.GenerateName("asupdateFails"); var inputAvailabilitySet = new AvailabilitySet { Location = location, Name = availabilitySetName, Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"}, } }; // Create and expect success. var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroupName, inputAvailabilitySet); Assert.True(createOrUpdateResponse.StatusCode == HttpStatusCode.OK); try // Modify the FD and expect failure { inputAvailabilitySet = new AvailabilitySet { Location = location, Name = availabilitySetName, Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"}, }, PlatformFaultDomainCount = nonDefaultFD, }; createOrUpdateResponse = null; createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroupName, inputAvailabilitySet); } catch (Hyak.Common.CloudException ex) { Assert.True(ex.Response.StatusCode == HttpStatusCode.Forbidden); Assert.True(ex.Error.Code == "PropertyChangeNotAllowed"); } Assert.True(createOrUpdateResponse == null); try // Modify the UD and expect failure { inputAvailabilitySet = new AvailabilitySet { Location = location, Name = availabilitySetName, Tags = new Dictionary<string, string>() { {"RG", "rg"}, {"testTag", "1"}, }, PlatformUpdateDomainCount = nonDefaultUD, }; createOrUpdateResponse = null; createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroupName, inputAvailabilitySet); } catch (Hyak.Common.CloudException ex) { Assert.True(ex.Response.StatusCode == HttpStatusCode.Forbidden); Assert.True(ex.Error.Code == "PropertyChangeNotAllowed"); } Assert.True(createOrUpdateResponse == null); // Clean up var deleteOperationResponse = computeClient.AvailabilitySets.Delete(resourceGroupName, availabilitySetName); }