예제 #1
0
    public async Async.Task <OneFuzzResultVoid> AddAutoScaleToVmss(Guid vmss, AutoscaleProfile autoScaleProfile)
    {
        _logTracer.Info($"Checking scaleset {vmss} for existing auto scale resource");

        var existingAutoScaleResource = GetAutoscaleSettings(vmss);

        if (!existingAutoScaleResource.IsOk)
        {
            return(OneFuzzResultVoid.Error(existingAutoScaleResource.ErrorV));
        }

        if (existingAutoScaleResource.OkV != null)
        {
            _logTracer.Warning($"Scaleset {vmss} already has auto scale resource");
        }

        var autoScaleResource = await CreateAutoScaleResourceFor(vmss, await _context.Creds.GetBaseRegion(), autoScaleProfile);

        if (!autoScaleResource.IsOk)
        {
            return(OneFuzzResultVoid.Error(autoScaleResource.ErrorV));
        }

        var diagnosticsResource = await SetupAutoScaleDiagnostics(autoScaleResource.OkV.Id !, autoScaleResource.OkV.Data.Name, _context.LogAnalytics.GetWorkspaceId().ToString());

        if (!diagnosticsResource.IsOk)
        {
            return(OneFuzzResultVoid.Error(diagnosticsResource.ErrorV));
        }

        return(OneFuzzResultVoid.Ok);
    }
예제 #2
0
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        public override void ExecuteCmdlet()
        {
            WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

            AutoscaleProfile profile = this.CreateSettingProfile();

            WriteObject(profile);
        }
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        public override void ExecuteCmdlet()
        {
            this.WriteIdentifiedWarning(
                cmdletName: "New-AzureRmAutoscaleProfile",
                topic: "Parameter name change",
                message: "The parameter plural names for the parameters will be deprecated in a future breaking change release in favor of the singular versions of the same names.");
            AutoscaleProfile profile = this.CreateSettingProfile();

            WriteObject(profile);
        }
 private static void AreEqual(AutoscaleProfile exp, AutoscaleProfile act)
 {
     if (exp != null)
     {
         Assert.Equal(exp.Name, act.Name);
         AreEqual(exp.Capacity, act.Capacity);
         AreEqual(exp.FixedDate, act.FixedDate);
         AreEqual(exp.Recurrence, act.Recurrence);
         for (int i = 0; i < exp.Rules.Count; i++)
         {
             AreEqual(exp.Rules[i], act.Rules[i]);
         }
     }
 }
        /// <summary>
        /// A string representation of the AutoscaleProfile object including indentation
        /// </summary>
        /// <param name="autoscaleProfile">The AutoscaleProfile object</param>
        /// <param name="indentationTabs">The number of tabs to insert in front of each member</param>
        /// <returns>A string representation of the AutoscaleProfile object including indentation</returns>
        public static string ToString(this AutoscaleProfile autoscaleProfile, int indentationTabs)
        {
            StringBuilder output = new StringBuilder();

            if (autoscaleProfile != null)
            {
                output.AppendLine();
                output.AddSpacesInFront(indentationTabs).AppendLine("Name       : " + autoscaleProfile.Name);
                output.AddSpacesInFront(indentationTabs).AppendLine("Capacity   : " + autoscaleProfile.Capacity.ToString(indentationTabs + DefaultIndentationTabs));
                output.AddSpacesInFront(indentationTabs).AppendLine("FixedDate  : " + autoscaleProfile.FixedDate.ToString(indentationTabs + DefaultIndentationTabs));
                output.AddSpacesInFront(indentationTabs).AppendLine("Recurrence : " + autoscaleProfile.Recurrence.ToString(indentationTabs + DefaultIndentationTabs));
                output.AddSpacesInFront(indentationTabs).Append("Rules      : " + autoscaleProfile.Rules.ToString(indentationTabs + DefaultIndentationTabs));
            }

            return(output.ToString());
        }
예제 #6
0
        static public AutoscaleProfile ConvertNamespace(Management.Monitor.Management.Models.AutoscaleProfile inputObject)
        {
            if (inputObject == null)
            {
                return(null);
            }

            AutoscaleProfile profile = new AutoscaleProfile(
                name: inputObject.Name,
                capacity: ConvertNamespace(inputObject.Capacity),
                rules: inputObject.Rules?.Select(ConvertNamespace).ToList(),
                fixedDate: ConvertNamespace(inputObject.FixedDate),
                recurrence: ConvertNamespace(inputObject.Recurrence));

            return(profile);
        }
