public static Ec2Response StartServer(DeveloperOptions developerOptions) { try { var ec2Config = new AmazonEC2Config { AuthenticationRegion = developerOptions.RegionEndpont }; var ec2Client = new AmazonEC2Client( new BasicAWSCredentials(developerOptions.AccessKey, developerOptions.SecretAccessKey), ec2Config); var launchRequest = new RunInstancesRequest { ImageId = developerOptions.AmiId, InstanceType = developerOptions.InstanceType, MinCount = 1, MaxCount = 1, KeyName = developerOptions.Ec2KeyPair, SecurityGroupIds = new List<string> { developerOptions.SecurityGroupId } }; var launchResponse = ec2Client.RunInstances(launchRequest); if (launchResponse.HttpStatusCode.Equals(HttpStatusCode.OK)) { while (true) { var instances = ec2Client.DescribeInstances(); } } } catch (Exception) { throw; } // TODO return null; }
public static DeveloperOptions Parse(string devOptions) { var options = new DeveloperOptions(); if (string.IsNullOrWhiteSpace(devOptions)) { return(options); } var optionPairs = devOptions.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (var optionPair in optionPairs) { var optionPairParts = optionPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optionPairParts.Length == 2) { MapToOption(options, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim()); } else { throw new ArgumentException( string.Format( "Unable to parse developer options which should be in the form of 'option=value&nextOption=nextValue'. The option '{0}' was not properly constructed", optionPair)); } } return(options); }
private static void MapToOption(DeveloperOptions existingOptions, string key, string value) { if (key.Equals("amiid")) { existingOptions.AmiId = value; return; } if (key.Equals("instancetype")) { existingOptions.InstanceType = value; return; } // else option is not found, throw exception throw new ArgumentException( string.Format("The developer option '{0}' was not expected and is not understood.", key)); }
public static Ec2Response StartServer(DeveloperOptions developerOptions) { try { var ec2Config = new AmazonEC2Config { AuthenticationRegion = developerOptions.RegionEndpont }; var ec2Client = new AmazonEC2Client( new BasicAWSCredentials(developerOptions.AccessKey, developerOptions.SecretAccessKey), ec2Config); var launchRequest = new RunInstancesRequest { ImageId = developerOptions.AmiId, InstanceType = developerOptions.InstanceType, MinCount = 1, MaxCount = 1, KeyName = developerOptions.Ec2KeyPair, SecurityGroupIds = new List <string> { developerOptions.SecurityGroupId } }; var launchResponse = ec2Client.RunInstances(launchRequest); if (launchResponse.HttpStatusCode.Equals(HttpStatusCode.OK)) { while (true) { var instances = ec2Client.DescribeInstances(); } } } catch (Exception) { throw; } // TODO return(null); }
public static DeveloperOptions Parse(string devOptions) { var options = new DeveloperOptions(); if (string.IsNullOrWhiteSpace(devOptions)) return options; var optionPairs = devOptions.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (var optionPair in optionPairs) { var optionPairParts = optionPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optionPairParts.Length == 2) { MapToOption(options, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim()); } else { throw new ArgumentException( string.Format( "Unable to parse developer options which should be in the form of 'option=value&nextOption=nextValue'. The option '{0}' was not properly constructed", optionPair)); } } return options; }