예제 #1
0
 public void CircularDependency()
 {
     var templateFile   = Path.Combine(_resourceFolder, "CircularDependency.json");
     var parametersFile = Path.Combine(_resourceFolder, "StandardTemplateParams.json");
     var taskBuilder    = new TaskBuilder();
     var taskExecutor   = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
 }
예제 #2
0
        public async Task ParseAndExecuteDeploymentTasks_Success()
        {
            var client = new FakeHttpClient();

            client.AddResponse("/network/networkDomain/d5791a6d-2b69-47e2-be06-f26a2ec4bff8", "NetworkDomain_Get.json");
            client.AddResponse("/network/vlan?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&name=Unit Test VLAN", "GenericNotFound.json");
            client.AddResponse("/network/deployVlan", "Vlan_Delpoy.json");
            client.AddResponse("/network/vlan/997e2084-00b1-4d1d-96ce-099946679c6f", "Vlan_Get.json");
            client.AddResponse("/imageWithDiskSpeed?name=RedHat 6 64-bit 2 CPU", "Image_Get.xml");
            client.AddResponse("/server/server?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&name=Unit Test Server", "GenericNotFound.json");
            client.AddResponse("/server/deployServer", "Server_Deploy.json");
            client.AddResponse("/server/server/b42b40e1-351a-4df9-b726-2ccff01f2767", "Server_Get.json");
            client.AddResponse("/network/addPublicIpBlock", "PublicIpBlock_Add.json");
            client.AddResponse("/network/publicIpBlock/996b066e-bdce-11e4-8c14-b8ca3a5d9ef8", "PublicIpBlock_Get.json");
            client.AddResponse("/network/natRule?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&internalIp=10.0.0.8", "GenericNotFound.json");
            client.AddResponse("/network/createNatRule", "NatRule_Create.json");
            client.AddResponse("/network/natRule/a6b2e743-e330-4deb-a76e-0d9cb0b1d1bb", "NatRule_Get.json");

            var templateFile   = Path.Combine(_resourceFolder, "StandardTemplate.json");
            var parametersFile = Path.Combine(_resourceFolder, "StandardTemplateParams.json");
            var taskBuilder    = new TaskBuilder();
            var taskExecutor   = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
            var log            = await taskExecutor.Execute(_runtimeContext);

            Assert.AreEqual(DeploymentLogStatus.Success, log.Status);
            Assert.AreEqual("http://168.128.5.106/index.html", taskExecutor.Context.OutputParameters["ServerPublicUrl"]);
        }
        public async Task ParseAndExecuteDeploymentTasks_Success()
        {
            var client = new FakeHttpClient();
            client.AddResponse("/network/networkDomain/d5791a6d-2b69-47e2-be06-f26a2ec4bff8", "NetworkDomain_Get.json");
            client.AddResponse("/network/vlan?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&name=Unit Test VLAN", "GenericNotFound.json");
            client.AddResponse("/network/deployVlan", "Vlan_Delpoy.json");
            client.AddResponse("/network/vlan/997e2084-00b1-4d1d-96ce-099946679c6f", "Vlan_Get.json");
            client.AddResponse("/imageWithDiskSpeed?name=RedHat 6 64-bit 2 CPU", "Image_Get.xml");
            client.AddResponse("/server/server?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&name=Unit Test Server", "GenericNotFound.json");
            client.AddResponse("/server/deployServer", "Server_Deploy.json");
            client.AddResponse("/server/server/b42b40e1-351a-4df9-b726-2ccff01f2767", "Server_Get.json");
            client.AddResponse("/network/addPublicIpBlock", "PublicIpBlock_Add.json");
            client.AddResponse("/network/publicIpBlock/996b066e-bdce-11e4-8c14-b8ca3a5d9ef8", "PublicIpBlock_Get.json");
            client.AddResponse("/network/natRule?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&internalIp=10.0.0.8", "GenericNotFound.json");
            client.AddResponse("/network/createNatRule", "NatRule_Create.json");
            client.AddResponse("/network/natRule/a6b2e743-e330-4deb-a76e-0d9cb0b1d1bb", "NatRule_Get.json");

            var templateFile = Path.Combine(_resourceFolder, "StandardTemplate.json");
            var parametersFile = Path.Combine(_resourceFolder, "StandardTemplateParams.json");
            var taskBuilder = new TaskBuilder();
            var taskExecutor = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
            var log = await taskExecutor.Execute(_runtimeContext);

            Assert.AreEqual(DeploymentLogStatus.Success, log.Status);
            Assert.AreEqual("http://168.128.5.106/index.html", taskExecutor.Context.OutputParameters["ServerPublicUrl"]);
        }