예제 #7
0
        /// <param name='resourceId'>
        /// Required. The resource ID.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// A standard service response including an HTTP status code and
        /// request ID.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Monitoring.Autoscale.Models.AutoscaleSettingGetResponse> GetAsync(string resourceId, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceId == null)
            {
                throw new ArgumentNullException("resourceId");
            }

            // 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("resourceId", resourceId);
                Tracing.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            // Construct URL
            string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/monitoring/autoscalesettings?";

            url = url + "resourceId=" + Uri.EscapeDataString(resourceId.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("Accept", "application/json");
                httpRequest.Headers.Add("x-ms-version", "2013-10-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
                    AutoscaleSettingGetResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new AutoscaleSettingGetResponse();
                    JToken responseDoc = null;
                    if (string.IsNullOrEmpty(responseContent) == false)
                    {
                        responseDoc = JToken.Parse(responseContent);
                    }

                    if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                    {
                        AutoscaleSetting settingInstance = new AutoscaleSetting();
                        result.Setting = settingInstance;

                        JToken profilesArray = responseDoc["Profiles"];
                        if (profilesArray != null && profilesArray.Type != JTokenType.Null)
                        {
                            foreach (JToken profilesValue in ((JArray)profilesArray))
                            {
                                AutoscaleProfile autoscaleProfileInstance = new AutoscaleProfile();
                                settingInstance.Profiles.Add(autoscaleProfileInstance);

                                JToken nameValue = profilesValue["Name"];
                                if (nameValue != null && nameValue.Type != JTokenType.Null)
                                {
                                    string nameInstance = ((string)nameValue);
                                    autoscaleProfileInstance.Name = nameInstance;
                                }

                                JToken capacityValue = profilesValue["Capacity"];
                                if (capacityValue != null && capacityValue.Type != JTokenType.Null)
                                {
                                    ScaleCapacity capacityInstance = new ScaleCapacity();
                                    autoscaleProfileInstance.Capacity = capacityInstance;

                                    JToken minimumValue = capacityValue["Minimum"];
                                    if (minimumValue != null && minimumValue.Type != JTokenType.Null)
                                    {
                                        string minimumInstance = ((string)minimumValue);
                                        capacityInstance.Minimum = minimumInstance;
                                    }

                                    JToken maximumValue = capacityValue["Maximum"];
                                    if (maximumValue != null && maximumValue.Type != JTokenType.Null)
                                    {
                                        string maximumInstance = ((string)maximumValue);
                                        capacityInstance.Maximum = maximumInstance;
                                    }

                                    JToken defaultValue = capacityValue["Default"];
                                    if (defaultValue != null && defaultValue.Type != JTokenType.Null)
                                    {
                                        string defaultInstance = ((string)defaultValue);
                                        capacityInstance.Default = defaultInstance;
                                    }
                                }

                                JToken rulesArray = profilesValue["Rules"];
                                if (rulesArray != null && rulesArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken rulesValue in ((JArray)rulesArray))
                                    {
                                        ScaleRule scaleRuleInstance = new ScaleRule();
                                        autoscaleProfileInstance.Rules.Add(scaleRuleInstance);

                                        JToken metricTriggerValue = rulesValue["MetricTrigger"];
                                        if (metricTriggerValue != null && metricTriggerValue.Type != JTokenType.Null)
                                        {
                                            MetricTrigger metricTriggerInstance = new MetricTrigger();
                                            scaleRuleInstance.MetricTrigger = metricTriggerInstance;

                                            JToken metricNameValue = metricTriggerValue["MetricName"];
                                            if (metricNameValue != null && metricNameValue.Type != JTokenType.Null)
                                            {
                                                string metricNameInstance = ((string)metricNameValue);
                                                metricTriggerInstance.MetricName = metricNameInstance;
                                            }

                                            JToken metricNamespaceValue = metricTriggerValue["MetricNamespace"];
                                            if (metricNamespaceValue != null && metricNamespaceValue.Type != JTokenType.Null)
                                            {
                                                string metricNamespaceInstance = ((string)metricNamespaceValue);
                                                metricTriggerInstance.MetricNamespace = metricNamespaceInstance;
                                            }

                                            JToken metricSourceValue = metricTriggerValue["MetricSource"];
                                            if (metricSourceValue != null && metricSourceValue.Type != JTokenType.Null)
                                            {
                                                string metricSourceInstance = ((string)metricSourceValue);
                                                metricTriggerInstance.MetricSource = metricSourceInstance;
                                            }

                                            JToken timeGrainValue = metricTriggerValue["TimeGrain"];
                                            if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null)
                                            {
                                                TimeSpan timeGrainInstance = TypeConversion.From8601TimeSpan(((string)timeGrainValue));
                                                metricTriggerInstance.TimeGrain = timeGrainInstance;
                                            }

                                            JToken statisticValue = metricTriggerValue["Statistic"];
                                            if (statisticValue != null && statisticValue.Type != JTokenType.Null)
                                            {
                                                MetricStatisticType statisticInstance = ((MetricStatisticType)Enum.Parse(typeof(MetricStatisticType), ((string)statisticValue), true));
                                                metricTriggerInstance.Statistic = statisticInstance;
                                            }

                                            JToken timeWindowValue = metricTriggerValue["TimeWindow"];
                                            if (timeWindowValue != null && timeWindowValue.Type != JTokenType.Null)
                                            {
                                                TimeSpan timeWindowInstance = TypeConversion.From8601TimeSpan(((string)timeWindowValue));
                                                metricTriggerInstance.TimeWindow = timeWindowInstance;
                                            }

                                            JToken timeAggregationValue = metricTriggerValue["TimeAggregation"];
                                            if (timeAggregationValue != null && timeAggregationValue.Type != JTokenType.Null)
                                            {
                                                TimeAggregationType timeAggregationInstance = ((TimeAggregationType)Enum.Parse(typeof(TimeAggregationType), ((string)timeAggregationValue), true));
                                                metricTriggerInstance.TimeAggregation = timeAggregationInstance;
                                            }

                                            JToken operatorValue = metricTriggerValue["Operator"];
                                            if (operatorValue != null && operatorValue.Type != JTokenType.Null)
                                            {
                                                ComparisonOperationType operatorInstance = ((ComparisonOperationType)Enum.Parse(typeof(ComparisonOperationType), ((string)operatorValue), true));
                                                metricTriggerInstance.Operator = operatorInstance;
                                            }

                                            JToken thresholdValue = metricTriggerValue["Threshold"];
                                            if (thresholdValue != null && thresholdValue.Type != JTokenType.Null)
                                            {
                                                double thresholdInstance = ((double)thresholdValue);
                                                metricTriggerInstance.Threshold = thresholdInstance;
                                            }
                                        }

                                        JToken scaleActionValue = rulesValue["ScaleAction"];
                                        if (scaleActionValue != null && scaleActionValue.Type != JTokenType.Null)
                                        {
                                            ScaleAction scaleActionInstance = new ScaleAction();
                                            scaleRuleInstance.ScaleAction = scaleActionInstance;

                                            JToken directionValue = scaleActionValue["Direction"];
                                            if (directionValue != null && directionValue.Type != JTokenType.Null)
                                            {
                                                ScaleDirection directionInstance = ((ScaleDirection)Enum.Parse(typeof(ScaleDirection), ((string)directionValue), true));
                                                scaleActionInstance.Direction = directionInstance;
                                            }

                                            JToken typeValue = scaleActionValue["Type"];
                                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                                            {
                                                ScaleType typeInstance = ((ScaleType)Enum.Parse(typeof(ScaleType), ((string)typeValue), true));
                                                scaleActionInstance.Type = typeInstance;
                                            }

                                            JToken valueValue = scaleActionValue["Value"];
                                            if (valueValue != null && valueValue.Type != JTokenType.Null)
                                            {
                                                string valueInstance = ((string)valueValue);
                                                scaleActionInstance.Value = valueInstance;
                                            }

                                            JToken cooldownValue = scaleActionValue["Cooldown"];
                                            if (cooldownValue != null && cooldownValue.Type != JTokenType.Null)
                                            {
                                                TimeSpan cooldownInstance = TypeConversion.From8601TimeSpan(((string)cooldownValue));
                                                scaleActionInstance.Cooldown = cooldownInstance;
                                            }
                                        }
                                    }
                                }

                                JToken fixedDateValue = profilesValue["FixedDate"];
                                if (fixedDateValue != null && fixedDateValue.Type != JTokenType.Null)
                                {
                                    TimeWindow fixedDateInstance = new TimeWindow();
                                    autoscaleProfileInstance.FixedDate = fixedDateInstance;

                                    JToken timeZoneValue = fixedDateValue["TimeZone"];
                                    if (timeZoneValue != null && timeZoneValue.Type != JTokenType.Null)
                                    {
                                        string timeZoneInstance = ((string)timeZoneValue);
                                        fixedDateInstance.TimeZone = timeZoneInstance;
                                    }

                                    JToken startValue = fixedDateValue["Start"];
                                    if (startValue != null && startValue.Type != JTokenType.Null)
                                    {
                                        DateTime startInstance = ((DateTime)startValue);
                                        fixedDateInstance.Start = startInstance;
                                    }

                                    JToken endValue = fixedDateValue["End"];
                                    if (endValue != null && endValue.Type != JTokenType.Null)
                                    {
                                        DateTime endInstance = ((DateTime)endValue);
                                        fixedDateInstance.End = endInstance;
                                    }
                                }

                                JToken recurrenceValue = profilesValue["Recurrence"];
                                if (recurrenceValue != null && recurrenceValue.Type != JTokenType.Null)
                                {
                                    Recurrence recurrenceInstance = new Recurrence();
                                    autoscaleProfileInstance.Recurrence = recurrenceInstance;

                                    JToken frequencyValue = recurrenceValue["Frequency"];
                                    if (frequencyValue != null && frequencyValue.Type != JTokenType.Null)
                                    {
                                        RecurrenceFrequency frequencyInstance = ((RecurrenceFrequency)Enum.Parse(typeof(RecurrenceFrequency), ((string)frequencyValue), true));
                                        recurrenceInstance.Frequency = frequencyInstance;
                                    }

                                    JToken scheduleValue = recurrenceValue["Schedule"];
                                    if (scheduleValue != null && scheduleValue.Type != JTokenType.Null)
                                    {
                                        RecurrentSchedule scheduleInstance = new RecurrentSchedule();
                                        recurrenceInstance.Schedule = scheduleInstance;

                                        JToken timeZoneValue2 = scheduleValue["TimeZone"];
                                        if (timeZoneValue2 != null && timeZoneValue2.Type != JTokenType.Null)
                                        {
                                            string timeZoneInstance2 = ((string)timeZoneValue2);
                                            scheduleInstance.TimeZone = timeZoneInstance2;
                                        }

                                        JToken daysArray = scheduleValue["Days"];
                                        if (daysArray != null && daysArray.Type != JTokenType.Null)
                                        {
                                            foreach (JToken daysValue in ((JArray)daysArray))
                                            {
                                                scheduleInstance.Days.Add(((string)daysValue));
                                            }
                                        }

                                        JToken hoursArray = scheduleValue["Hours"];
                                        if (hoursArray != null && hoursArray.Type != JTokenType.Null)
                                        {
                                            foreach (JToken hoursValue in ((JArray)hoursArray))
                                            {
                                                scheduleInstance.Hours.Add(((int)hoursValue));
                                            }
                                        }

                                        JToken minutesArray = scheduleValue["Minutes"];
                                        if (minutesArray != null && minutesArray.Type != JTokenType.Null)
                                        {
                                            foreach (JToken minutesValue in ((JArray)minutesArray))
                                            {
                                                scheduleInstance.Minutes.Add(((int)minutesValue));
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        JToken enabledValue = responseDoc["Enabled"];
                        if (enabledValue != null && enabledValue.Type != JTokenType.Null)
                        {
                            bool enabledInstance = ((bool)enabledValue);
                            settingInstance.Enabled = enabledInstance;
                        }
                    }

                    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();
                }
            }
        }
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        public override void ExecuteCmdlet()
        {
            AutoscaleProfile profile = this.CreateSettingProfile();

            WriteObject(profile);
        }
        internal static AutoscaleSettingData DeserializeAutoscaleSettingData(JsonElement element)
        {
            IDictionary <string, string> tags   = default;
            AzureLocation            location   = default;
            ResourceIdentifier       id         = default;
            string                   name       = default;
            ResourceType             type       = default;
            SystemData               systemData = default;
            IList <AutoscaleProfile> profiles   = default;
            Optional <IList <AutoscaleNotification> > notifications = default;
            Optional <bool>   enabled                = default;
            Optional <string> name0                  = default;
            Optional <string> targetResourceUri      = default;
            Optional <string> targetResourceLocation = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("profiles"))
                        {
                            List <AutoscaleProfile> array = new List <AutoscaleProfile>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(AutoscaleProfile.DeserializeAutoscaleProfile(item));
                            }
                            profiles = array;
                            continue;
                        }
                        if (property0.NameEquals("notifications"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                notifications = null;
                                continue;
                            }
                            List <AutoscaleNotification> array = new List <AutoscaleNotification>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(AutoscaleNotification.DeserializeAutoscaleNotification(item));
                            }
                            notifications = array;
                            continue;
                        }
                        if (property0.NameEquals("enabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("name"))
                        {
                            name0 = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("targetResourceUri"))
                        {
                            targetResourceUri = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("targetResourceLocation"))
                        {
                            targetResourceLocation = property0.Value.GetString();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new AutoscaleSettingData(id, name, type, systemData, tags, location, profiles, Optional.ToList(notifications), Optional.ToNullable(enabled), name0.Value, targetResourceUri.Value, targetResourceLocation.Value));
        }
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ProcessRecord()
        {
            AutoscaleProfile profile = this.CreateSettingProfile();

            WriteObject(profile);
        }
예제 #11
0
        private static AutoscaleSettingResource CreateAutoscaleSetting(string location, string resourceUri, string metricName)
        {
            var capacity = new ScaleCapacity()
            {
                DefaultProperty = "1",
                Maximum         = "10",
                Minimum         = "1"
            };

            var fixedDate = new TimeWindow()
            {
                End      = DateTime.Parse("2014-04-16T21:06:11.7882792Z"),
                Start    = DateTime.Parse("2014-04-15T21:06:11.7882792Z"),
                TimeZone = TimeZoneInfo.Utc.Id.ToString()
            };

            var recurrence = new Recurrence()
            {
                Frequency = RecurrenceFrequency.Week,
                Schedule  = new RecurrentSchedule()
                {
                    Days = new List <string> {
                        "Monday"
                    },
                    Hours = new List <int?> {
                        0
                    },
                    Minutes = new List <int?> {
                        10
                    },
                    TimeZone = "UTC-11"
                }
            };

            var rules = new ScaleRule[]
            {
                new ScaleRule()
                {
                    MetricTrigger = new MetricTrigger
                    {
                        MetricName        = metricName,
                        MetricResourceUri = resourceUri,
                        Statistic         = MetricStatisticType.Average,
                        Threshold         = 80.0,
                        TimeAggregation   = TimeAggregationType.Maximum,
                        TimeGrain         = TimeSpan.FromMinutes(1),
                        TimeWindow        = TimeSpan.FromHours(1)
                    },
                    ScaleAction = new ScaleAction
                    {
                        Cooldown  = TimeSpan.FromMinutes(20),
                        Direction = ScaleDirection.Increase,
                        Value     = "1",
                        Type      = ScaleType.ChangeCount
                    }
                }
            };

            var profiles = new AutoscaleProfile[]
            {
                new AutoscaleProfile()
                {
                    Name       = "Profile1",
                    Capacity   = capacity,
                    FixedDate  = fixedDate,
                    Recurrence = null,
                    Rules      = rules
                },
                new AutoscaleProfile()
                {
                    Name       = "Profile2",
                    Capacity   = capacity,
                    FixedDate  = null,
                    Recurrence = recurrence,
                    Rules      = rules
                }
            };

            AutoscaleSettingResource setting = new AutoscaleSettingResource(location: Location, profiles: profiles, name: SettingName)
            {
                AutoscaleSettingResourceName = SettingName,
                TargetResourceUri            = resourceUri,
                Enabled       = true,
                Tags          = null,
                Notifications = null
            };

            return(setting);
        }
예제 #12
0
    private async Async.Task <OneFuzzResult <AutoscaleSettingResource> > CreateAutoScaleResourceFor(Guid resourceId, string location, AutoscaleProfile profile)
    {
        _logTracer.Info($"Creating auto-scale resource for: {resourceId}");

        var resourceGroup = _context.Creds.GetBaseResourceGroup();
        var subscription  = _context.Creds.GetSubscription();

        var scalesetUri = $"/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachineScaleSets/{resourceId}";
        var parameters  = new AutoscaleSettingData(location, new[] { profile })
        {
            TargetResourceId = scalesetUri,
            Enabled          = true
        };

        try {
            var autoScaleResource = await _context.Creds.GetResourceGroupResource().GetAutoscaleSettings()
                                    .CreateOrUpdateAsync(WaitUntil.Completed, Guid.NewGuid().ToString(), parameters);

            if (autoScaleResource != null && autoScaleResource.HasValue)
            {
                _logTracer.Info($"Successfully created auto scale resource {autoScaleResource.Id} for {resourceId}");
                return(OneFuzzResult <AutoscaleSettingResource> .Ok(autoScaleResource.Value));
            }

            return(OneFuzzResult <AutoscaleSettingResource> .Error(
                       ErrorCode.UNABLE_TO_CREATE,
                       $"Could not get auto scale resource value after creating for {resourceId}"
                       ));
        } catch (Exception ex) {
            _logTracer.Exception(ex);
            return(OneFuzzResult <AutoscaleSettingResource> .Error(
                       ErrorCode.UNABLE_TO_CREATE,
                       $"unable to create auto scale resource for resource: {resourceId} with profile: {profile}"));
        }
    }
예제 #13
0
 static public Management.Monitor.Management.Models.AutoscaleProfile ConvertNamespace(AutoscaleProfile inputObject)
 {
     return(new Management.Monitor.Management.Models.AutoscaleProfile(inputObject));
 }