コード例 #1
0
        /// <summary>
        /// 本接口(DescribeLifecycleHooks)用于查询生命周期挂钩信息。
        ///
        /// * 可以根据伸缩组ID、生命周期挂钩ID或者生命周期挂钩名称等信息来查询生命周期挂钩的详细信息。过滤信息详细请见过滤器`Filter`。
        /// * 如果参数为空,返回当前用户一定数量(`Limit`所指定的数量,默认为20)的生命周期挂钩。
        /// </summary>
        /// <param name="req">参考<see cref="DescribeLifecycleHooksRequest"/></param>
        /// <returns>参考<see cref="DescribeLifecycleHooksResponse"/>实例</returns>
        public async Task <DescribeLifecycleHooksResponse> DescribeLifecycleHooks(DescribeLifecycleHooksRequest req)
        {
            JsonResponseModel <DescribeLifecycleHooksResponse> rsp = null;

            try
            {
                var strResp = await this.InternalRequest(req, "DescribeLifecycleHooks");

                rsp = JsonConvert.DeserializeObject <JsonResponseModel <DescribeLifecycleHooksResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
コード例 #2
0
        /// <summary>
        /// checks to see if this is an autoscaled instance
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        private bool IsAutoscaledInstance()
        {
            bool returnValue = false;

            if (!_InstanceId.IsNullOrWhiteSpace())
            {
                using (AmazonAutoScalingClient scalingClient = new AmazonAutoScalingClient())
                {
                    DescribeAutoScalingInstancesRequest describeAutoScalingInstancesRequest = new DescribeAutoScalingInstancesRequest
                    {
                        InstanceIds = new List <string>(new string[] { _InstanceId })
                    };
                    try
                    {
                        DescribeAutoScalingInstancesResponse describeAutoScalingInstancesResponse = scalingClient.DescribeAutoScalingInstancesAsync(describeAutoScalingInstancesRequest).Result;
                        if (describeAutoScalingInstancesResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                        {
                            foreach (AutoScalingInstanceDetails instDetail in describeAutoScalingInstancesResponse.AutoScalingInstances)
                            {
                                if (instDetail.InstanceId.CaseInsensitiveEquals(_InstanceId))
                                {
                                    _AutoScalingGroupName = instDetail.AutoScalingGroupName;
                                    returnValue           = true;
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //Yes AWS throws Exceptions and System.AggregrateExceptions
                        //so for now this is the right way to handle it
                        returnValue = false;
                    }
                    if (returnValue)
                    {
                        DescribeLifecycleHooksRequest describeLifecycleHooksRequest = new DescribeLifecycleHooksRequest
                        {
                            AutoScalingGroupName = _AutoScalingGroupName
                        };
                        try
                        {
                            DescribeLifecycleHooksResponse describeLifecycleHooksResponse = scalingClient.DescribeLifecycleHooksAsync(describeLifecycleHooksRequest).Result;

                            if (describeLifecycleHooksResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                            {
                                foreach (LifecycleHook lifecycleHook in describeLifecycleHooksResponse.LifecycleHooks)
                                {
                                    if (lifecycleHook.LifecycleTransition.CaseInsensitiveEquals("autoscaling:EC2_INSTANCE_TERMINATING"))
                                    {
                                        _TerminatingLifeCycleHookName = lifecycleHook.LifecycleHookName;
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            //Yes AWS throws Exceptions and System.AggregrateExceptions
                            //so for now this is the right way to handle it
                            returnValue = false;
                        }
                    }
                }
            }
            return(returnValue);
        }