示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#5
0
        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");
        }
示例#6
0
        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);
        }
示例#7
0
        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.");
            }
        }
示例#8
0
        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);
        }
示例#9
0
 public AwsBootstrapOperation(AwsBootstrapOptionsValues options)
 {
     _options = options;
 }
示例#10
0
        public IEnumerable <string> CreateInstances(AwsBootstrapOptionsValues request)
        {
            RunInstancesResponse runResponse = _client.RunInstances(request.InstanceRequest);

            return(runResponse.Reservation.Instances.Select(x => x.InstanceId));
        }