/// <summary>
        /// detact this instance from the ASG
        /// and decrement the ASG desired
        /// </summary>
        /// <returns></returns>
        private bool DetachFromAutoScalingGroup()
        {
            bool returnValue = false;

            using (AmazonAutoScalingClient scalingClient = new AmazonAutoScalingClient())
            {
                DetachInstancesRequest detachRequest = new DetachInstancesRequest
                {
                    AutoScalingGroupName           = _AutoScalingGroupName,
                    InstanceIds                    = new List <string>(new string[] { _InstanceId }),
                    ShouldDecrementDesiredCapacity = true
                };
                try
                {
                    DetachInstancesResponse detachResponse = scalingClient.DetachInstancesAsync(detachRequest).Result;
                    if (detachResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        returnValue = true;
                    }
                }
                catch (Exception)
                {
                    //Yes AWS throws Exceptions and System.AggregrateExceptions
                    //so for now this is the right way to handle it
                    returnValue = false;
                }
            }
            return(returnValue);
        }
Beispiel #2
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, DetachInstancesResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Activities/member", targetDepth))
                    {
                        var unmarshaller = ActivityUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Activities.Add(item);
                        continue;
                    }
                }
            }

            return;
        }
Beispiel #3
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DetachInstancesResponse response = new DetachInstancesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("DetachInstancesResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
        public static DetachInstancesResponse Unmarshall(UnmarshallerContext context)
        {
            DetachInstancesResponse detachInstancesResponse = new DetachInstancesResponse();

            detachInstancesResponse.HttpResponse      = context.HttpResponse;
            detachInstancesResponse.ScalingActivityId = context.StringValue("DetachInstances.ScalingActivityId");
            detachInstancesResponse.RequestId         = context.StringValue("DetachInstances.RequestId");

            return(detachInstancesResponse);
        }