protected override void Execute() { if (!string.IsNullOrEmpty(Name)) { try { QuotaGetResponse response = Client.Quotas.Get(Location, Name); if (response != null && response.Quota != null) { throw new AdminException(string.Format(CultureInfo.InvariantCulture, Resources.QuotaAlreadyExistsErrorMessage)); } } catch (Hyak.Common.CloudException) { // ignore this exception as the quota may not exist at all } } if (ShouldProcess(string.Format(CultureInfo.InvariantCulture, ShouldProcessTargetFormat, Name))) { QuotaCreateOrUpdateParameters request = new QuotaCreateOrUpdateParameters { Properties = new Quota { CapacityInGB = CapacityInGB, NumberOfStorageAccounts = NumberOfStorageAccounts } }; QuotaGetResponse response = Client.Quotas.CreateOrUpdate(Location, Name, request); WriteObject(new QuotaResponse(response.Quota)); } }
protected override void Execute() { Name = base.ParseNameForQuota(Name); // try to fetch the quota. // if the quota doesnt exist, this will throw an exception QuotaGetResponse getResponse = Client.Quotas.Get(Location, Name); if (ShouldProcess( Resources.SetQuotaDescription.FormatInvariantCulture(Name), Resources.SetQuotaWarning.FormatInvariantCulture(Name), Resources.ShouldProcessCaption)) { QuotaCreateOrUpdateParameters request = new QuotaCreateOrUpdateParameters { Properties = new Quota { CapacityInGB = CapacityInGB, NumberOfStorageAccounts = NumberOfStorageAccounts } }; QuotaGetResponse response = Client.Quotas.CreateOrUpdate(Location, Name, request); WriteObject(new QuotaResponse(response.Quota)); } }
protected override void Execute() { if (!string.IsNullOrEmpty(Name)) { Name = base.ParseNameForQuota(Name); QuotaGetResponse response = Client.Quotas.Get(Location, Name); WriteObject(new QuotaResponse(response.Quota)); } else { QuotaListResponse response = Client.Quotas.List(Location); WriteObject(response.Quotas.Select(q => new QuotaResponse(q)), true); } }
protected override void Execute() { Name = base.ParseNameForQuota(Name); QuotaGetResponse getResponse = Client.Quotas.Get(Location, Name); if (ShouldProcess( Resources.DeleteQuotaDescription.FormatInvariantCulture(Name), Resources.DeleteQuotaWarning.FormatInvariantCulture(Name), Resources.ShouldProcessCaption)) { var response = Client.Quotas.Delete(Location, Name); if (response.StatusCode != HttpStatusCode.OK) { throw new AdminException(string.Format(CultureInfo.InvariantCulture, Resources.OperationFailedErrorMessage, response.StatusCode)); } } }
/// <summary> /// Retrieves the specified quota from the server. /// </summary> /// <param name='serverName'> /// Required. The name of the Azure SQL Database Server from which to /// retrieve the quota. /// </param> /// <param name='quotaName'> /// Required. The name of the quota to retrieve. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Represents the response structure for the Quota Get operation. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Sql.Models.QuotaGetResponse> GetAsync(string serverName, string quotaName, CancellationToken cancellationToken) { // Validate if (serverName == null) { throw new ArgumentNullException("serverName"); } if (quotaName == null) { throw new ArgumentNullException("quotaName"); } // 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("serverName", serverName); tracingParameters.Add("quotaName", quotaName); Tracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = "/" + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId) + "/services/sqlservers/servers/" + Uri.EscapeDataString(serverName) + "/serverquotas/" + Uri.EscapeDataString(quotaName); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2012-03-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // 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.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result QuotaGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new QuotaGetResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement serviceResourceElement = responseDoc.Element(XName.Get("ServiceResource", "http://schemas.microsoft.com/windowsazure")); if (serviceResourceElement != null) { XElement serviceResourceElement2 = serviceResourceElement.Element(XName.Get("ServiceResource", "http://schemas.microsoft.com/windowsazure")); if (serviceResourceElement2 != null) { Quota serviceResourceInstance = new Quota(); result.Quota = serviceResourceInstance; XElement valueElement = serviceResourceElement2.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")); if (valueElement != null) { string valueInstance = valueElement.Value; serviceResourceInstance.Value = valueInstance; } XElement nameElement = serviceResourceElement2.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; serviceResourceInstance.Name = nameInstance; } XElement typeElement = serviceResourceElement2.Element(XName.Get("Type", "http://schemas.microsoft.com/windowsazure")); if (typeElement != null) { string typeInstance = typeElement.Value; serviceResourceInstance.Type = typeInstance; } XElement stateElement = serviceResourceElement2.Element(XName.Get("State", "http://schemas.microsoft.com/windowsazure")); if (stateElement != null) { string stateInstance = stateElement.Value; serviceResourceInstance.State = stateInstance; } } } 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(); } } }