internal static string ToSerializedValue(this WorkerSizeOptions value) { switch (value) { case WorkerSizeOptions.Small: return("Small"); case WorkerSizeOptions.Medium: return("Medium"); case WorkerSizeOptions.Large: return("Large"); case WorkerSizeOptions.D1: return("D1"); case WorkerSizeOptions.D2: return("D2"); case WorkerSizeOptions.D3: return("D3"); case WorkerSizeOptions.Default: return("Default"); } return(null); }
public WebHostingPlanCreateOrUpdateResponse CreateAppServicePlan(string resourceGroupName, string whpName, string location, string adminSiteName, int numberOfWorkers, SkuOptions sku, WorkerSizeOptions workerSize) { WebHostingPlanProperties webHostingPlanProperties = new WebHostingPlanProperties(); webHostingPlanProperties.Sku = sku; webHostingPlanProperties.AdminSiteName = adminSiteName; webHostingPlanProperties.NumberOfWorkers = numberOfWorkers; webHostingPlanProperties.WorkerSize = workerSize; WebHostingPlan webHostingPlan = new WebHostingPlan(); WebHostingPlanCreateOrUpdateParameters webHostingPlanCreateOrUpdateParameters = new WebHostingPlanCreateOrUpdateParameters(webHostingPlan); webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Location = location; webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Name = whpName; webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Properties = webHostingPlanProperties; var createdWHP = WrappedWebsitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, webHostingPlanCreateOrUpdateParameters); //proper return type need to be discussed return(createdWHP); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="WorkerSizeOptions" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => WorkerSizeOptions.CreateFrom(sourceValue);
public WebHostingPlanCreateOrUpdateResponse CreateAppServicePlan(string resourceGroupName, string whpName, string location, string adminSiteName, int numberOfWorkers, SkuOptions sku, WorkerSizeOptions workerSize) { WebHostingPlanProperties webHostingPlanProperties = new WebHostingPlanProperties(); webHostingPlanProperties.Sku = sku; webHostingPlanProperties.AdminSiteName = adminSiteName; webHostingPlanProperties.NumberOfWorkers = numberOfWorkers; webHostingPlanProperties.WorkerSize = workerSize; WebHostingPlan webHostingPlan = new WebHostingPlan(); WebHostingPlanCreateOrUpdateParameters webHostingPlanCreateOrUpdateParameters = new WebHostingPlanCreateOrUpdateParameters(webHostingPlan); webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Location = location; webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Name = whpName; webHostingPlanCreateOrUpdateParameters.WebHostingPlan.Properties = webHostingPlanProperties; var createdWHP = WrappedWebsitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, webHostingPlanCreateOrUpdateParameters); //proper return type need to be discussed return createdWHP; }
public override void ExecuteCmdlet() { //for now not asking admin site name need to implement in future string adminSiteName = null; //if Sku is not specified assume default to be Standard SkuOptions skuInput = SkuOptions.Standard; //if workerSize is not specified assume default to be small WorkerSizeOptions workerSizeInput = WorkerSizeOptions.Small; //if NumberofWorkers is not specified assume default to be 1 if (NumberofWorkers == 0) { NumberofWorkers = 1; } if (WorkerSize != null) { switch (WorkerSize.ToUpper()) { case "SMALL": workerSizeInput = WorkerSizeOptions.Small; break; case "MEDIUM": workerSizeInput = WorkerSizeOptions.Medium; break; case "LARGE": workerSizeInput = WorkerSizeOptions.Large; break; default: workerSizeInput = WorkerSizeOptions.Large; break; } } if (Sku != null) { switch (Sku.ToUpper()) { case "FREE": skuInput = SkuOptions.Free; break; case "SHARED": skuInput = SkuOptions.Shared; break; case "BASIC": skuInput = SkuOptions.Basic; break; case "PREMIUM": skuInput = SkuOptions.Premium; break; default: skuInput = SkuOptions.Standard; break; } } WriteObject(WebsitesClient.CreateAppServicePlan(ResourceGroupName, Name, Location, adminSiteName, NumberofWorkers, skuInput, workerSizeInput)); }
public static string ToSerialString(this WorkerSizeOptions value) => value switch {
/// <summary> /// You can retrieve details for a specified web hosting plan name by /// issuing an HTTP GET request. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167017.aspx /// for more information) /// </summary> /// <param name='webSpaceName'> /// Required. The name of the web space. /// </param> /// <param name='webHostingPlanName'> /// Required. The name of the web hosting plan. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The Get Web Hosting Plans details operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.WebSites.Models.WebHostingPlanGetResponse> GetAsync(string webSpaceName, string webHostingPlanName, CancellationToken cancellationToken) { // Validate if (webSpaceName == null) { throw new ArgumentNullException("webSpaceName"); } if (webHostingPlanName == null) { throw new ArgumentNullException("webHostingPlanName"); } // 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("webSpaceName", webSpaceName); tracingParameters.Add("webHostingPlanName", webHostingPlanName); Tracing.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/WebSpaces/" + webSpaceName.Trim() + "/serverFarms/" + webHostingPlanName.Trim(); 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", "2013-08-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 WebHostingPlanGetResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new WebHostingPlanGetResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement serverFarmElement = responseDoc.Element(XName.Get("ServerFarm", "http://schemas.microsoft.com/windowsazure")); if (serverFarmElement != null) { XElement nameElement = serverFarmElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; result.Name = nameInstance; } XElement sKUElement = serverFarmElement.Element(XName.Get("SKU", "http://schemas.microsoft.com/windowsazure")); if (sKUElement != null) { string sKUInstance = sKUElement.Value; result.SKU = sKUInstance; } XElement workerSizeElement = serverFarmElement.Element(XName.Get("WorkerSize", "http://schemas.microsoft.com/windowsazure")); if (workerSizeElement != null && string.IsNullOrEmpty(workerSizeElement.Value) == false) { WorkerSizeOptions workerSizeInstance = ((WorkerSizeOptions)Enum.Parse(typeof(WorkerSizeOptions), workerSizeElement.Value, true)); result.WorkerSize = workerSizeInstance; } XElement numberOfWorkersElement = serverFarmElement.Element(XName.Get("NumberOfWorkers", "http://schemas.microsoft.com/windowsazure")); if (numberOfWorkersElement != null && string.IsNullOrEmpty(numberOfWorkersElement.Value) == false) { int numberOfWorkersInstance = int.Parse(numberOfWorkersElement.Value, CultureInfo.InvariantCulture); result.NumberOfWorkers = numberOfWorkersInstance; } XElement currentWorkerSizeElement = serverFarmElement.Element(XName.Get("CurrentWorkerSize", "http://schemas.microsoft.com/windowsazure")); if (currentWorkerSizeElement != null && string.IsNullOrEmpty(currentWorkerSizeElement.Value) == false) { WorkerSizeOptions currentWorkerSizeInstance = ((WorkerSizeOptions)Enum.Parse(typeof(WorkerSizeOptions), currentWorkerSizeElement.Value, true)); result.CurrentWorkerSize = currentWorkerSizeInstance; } XElement currentNumberOfWorkersElement = serverFarmElement.Element(XName.Get("CurrentNumberOfWorkers", "http://schemas.microsoft.com/windowsazure")); if (currentNumberOfWorkersElement != null && string.IsNullOrEmpty(currentNumberOfWorkersElement.Value) == false) { int currentNumberOfWorkersInstance = int.Parse(currentNumberOfWorkersElement.Value, CultureInfo.InvariantCulture); result.CurrentNumberOfWorkers = currentNumberOfWorkersInstance; } XElement statusElement = serverFarmElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure")); if (statusElement != null) { StatusOptions statusInstance = ((StatusOptions)Enum.Parse(typeof(StatusOptions), statusElement.Value, true)); result.Status = statusInstance; } } 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(); } } }