Exemplo n.º 1
0
        internal override void Execute(SkytapClient client, SkytapConfiguration configuration)
        {
            var runstate = client.GetConfigurationRunstate(configuration.Id);

            if (runstate == "stopped")
            {
                this.LogInformation("Environment {0} is already stopped.", configuration.Name);
                return;
            }

            if (runstate == "suspended" && this.Runstate == StopConfigurationMode.Suspend)
            {
                this.LogInformation("Environment {0} is already suspended.", configuration.Name);
                return;
            }

            this.LogInformation(
                "{0} environment...",
                InedoLib.Util.Switch <StopConfigurationMode, string>(this.Runstate)
                .Case(StopConfigurationMode.Suspend, "Suspending")
                .Case(StopConfigurationMode.ShutDown, "Shutting down")
                .Case(StopConfigurationMode.PowerOff, "Powering off")
                .End()
                );

            var targetRunstate = InedoLib.Util.Switch <StopConfigurationMode, string>(this.Runstate)
                                 .Case(StopConfigurationMode.Suspend, "suspended")
                                 .Case(StopConfigurationMode.ShutDown, "stopped")
                                 .Case(StopConfigurationMode.PowerOff, "halted")
                                 .End();

            client.SetConfigurationRunstate(configuration.Id, targetRunstate);

            if (this.WaitForStop)
            {
                this.LogInformation("Stop command issued; waiting for environment to enter {0} state...", this.Runstate == StopConfigurationMode.Suspend ? "suspended" : "stopped");

                do
                {
                    this.Context.CancellationToken.WaitHandle.WaitOne(5000);
                    this.ThrowIfCanceledOrTimeoutExpired();
                    runstate = client.GetConfigurationRunstate(configuration.Id);
                }while (runstate == "busy");

                if (runstate == "stopped" || runstate == "suspended")
                {
                    this.LogInformation("Environment is {0}.", runstate);
                }
                else
                {
                    this.LogError("Environment is {0}.", runstate);
                }
            }
            else
            {
                this.LogInformation("Stop command issued.");
            }
        }
Exemplo n.º 2
0
        internal override void Execute(SkytapClient client, SkytapConfiguration configuration)
        {
            var runstate = client.GetConfigurationRunstate(configuration.Id);

            if (runstate == "running")
            {
                this.LogInformation("Environment {0} is already running.", configuration.Name);
                return;
            }

            this.LogInformation("Starting environment...");
            client.SetConfigurationRunstate(configuration.Id, "running");

            if (this.WaitForStart)
            {
                this.LogInformation("Start command issued; waiting for environment to enter running state...");

                do
                {
                    this.Context.CancellationToken.WaitHandle.WaitOne(5000);
                    this.ThrowIfCanceledOrTimeoutExpired();
                    runstate = client.GetConfigurationRunstate(configuration.Id);
                }while (runstate == "busy");

                if (runstate == "running")
                {
                    this.LogInformation("Environment is running.");
                }
                else
                {
                    this.LogError("Environment is {0}.", runstate);
                }
            }
            else
            {
                this.LogInformation("Start command issued.");
            }
        }