public void StartInstance(ref bool actionSucceeded, ref string actionMessage) { if (InstanceRequestObj.InstanceState.ToLower() != "stopped") { actionSucceeded = false; actionMessage = $"The instance {InstanceRequestObj.InstanceName} is currently in {InstanceRequestObj.InstanceState} state , and cannot be started at this time."; return; } var request = new StartInstancesRequest { InstanceIds = new List <string>() { InstanceRequestObj.InstanceID } }; try { StartInstancesResponse response = Ec2Client.StartInstancesAsync(request).GetAwaiter().GetResult(); foreach (InstanceStateChange item in response.StartingInstances) { Console.WriteLine("Started instance: " + item.InstanceId); Console.WriteLine("Instance state: " + item.CurrentState.Name); } actionSucceeded = true; actionMessage = $"The instance {InstanceRequestObj.InstanceName} is being started. Please check the AWS Console to verify."; } catch (Exception ex) { context.Logger.LogLine($"ServerOperationsHelper::StopInstance {ex.Message}"); context.Logger.LogLine($"ServerOperationsHelper::StopInstance {ex.StackTrace}"); actionSucceeded = false; actionMessage = $"Could not start {InstanceRequestObj.InstanceName} . Please contact your administrator."; } }
public async Task StartAsync(HostInfo host, TimeSpan cooldown) { #region Preconditions Validate.NotNull(host, nameof(host)); if (host.IsTerminated) { throw new ArgumentException("Must not be terminated", nameof(host)); } #endregion await ec2.StartInstancesAsync(new StartInstancesRequest(host.ResourceId)); await TransitionStateAsync(host, HostStatus.Pending); // back to pending... // the host will register with the cluster again on boot }