public NewAzureQuickVMCmdletInfo(OS os, string name, string serviceName, string imageName, string userName, string password, string locationName, InstanceSize? instanceSize)
     : this(os, name, serviceName, imageName, userName, password, locationName)
 {
     if (instanceSize.HasValue)
     {
         cmdletParams.Add(new CmdletParam("InstanceSize", instanceSize.ToString()));
     }               
 }
        public static PersistentVM CreateIaaSVMObject(string vmName, InstanceSize size, string imageName, bool isWindows = true, string username = null, string password = null, bool disableGuestAgent = false)
        {
            //Create an IaaS VM
            var azureVMConfigInfo = new AzureVMConfigInfo(vmName, size.ToString(), imageName);
            AzureProvisioningConfigInfo azureProvisioningConfig = null;

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(username))
            {
                azureProvisioningConfig = new AzureProvisioningConfigInfo(isWindows ? OS.Windows:OS.Linux, username, password, disableGuestAgent);
            }
            var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);

            return(vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo));
        }
        private string Deployment2GceArgs(string tag                   = "",
                                          string MachineType           = "n1-standard-16",
                                          string Zone                  = "us-central1-a",
                                          string Region                = "NA",
                                          int InstanceSize             = 1,
                                          int InstanceSizeMin          = 1,
                                          int InstanceSizeMax          = 6,
                                          string AutoscalerId          = "default",
                                          string ExtraCliArgs          = "",
                                          string AppNameStringOverride = "",
                                          string HubServerName         = "")
        {
            int LocalCpuBudget = CpuBudget;

            UnrealTournamentBuild.UnrealTournamentAppName LocalAppName = AppName;
            if (!String.IsNullOrEmpty(AppNameStringOverride))
            {
                if (!Enum.IsDefined(typeof(UnrealTournamentBuild.UnrealTournamentAppName), AppNameStringOverride))
                {
                    throw new AutomationException("Trying to override AppName to non-existant type: " + AppNameStringOverride);
                }
                LocalAppName = (UnrealTournamentBuild.UnrealTournamentAppName)Enum.Parse(typeof(UnrealTournamentBuild.UnrealTournamentAppName), AppNameStringOverride);
                CommandUtils.Log("Overriding AppName from {0} to {1}", AppName, LocalAppName);
            }

            string NetworkId       = "default";
            string CredentialsFile = "GceUtDevCredentials.txt";

            /* This is very confusing. UnrealTournament's live lable is UnrealTournamentDev. */
            if (LocalAppName == UnrealTournamentBuild.UnrealTournamentAppName.UnrealTournamentDev)
            {
                NetworkId       = "unreal-tournament";
                CredentialsFile = "GceUtLiveCredentials.txt";
            }

            if (InstanceSize == 0)
            {
                InstanceSizeMin = 0;
                InstanceSizeMax = 0;
            }
            else if (InstanceSizeMin > InstanceSize)
            {
                InstanceSize = InstanceSizeMin;
            }

            string         CredentialsFilePath           = GetUtilitiesFilePath(CredentialsFile);
            string         CredentialsFileContentsBase64 = ReadFileContents(CredentialsFilePath);
            string         CredentialsFileContents       = ConvertFromBase64(CredentialsFileContentsBase64);
            GceCredentials gceCredentials = GceCredentialsFromJson(CredentialsFileContents);

            string HTTPCredentialsFilePath = GetUtilitiesFilePath("DeployerAuthBase64.txt");

            if (File.Exists(HTTPCredentialsFilePath))
            {
                string HTTPCredentialsFileContentsBase64 = ReadFileContents(HTTPCredentialsFilePath);
                HTTPAuthBase64 = HTTPCredentialsFileContentsBase64;
            }

            Byte[] CliArgBytes;
            if (HubServerName != "")
            {
                CliArgBytes    = System.Text.Encoding.UTF8.GetBytes("UnrealTournament ut-entry?game=lobby?ServerName=\"" + HubServerName + "\" -nocore -epicapp=" + LocalAppName.ToString() + " " + ExtraCliArgs);
                LocalCpuBudget = 32000;
            }
            else
            {
                CliArgBytes = System.Text.Encoding.UTF8.GetBytes("UnrealTournament ut-entry?game=empty?region=" + Region + " -epicapp=" + LocalAppName.ToString() + " " + ExtraCliArgs);
            }
            Byte[] BuildStringBytes = System.Text.Encoding.UTF8.GetBytes(BuildString);
            string CloudArgs        = "epic_game_name=" + GameNameShort + "&" +
                                      "epic_game_binary=" + this.GameBinary + "&" +
                                      "epic_game_binary_path=" + this.GameBinaryPath + "&" +
                                      "epic_game_log_path=" + this.GameLogPath + "&" +
                                      "epic_game_saved_path=" + this.GameSavedPath + "&" +
                                      "epic_game_max_match_length=" + this.MaxMatchLength.ToString() + "&" +
                                      "epic_game_ttl_interval=" + this.TtlInterval.ToString() + "&" +
                                      "epic_install_sumo=" + this.InstallSumo + "&" +
                                      "epic_game_tag=" + GetTag(LocalAppName, Region, tag) + "&" +
                                      "epic_game_version=" + Changelist.ToString() + "&" +
                                      "epic_game_region=" + Region + "&" +
                                      "epic_game_cpu_budget=" + LocalCpuBudget + "&" +
                                      "epic_game_ram_budget=" + RamBudget + "&" +
                                      "epic_game_buildstr_base64=" + System.Convert.ToBase64String(BuildStringBytes) + "&" +
                                      "epic_game_environment=" + LocalAppName.ToString() + "&" +
                                      "epic_instance_size=" + InstanceSize.ToString() + "&" +
                                      "epic_instance_min=" + InstanceSizeMin.ToString() + "&" +
                                      "epic_instance_max=" + InstanceSizeMax.ToString() + "&" +
                                      "epic_autoscaler_id=" + AutoscalerId + "&" +
                                      "epic_gce_project_id=" + gceCredentials.project_id + "&" +
                                      "epic_gce_base64_credentials=" + CredentialsFileContentsBase64 + "&" +
                                      "epic_gce_machine_type=" + MachineType + "&" +
                                      "epic_gce_network=" + NetworkId + "&" +
                                      "epic_gce_zone=" + Zone + "&" +
                                      "epic_game_base64_cli_args=" + System.Convert.ToBase64String(CliArgBytes);

            return(CloudArgs);
        }
        public NewAzureQuickVMCmdletInfo(OS os, string name, string serviceName, string imageName, InstanceSize? instanceSize, string userName, string password, string vNetName, string[] subnetNames, string affinityGroup)
            : this(os, name, serviceName, imageName, userName, password)
        {
            if (!string.IsNullOrEmpty(affinityGroup))
            {
                cmdletParams.Add(new CmdletParam("AffinityGroup", affinityGroup));
            }
            if (instanceSize.HasValue)
            {
                cmdletParams.Add(new CmdletParam("InstanceSize", instanceSize.ToString()));
            }
            if (!string.IsNullOrEmpty(vNetName))
            {
                cmdletParams.Add(new CmdletParam("VNetName", vNetName));
            }
            if (subnetNames != null)
            {
                cmdletParams.Add(new CmdletParam("SubnetNames", subnetNames));
            }                      

        }
        private string Deployment2AwsArgs(string tag           = "",
                                          string InstanceType  = "c4.4xlarge",
                                          string AwsRegion     = "us-east-1",                           /* AU ap-southeast-2. KR ap-northeast-2 */
                                          string Region        = "NA",                                  /* KR South Korea. AU Australia */
                                          int InstanceSize     = 1,
                                          int InstanceSizeMin  = 1,
                                          int InstanceSizeMax  = 6,
                                          string AutoscalerId  = "default",
                                          string ExtraCliArgs  = "",
                                          string HubServerName = "")
        {
            string AwsCredentialsFile = "AwsDedicatedServerCredentialsDecoded.txt";

            int LocalCpuBudget = CpuBudget;

            if (InstanceSize == 0)
            {
                InstanceSizeMin = 0;
                InstanceSizeMax = 0;
            }
            else if (InstanceSizeMin > InstanceSize)
            {
                InstanceSize = InstanceSizeMin;
            }

            string CredentialsFilePath = GetUtilitiesFilePath(AwsCredentialsFile);
            string AwsCredentials      = ReadFileContents(CredentialsFilePath);

            string[] AwsCredentialsList = AwsCredentials.Split(':');

            if (AwsCredentialsList.Length != 2)
            {
                throw new AutomationException("Unable to parse credentials from file {0} {1}",
                                              AwsCredentialsFile, AwsCredentials);
            }

            string AwsAccessKey = AwsCredentialsList[0];

            Byte[] AwsAccessSecretKeyBytes = System.Text.Encoding.UTF8.GetBytes(AwsCredentialsList[1]);

            Byte[] CliArgBytes;
            if (HubServerName != "")
            {
                CliArgBytes    = System.Text.Encoding.UTF8.GetBytes("UnrealTournament ut-entry?game=lobby?ServerName=\"" + HubServerName + "\" -nocore -epicapp=" + AppName.ToString() + " " + ExtraCliArgs);
                LocalCpuBudget = 32000;
            }
            else
            {
                CliArgBytes = System.Text.Encoding.UTF8.GetBytes("UnrealTournament ut-entry?game=empty?region=" + Region + " -epicapp=" + AppName.ToString() + " " + ExtraCliArgs);
            }
            Byte[] BuildStringBytes = System.Text.Encoding.UTF8.GetBytes(BuildString);

            string CloudArgs = "epic_game_name=" + GameNameShort + "&" +
                               "epic_game_binary=" + this.GameBinary + "&" +
                               "epic_game_binary_path=" + this.GameBinaryPath + "&" +
                               "epic_game_log_path=" + this.GameLogPath + "&" +
                               "epic_game_saved_path=" + this.GameSavedPath + "&" +
                               "epic_game_max_match_length=" + this.MaxMatchLength.ToString() + "&" +
                               "epic_game_ttl_interval=" + this.TtlInterval.ToString() + "&" +
                               "epic_install_sumo=" + this.InstallSumo + "&" +
                               "epic_game_tag=" + GetTag(AppName, Region, tag) + "&" +
                               "epic_game_version=" + Changelist.ToString() + "&" +
                               "epic_game_buildstr_base64=" + System.Convert.ToBase64String(BuildStringBytes) + "&" +
                               "epic_game_cpu_budget=" + LocalCpuBudget + "&" +
                               "epic_game_ram_budget=" + RamBudget + "&" +
                               "epic_game_environment=" + AppName.ToString() + "&" +
                               "epic_instance_size=" + InstanceSize.ToString() + "&" +
                               "epic_instance_min=" + InstanceSizeMin.ToString() + "&" +
                               "epic_instance_max=" + InstanceSizeMax.ToString() + "&" +
                               "epic_autoscaler_id=" + AutoscalerId + "&" +
                               "epic_aws_access_key=" + AwsAccessKey + "&" +
                               "epic_aws_base64_secret_key=" + System.Convert.ToBase64String(AwsAccessSecretKeyBytes) + "&" +
                               "epic_aws_instance_type=" + InstanceType + "&" +
                               "epic_aws_region=" + AwsRegion + "&" +
                               "epic_game_base64_cli_args=" + System.Convert.ToBase64String(CliArgBytes);

            return(CloudArgs);
        }