/// <summary> /// Create affinity group /// </summary> /// <param name="input"></param> public void CreateAffinityGroup(AffinityGroupCreateParameters input) { TestEasyLog.Instance.Info(string.Format("Creating affinity group '{0}'", input.Name)); ManagementClient.AffinityGroups.CreateAsync(input, new CancellationToken()).Wait(); Dependencies.TestResourcesCollector.Remember(AzureResourceType.AffinityGroup, input.Name, input.Name); }
public void ExecuteCommand() { ServiceManagementProfile.Initialize(); if (string.IsNullOrEmpty(Label)) { Label = Name; } var input = new AffinityGroupCreateParameters { Description = this.Description, Label = this.Label, Location = this.Location, Name = this.Name }; ExecuteClientActionNewSM( null, CommandRuntime.ToString(), () => this.ManagementClient.AffinityGroups.Create(input)); }
public void ExecuteCommand() { ServiceManagementProfile.Initialize(); if (string.IsNullOrEmpty(Label)) { Label = Name; } var input = new AffinityGroupCreateParameters { Description = this.Description, Label = this.Label, Location = this.Location, Name = this.Name }; ExecuteClientActionNewSM( null, CommandRuntime.ToString(), () => this.ManagementClient.AffinityGroups.Create(input)); }
/// <summary> /// The Create Affinity Group operation creates a new affinity group /// for the specified subscription. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.IAffinityGroupOperations. /// </param> /// <param name='parameters'> /// Parameters supplied to the Create Affinity Group operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <OperationResponse> CreateAsync(this IAffinityGroupOperations operations, AffinityGroupCreateParameters parameters) { return(operations.CreateAsync(parameters, CancellationToken.None)); }
/// <summary> /// The Create Affinity Group operation creates a new affinity group /// for the specified subscription. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.IAffinityGroupOperations. /// </param> /// <param name='parameters'> /// Parameters supplied to the Create Affinity Group operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static OperationResponse Create(this IAffinityGroupOperations operations, AffinityGroupCreateParameters parameters) { try { return(operations.CreateAsync(parameters).Result); } catch (AggregateException ex) { if (ex.InnerExceptions.Count > 1) { throw; } else { throw ex.InnerException; } } }
/// <summary> /// The Create Affinity Group operation creates a new affinity group /// for the specified subscription. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.IAffinityGroupOperations. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the Create Affinity Group /// operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static OperationResponse Create(this IAffinityGroupOperations operations, AffinityGroupCreateParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IAffinityGroupOperations)s).CreateAsync(parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// The Create Affinity Group operation creates a new affinity group /// for the specified subscription. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx /// for more information) /// </summary> /// <param name='parameters'> /// Parameters supplied to the Create Affinity Group operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async Task <OperationResponse> CreateAsync(AffinityGroupCreateParameters parameters, CancellationToken cancellationToken) { // Validate if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.Description != null && parameters.Description.Length > 1024) { throw new ArgumentOutOfRangeException("parameters.Description"); } if (parameters.Label == null) { throw new ArgumentNullException("parameters.Label"); } if (parameters.Label.Length > 100) { throw new ArgumentOutOfRangeException("parameters.Label"); } if (parameters.Location == null) { throw new ArgumentNullException("parameters.Location"); } if (parameters.Name == null) { throw new ArgumentNullException("parameters.Name"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("parameters", parameters); Tracing.Enter(invocationId, this, "CreateAsync", tracingParameters); } // Construct URL string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/affinitygroups"; // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Post; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2013-03-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; XDocument requestDoc = new XDocument(); XElement createAffinityGroupElement = new XElement(XName.Get("CreateAffinityGroup", "http://schemas.microsoft.com/windowsazure")); requestDoc.Add(createAffinityGroupElement); XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); nameElement.Value = parameters.Name; createAffinityGroupElement.Add(nameElement); XElement labelElement = new XElement(XName.Get("Label", "http://schemas.microsoft.com/windowsazure")); labelElement.Value = TypeConversion.ToBase64String(parameters.Label); createAffinityGroupElement.Add(labelElement); if (parameters.Description != null) { XElement descriptionElement = new XElement(XName.Get("Description", "http://schemas.microsoft.com/windowsazure")); descriptionElement.Value = parameters.Description; createAffinityGroupElement.Add(descriptionElement); } XElement locationElement = new XElement(XName.Get("Location", "http://schemas.microsoft.com/windowsazure")); locationElement.Value = parameters.Location; createAffinityGroupElement.Add(locationElement); requestContent = requestDoc.ToString(); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.Created) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; result = new OperationResponse(); result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
public void CanListRoleSizeInfo() { using (var undoContext = UndoContext.Current) { undoContext.Start(); string affinityGroupName = HttpMockServer.GetAssetName("CanListRoleSizeInfo", "testag"); var mgmt = this.GetManagementClient(); var roleSizeList = mgmt.RoleSizes.List(); foreach (var loc in mgmt.Locations.List()) { Assert.True(loc.ComputeCapabilities != null); Assert.True(loc.ComputeCapabilities.VirtualMachinesRoleSizes.Any()); foreach (var r in loc.ComputeCapabilities.VirtualMachinesRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } Assert.True(loc.ComputeCapabilities.WebWorkerRoleSizes.Any()); foreach (var r in loc.ComputeCapabilities.WebWorkerRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any()); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_LRS", s, StringComparison.OrdinalIgnoreCase))); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_GRS", s, StringComparison.OrdinalIgnoreCase))); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_RAGRS", s, StringComparison.OrdinalIgnoreCase))); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_ZRS", s, StringComparison.OrdinalIgnoreCase))); } var locName = mgmt.Locations.List().First().Name; var agParam = new AffinityGroupCreateParameters { Name = affinityGroupName, Label = affinityGroupName + "Label", Description = affinityGroupName + "Description", Location = locName }; mgmt.AffinityGroups.Create(agParam); var agGetResult = mgmt.AffinityGroups.Get(affinityGroupName); Assert.True(agGetResult.Name.Equals(agParam.Name)); Assert.True(agGetResult.Label.Equals(agParam.Label)); Assert.True(agGetResult.Description.Equals(agParam.Description)); Assert.True(agGetResult.Location.Equals(agParam.Location)); var ag = mgmt.AffinityGroups.List().First(g => g.Name.Equals(affinityGroupName)); Assert.True(ag.ComputeCapabilities != null); Assert.True(ag.ComputeCapabilities.VirtualMachinesRoleSizes.Any()); foreach (var r in ag.ComputeCapabilities.VirtualMachinesRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } Assert.True(ag.ComputeCapabilities.WebWorkerRoleSizes.Any()); foreach (var r in ag.ComputeCapabilities.WebWorkerRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } } }
public void CanListRoleSizeInfo() { using (var undoContext = UndoContext.Current) { undoContext.Start(); string affinityGroupName = HttpMockServer.GetAssetName("CanListRoleSizeInfo", "testag"); var mgmt = this.GetManagementClient(); var roleSizeList = mgmt.RoleSizes.List(); foreach (var loc in mgmt.Locations.List()) { Assert.True(loc.ComputeCapabilities != null); Assert.True(loc.ComputeCapabilities.VirtualMachinesRoleSizes.Any()); foreach (var r in loc.ComputeCapabilities.VirtualMachinesRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } Assert.True(loc.ComputeCapabilities.WebWorkerRoleSizes.Any()); foreach (var r in loc.ComputeCapabilities.WebWorkerRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any()); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_LRS", s, StringComparison.OrdinalIgnoreCase))); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_GRS", s, StringComparison.OrdinalIgnoreCase))); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_RAGRS", s, StringComparison.OrdinalIgnoreCase))); Assert.True(loc.StorageCapabilities.StorageAccountTypes.Any( s => string.Equals("Standard_ZRS", s, StringComparison.OrdinalIgnoreCase))); } var locName = mgmt.Locations.List().First().Name; var agParam = new AffinityGroupCreateParameters { Name = affinityGroupName, Label = affinityGroupName + "Label", Description = affinityGroupName + "Description", Location = locName }; mgmt.AffinityGroups.Create(agParam); var agGetResult = mgmt.AffinityGroups.Get(affinityGroupName); Assert.True(agGetResult.Name.Equals(agParam.Name)); Assert.True(agGetResult.Label.Equals(agParam.Label)); Assert.True(agGetResult.Description.Equals(agParam.Description)); Assert.True(agGetResult.Location.Equals(agParam.Location)); var ag = mgmt.AffinityGroups.List().First(g => g.Name.Equals(affinityGroupName)); Assert.True(ag.ComputeCapabilities != null); Assert.True(ag.ComputeCapabilities.VirtualMachinesRoleSizes.Any()); foreach (var r in ag.ComputeCapabilities.VirtualMachinesRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } Assert.True(ag.ComputeCapabilities.WebWorkerRoleSizes.Any()); foreach (var r in ag.ComputeCapabilities.WebWorkerRoleSizes) { Assert.True(roleSizeList.Any(s => string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))); } } }