private Ec2BootstrapConfig GetConfigFromExisting(AwsBootstrapOptionsValues options, Ec2BootstrapConfig config) { Logger.Info("Allready bootstrapped. Getting server information."); var existingInstances = options.IdempotencyType == AwsEc2IdempotencyType.ClientToken ? _instanceHandler.GetInstances(_options.InstanceRequest.ClientToken).ToList() : _instanceHandler.GetInstances(_options.IdempotencyTags).ToList(); List <Tuple <string, string> > existingPasswords = null; if (!_conDepSettings.Config.DeploymentUser.IsDefined()) { existingPasswords = _passwordHandler.WaitForPassword(existingInstances.Select(x => x.InstanceId), _options.PrivateKeyFileLocation); } foreach (var instance in existingInstances.Where(x => x.State.Name == "Running")) { config.Instances.Add(new Ec2Instance { InstanceId = instance.InstanceId, UserName = _conDepSettings.Config.DeploymentUser.IsDefined() ? _conDepSettings.Config.DeploymentUser.UserName : "******", Password = _conDepSettings.Config.DeploymentUser.IsDefined() ? _conDepSettings.Config.DeploymentUser.Password : existingPasswords.Single(x => x.Item1 == instance.InstanceId).Item2, AwsInstance = instance, ManagementAddress = GetManagementAddress(instance) }); } return(config); }
public Ec2Bootstrapper(AwsBootstrapOptionsValues options, ConDepSettings conDepSettings) { _options = options; _conDepSettings = conDepSettings; _client = new AmazonEC2Client(_options.Credentials, _options.RegionEndpoint); _instanceHandler = new Ec2InstanceHandler(_client); _passwordHandler = new Ec2InstancePasswordHandler(_client); }
private bool PrimaryNetworkInterfaceDefined(AwsBootstrapOptionsValues options) { if (options.NetworkInterfaceValues == null || options.NetworkInterfaceValues.NetworkInterfaces.Count == 0) { return(false); } return(!string.IsNullOrWhiteSpace(options.NetworkInterfaceValues.NetworkInterfaces[0].SubnetId)); }
/// <summary> /// Bootstrap one or more Amazon AWS Virtual Private Cloud (VPC) instances and adds /// them to ConDep's servers collection. This method assume mandatory settings are /// found in ConDep's environment file. If you prefer to specify settings directly, use /// the other overload and specify settings in code. /// </summary> /// <param name="ec2"></param> /// <param name="bootstrapId">Unique, case-sensitive identifier you provide to ensure the idempotency of the bootstrap operation. /// In AWS this is refered to as the Client Token.</param> /// <returns></returns> public static Result CreateInstances(this IOfferAwsEc2Operations ec2, string bootstrapId) { var ec2Builder = ec2 as AwsEc2OperationsBuilder; var options = new AwsBootstrapOptionsValues(bootstrapId); var awsBootstrapOperation = new AwsBootstrapOperation(options); OperationExecutor.Execute((LocalBuilder)ec2, awsBootstrapOperation); return(ec2Builder.Result); }
public bool AllreadyBootstrapped(AwsBootstrapOptionsValues options) { if (options.IdempotencyType == AwsEc2IdempotencyType.ClientToken) { return(GetInstances(options.InstanceRequest.ClientToken).Any()); } if (options.IdempotencyType == AwsEc2IdempotencyType.Tags) { return(GetInstances(options.IdempotencyTags).Any()); } throw new ArgumentException("options.IdempotencyType"); }
public AwsBootstrapOptionsBuilder(string bootstrapId) { _values = new AwsBootstrapOptionsValues(bootstrapId); _values.InstanceRequest.ClientToken = bootstrapId; _image = new AwsBootstrapImageOptionsBuilder(_values.Image, this); _userData = new AwsBootstrapUserDataOptionsBuilder(_values.InstanceRequest, this); _values.NetworkInterfaceValues = new AwsBootstrapNetworkInterfaceOptionsValues(_values.InstanceRequest.NetworkInterfaces); _networkInterfaces = new AwsBootstrapNetworkInterfacesOptionsBuilder(_values.NetworkInterfaceValues, this); _disks = new AwsBootstrapDisksOptionsBuilder(_values.InstanceRequest.BlockDeviceMappings, this); _tags = new AwsBootstrapTagOptionsBuilder(_values.Tags); }
private void ValidateMandatoryOptions(AwsBootstrapOptionsValues options, ConDepSettings conDepSettings) { if (string.IsNullOrWhiteSpace(options.InstanceRequest.SubnetId) && !PrimaryNetworkInterfaceDefined(options)) { throw new OperationConfigException(string.Format("Missing value for SubnetId. Please specify in code (using SubnetId or specify in NetworkInterface) or in config.")); } if (string.IsNullOrWhiteSpace(options.InstanceRequest.KeyName)) { throw new OperationConfigException(string.Format("Missing value for PublicKeyName. Please specify in code or in config.")); } if (!conDepSettings.Config.DeploymentUser.IsDefined()) { if (string.IsNullOrWhiteSpace(options.PrivateKeyFileLocation)) { throw new OperationConfigException(string.Format("Missing value for PrivateKeyFileLocation. Please specify in code or in config.")); } } if (options.RegionEndpoint == null) { throw new OperationConfigException(string.Format("Missing value for Region. Please specify in code or in config.")); } if (options.Credentials == null) { throw new OperationConfigException(string.Format("Missing value for Credentials. Please specify in code or in config.")); } if (options.InstanceRequest.Placement == null) { throw new OperationConfigException(string.Format("Missing value for AvailabilityZone. Please specify in code or in config.")); } if (options.InstanceRequest.SecurityGroupIds.Count == 0) { Logger.Warn("No value for SecurityGroupIds given. Default Security Group will be used."); } if (string.IsNullOrWhiteSpace(options.InstanceRequest.SubnetId)) { Logger.Warn("No value for SubnetId given. Default Subnet will be used."); } if (!options.Image.HasImageFilter() && !options.Image.HasImageId() && !options.Image.HasLatestImageDefined()) { Logger.Warn("No value for Image given. Latest defined Windows Image will be used."); } if (string.IsNullOrWhiteSpace(options.InstanceRequest.InstanceType)) { Logger.Warn("No value for InstanceType given. Default Instance Type will be used."); } }
public AwsBootstrapOptionsBuilder(Action <IOfferAwsTagOptions> tags) { _values = new AwsBootstrapOptionsValues(); var idempotenseTagBuilder = new AwsBootstrapTagOptionsBuilder(_values.IdempotencyTags); var tagBuilder = new AwsBootstrapTagOptionsBuilder(_values.Tags); tags(idempotenseTagBuilder); tags(tagBuilder); _image = new AwsBootstrapImageOptionsBuilder(_values.Image, this); _userData = new AwsBootstrapUserDataOptionsBuilder(_values.InstanceRequest, this); _values.NetworkInterfaceValues = new AwsBootstrapNetworkInterfaceOptionsValues(_values.InstanceRequest.NetworkInterfaces); _networkInterfaces = new AwsBootstrapNetworkInterfacesOptionsBuilder(_values.NetworkInterfaceValues, this); _disks = new AwsBootstrapDisksOptionsBuilder(_values.InstanceRequest.BlockDeviceMappings, this); }
public AwsBootstrapOperation(AwsBootstrapOptionsValues options) { _options = options; }
public IEnumerable <string> CreateInstances(AwsBootstrapOptionsValues request) { RunInstancesResponse runResponse = _client.RunInstances(request.InstanceRequest); return(runResponse.Reservation.Instances.Select(x => x.InstanceId)); }