Exemplo n.º 1
0
        /// <inheritdoc cref="IServerManager" />
        public async Task <List <LaunchedCapacity> > LaunchServersAsync(ServerType type, ServerSize size, int quantity)
        {
            var random  = new Random();
            var config  = (await this.configRetriever.RetrieveConfigAsync()).ServerOptions;
            var az      = config.AvailabilityZones[random.Next(0, config.AvailabilityZones.Count)];
            var request = new RunInstancesRequest()
            {
                MinCount  = 1,
                MaxCount  = 1,
                Placement = new Placement()
                {
                    AvailabilityZone = az.Az,
                },
                SubnetId           = az.SubnetId,
                ImageId            = config.Ami,
                Monitoring         = true,
                IamInstanceProfile = new IamInstanceProfileSpecification()
                {
                    Arn = config.InstanceProfile,
                },
                InstanceType        = InstanceTypeFromServerTypeAndSize(type, size),
                SecurityGroupIds    = new List <string>(new[] { "sg-05aad9a19aa99f7fd", }),
                BlockDeviceMappings = new List <BlockDeviceMapping>()
                {
                    new BlockDeviceMapping()
                    {
                        DeviceName = "/dev/sdf",
                        Ebs        = new EbsBlockDevice()
                        {
                            SnapshotId = config.TablebaseSnapshotId,
                            VolumeType = VolumeType.Gp2,
                        },
                    },
                },
                TagSpecifications = new List <TagSpecification>()
                {
                    new TagSpecification()
                    {
                        ResourceType = ResourceType.Instance,
                        Tags         = new List <Tag>()
                        {
                            new Tag()
                            {
                                Key   = "LaunchedBy",
                                Value = "Janus",
                            },
                        },
                    },
                },
            };
            var response = await this.ec2.RunInstancesAsync(request);

            return(response.Reservation.Instances.Select(i => new LaunchedCapacity()
            {
                InstanceId = i.InstanceId,
                AvailabilityZone = az.Az,
                LaunchTime = i.LaunchTime,
                InstanceType = i.InstanceType.Value,
            }).ToList());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Determines the EC2 instance type to launch based on the requested server type and size.
 /// </summary>
 /// <param name="type">The server type.</param>
 /// <param name="size">The server size.</param>
 /// <returns>The EC2 instance type.</returns>
 public static InstanceType InstanceTypeFromServerTypeAndSize(ServerType type, ServerSize size)
 {
     if (type == ServerType.CPU)
     {
         // TODO: Compare c5-series with:
         //       * c6g (ARM)
         //       * z1d (nice clock speed = 4Ghz)
         //       * m5zn (turbo clock speed up to 4.5Ghz)
         //       *
         return(InstanceType.M5znLarge);
     }
     else
     {
         return(InstanceType.P38xlarge);
     }
 }