public IEnumerable <Ec2Instance> Start() { var bootstrapId = _options.InstanceRequest.ClientToken; IEnumerable <Instance> instances = _instanceHandler.GetInstances(bootstrapId); List <Tuple <string, string> > existingPasswords = null; if (!_settings.Config.DeploymentUser.IsDefined()) { existingPasswords = _passwordHandler.WaitForPassword(instances.Select(x => x.InstanceId), _options.PrivateKeyFileLocation); } List <Ec2Instance> ec2instances = new List <Ec2Instance>(); foreach (var instance in instances) { ec2instances.Add(new Ec2Instance { InstanceId = instance.InstanceId, UserName = _settings.Config.DeploymentUser.IsDefined() ? _settings.Config.DeploymentUser.UserName : "******", Password = _settings.Config.DeploymentUser.IsDefined() ? _settings.Config.DeploymentUser.Password : existingPasswords.Single(x => x.Item1 == instance.InstanceId).Item2, AwsInstance = instance, ManagementAddress = _instanceHandler.GetManagementAddress(instance) }); } _instanceHandler.Start(bootstrapId); return(ec2instances); }
public IEnumerable <Instance> Stop() { var bootstrapId = _options.InstanceRequest.ClientToken; IEnumerable <Instance> instances = _instanceHandler.GetInstances(bootstrapId); _instanceHandler.Stop(bootstrapId); return(instances); }
private Ec2BootstrapConfig BootstrapNew(Ec2BootstrapConfig config) { var amiLocator = new Ec2AmiLocator(_client); var imageValues = _options.Image; if (imageValues.HasImageId()) { _options.InstanceRequest.ImageId = imageValues.Id; } else if (imageValues.HasLatestImageDefined()) { switch (imageValues.LatestImage) { case AwsWindowsImage.Win2008: _options.InstanceRequest.ImageId = amiLocator.Find2008Core(); break; case AwsWindowsImage.Win2008R2: _options.InstanceRequest.ImageId = amiLocator.Find2008R2Core(); break; case AwsWindowsImage.Win2012: _options.InstanceRequest.ImageId = amiLocator.Find2012Core(); break; case AwsWindowsImage.Win2012R2: _options.InstanceRequest.ImageId = amiLocator.Find2012R2Core(); break; case AwsWindowsImage.Win2016: _options.InstanceRequest.ImageId = amiLocator.Find2016Core(); break; default: throw new Exception("Image " + imageValues.LatestImage + " currently not supported. Please specify image id as a string instead."); } } else if (imageValues.HasImageFilter()) { _options.InstanceRequest.ImageId = amiLocator.FindWithFilters(imageValues.Filters, imageValues.FilterByOwner); } else { _options.InstanceRequest.ImageId = amiLocator.Find2012R2Core(); } Logger.Info("Creating instances..."); var instanceIds = _instanceHandler.CreateInstances(_options).ToList(); Thread.Sleep(10000); //Logger.Info("Tagging instances. //var instanceTag = _tagHandler.CreateNameTags(config.BootstrapId, instanceIds); Logger.WithLogSection("Waiting for instances to be ready", () => _instanceHandler.WaitForInstancesStatus(instanceIds, Ec2InstanceState.Running)); List <Tuple <string, string> > passwords = null; if (!_conDepSettings.Config.DeploymentUser.IsDefined()) { Logger.WithLogSection("Waiting for Windows password to be available", () => { passwords = _passwordHandler.WaitForPassword(instanceIds, _options.PrivateKeyFileLocation); }); } _instanceHandler.TagInstances(instanceIds, _options.Tags); var instances = _instanceHandler.GetInstances(instanceIds).ToList(); foreach (var instance in instances) { config.Instances.Add(new Ec2Instance { InstanceId = instance.InstanceId, UserName = _conDepSettings.Config.DeploymentUser.IsDefined() ? _conDepSettings.Config.DeploymentUser.UserName : @".\Administrator", Password = _conDepSettings.Config.DeploymentUser.IsDefined() ? _conDepSettings.Config.DeploymentUser.Password : passwords.Single(x => x.Item1 == instance.InstanceId).Item2, ManagementAddress = GetManagementAddress(instance) }); } HaveAccessToServers(config); //StopServers(config); //if (takeSnapshots) //{ // Logger.Info("Taking snapshots of disks to enable resets..."); // _snapshotHandler.TakeSnapshots(instances, config); //} //else //{ // Logger.Warn("Snapshots disabled. Note that reset will not work without snapshots."); //} //StartServers(config); //Logger.Info("Storing configuration..."); //var configHandler = new BootstrapConfigHandler(config.BootstrapId); //configHandler.Write(config); //return config.BootstrapId; return(config); }