예제 #4
0
        /// <summary>
        /// Begins the processing asynchronously.
        /// </summary>
        /// <returns>The async <see cref="Task"/>.</returns>
        private async Task BeginProcessingAsync()
        {
            var runtimeContext = new RuntimeContext
            {
                AccountDetails = await CaasAuthentication.Authenticate(UserName, Password, Region),
                LogProvider    = new ConsoleLogProvider()
            };

            var taskBuilder  = new TaskBuilder();
            var taskExecutor = taskBuilder.BuildTasksFromDeploymentTemplate(ResolvePath(Template), ResolvePath(Parameters));
            var log          = await taskExecutor.Execute(runtimeContext);

            Console.WriteLine($"Result: {log.Status}");
            WriteLog(log, ResolvePath(DeploymentLog));
            Console.WriteLine($"Complete! Deployment log written to {DeploymentLog}.");

            if (taskExecutor.Context.OutputParameters != null)
            {
                Console.WriteLine("OUTPUT PARAMETERS:");

                foreach (var param in taskExecutor.Context.OutputParameters)
                {
                    Console.WriteLine($"{param.Key}: {param.Value}");
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Performs the request.
        /// </summary>
        /// <param name="arguments">The arguments.</param>
        /// <returns>The async <see cref="Task"/>.</returns>
        private static async Task PerformRequest(Dictionary <string, string> arguments)
        {
            try
            {
                var accountDetails = await CaasAuthentication.Authenticate(
                    arguments["username"],
                    arguments["password"],
                    arguments["region"]);

                var runtimeContext = new RuntimeContext
                {
                    AccountDetails = accountDetails,
                    LogProvider    = new ConsoleLogProvider()
                };

                var taskBuilder = new TaskBuilder();

                if (arguments["action"].ToLower() == "deploy")
                {
                    var parametersFile = arguments.ContainsKey("parameters") ? arguments["parameters"] : null;
                    var templateFile   = arguments["template"];

                    var taskExecutor = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
                    var log          = await taskExecutor.Execute(runtimeContext);

                    Console.WriteLine($"Result: {log.Status}");

                    log.SaveToFile(arguments["deploymentlog"]);
                    Console.WriteLine($"Complete! Deployment log written to {arguments["deploymentlog"]}.");

                    if (taskExecutor.Context.OutputParameters != null)
                    {
                        Console.WriteLine("OUTPUT PARAMETERS:");

                        foreach (var param in taskExecutor.Context.OutputParameters)
                        {
                            Console.WriteLine($"{param.Key}: {param.Value}");
                        }
                    }
                }
                else if (arguments["action"].ToLower() == "delete")
                {
                    var deploymentLogFile = arguments["deploymentlog"];

                    var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(deploymentLogFile);
                    var log          = await taskExecutor.Execute(runtimeContext);

                    Console.WriteLine($"Result: {log.Status}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public async Task ParseAndExecuteDeploymentTasks_Failed()
        {
            var client = new FakeHttpClient();
            client.AddResponse("/network/networkDomain/d5791a6d-2b69-47e2-be06-f26a2ec4bff8", "NetworkDomain_Get.json");
            client.AddResponse("/network/vlan?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&name=Unit Test VLAN", "GenericNotFound.json");
            client.AddResponse("/network/deployVlan", "GenericError.json", HttpStatusCode.BadRequest);

            var templateFile = Path.Combine(_resourceFolder, "StandardTemplate.json");
            var parametersFile = Path.Combine(_resourceFolder, "StandardTemplateParams.json");
            var taskBuilder = new TaskBuilder();
            var taskExecutor = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
            var log = await taskExecutor.Execute(_runtimeContext);

            Assert.AreEqual(DeploymentLogStatus.Failed, log.Status);
            Assert.AreEqual(1, log.Resources.Count);
            Assert.AreEqual(ResourceLogStatus.Failed, log.Resources[0].DeploymentStatus);
            Assert.AreEqual("UNEXPECTED_ERROR", log.Resources[0].Error.ResponseCode);
        }
예제 #7
0
        public async Task ParseAndExecuteDeploymentTasks_Failed()
        {
            var client = new FakeHttpClient();

            client.AddResponse("/network/networkDomain/d5791a6d-2b69-47e2-be06-f26a2ec4bff8", "NetworkDomain_Get.json");
            client.AddResponse("/network/vlan?networkDomainId=d5791a6d-2b69-47e2-be06-f26a2ec4bff8&name=Unit Test VLAN", "GenericNotFound.json");
            client.AddResponse("/network/deployVlan", "GenericError.json", HttpStatusCode.BadRequest);

            var templateFile   = Path.Combine(_resourceFolder, "StandardTemplate.json");
            var parametersFile = Path.Combine(_resourceFolder, "StandardTemplateParams.json");
            var taskBuilder    = new TaskBuilder();
            var taskExecutor   = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
            var log            = await taskExecutor.Execute(_runtimeContext);

            Assert.AreEqual(DeploymentLogStatus.Failed, log.Status);
            Assert.AreEqual(1, log.Resources.Count);
            Assert.AreEqual(ResourceLogStatus.Failed, log.Resources[0].DeploymentStatus);
            Assert.AreEqual("UNEXPECTED_ERROR", log.Resources[0].Error.ResponseCode);
        }
 public void CircularDependency()
 {
     var templateFile = Path.Combine(_resourceFolder, "CircularDependency.json");
     var parametersFile = Path.Combine(_resourceFolder, "StandardTemplateParams.json");
     var taskBuilder = new TaskBuilder();
     var taskExecutor = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile);
 }