Beispiel #1
0
        /// <inheritdoc/>
        public override async Task RunAsync(CommandLine commandLine)
        {
            if (commandLine.HasHelpOption)
            {
                Help();
                Program.Exit(0);
            }

            Console.WriteLine();

            var context = KubeHelper.CurrentContext;

            if (context == null)
            {
                Console.Error.WriteLine($"*** ERROR: There is no current cluster.");
                Program.Exit(1);
            }

            var force = commandLine.HasOption("--force");

            using (var cluster = new ClusterProxy(context, new HostingManagerFactory()))
            {
                var capabilities = cluster.Capabilities;

                if ((capabilities & HostingCapabilities.Pausable) == 0)
                {
                    Console.Error.WriteLine($"*** ERROR: Cluster does not support pause/resume.");
                    Program.Exit(1);
                }

                var status = await cluster.GetClusterHealthAsync();

                switch (status.State)
                {
                case ClusterState.Healthy:
                case ClusterState.Unhealthy:

                    if (!force)
                    {
                        var isLocked = await cluster.IsLockedAsync();

                        if (!isLocked.HasValue)
                        {
                            Console.Error.WriteLine($"*** ERROR: [{cluster.Name}] lock status is unknown.");
                            Program.Exit(1);
                        }

                        if (isLocked.Value)
                        {
                            Console.Error.WriteLine($"*** ERROR: [{cluster.Name}] is locked.");
                            Program.Exit(1);
                        }

                        if (!Program.PromptYesNo($"Are you sure you want to pause: {cluster.Name}?"))
                        {
                            Program.Exit(0);
                        }
                    }

                    Console.WriteLine($"Pausing: {cluster.Name}");

                    try
                    {
                        await cluster.StopAsync(StopMode.Pause);

                        Console.WriteLine($"PAUSED:  {cluster.Name}");
                    }
                    catch (TimeoutException)
                    {
                        Console.WriteLine();
                        Console.WriteLine($"*** ERROR: Timeout waiting for cluster.");
                    }
                    break;

                default:

                    Console.Error.WriteLine($"*** ERROR: Cluster is not running.");
                    Program.Exit(1);
                    break;
                }
            }
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override async Task RunAsync(CommandLine commandLine)
        {
            if (commandLine.HasHelpOption)
            {
                Help();
                Program.Exit(0);
            }

            Console.WriteLine();

            var context = KubeHelper.CurrentContext;

            if (context == null)
            {
                Console.Error.WriteLine($"*** ERROR: There is no current cluster.");
                Program.Exit(1);
            }

            var turnoff = commandLine.HasOption("--turnoff");
            var force   = commandLine.HasOption("--force");

            using (var cluster = new ClusterProxy(context, new HostingManagerFactory()))
            {
                var capabilities = cluster.Capabilities;

                if ((capabilities & HostingCapabilities.Stoppable) == 0)
                {
                    Console.Error.WriteLine($"*** ERROR: Cluster does not support start/stop.");
                    Program.Exit(1);
                }

                var status = await cluster.GetClusterHealthAsync();

                switch (status.State)
                {
                case ClusterState.Healthy:
                case ClusterState.Unhealthy:

                    if (!force)
                    {
                        var isLocked = await cluster.IsLockedAsync();

                        if (!isLocked.HasValue)
                        {
                            Console.Error.WriteLine($"*** ERROR: [{cluster.Name}] lock status is unknown.");
                            Program.Exit(1);
                        }

                        if (isLocked.Value)
                        {
                            Console.Error.WriteLine($"*** ERROR: [{cluster.Name}] is locked.");
                            Program.Exit(1);
                        }

                        if (!Program.PromptYesNo($"Are you sure you want to stop: {cluster.Name}?"))
                        {
                            Program.Exit(0);
                        }
                    }

                    try
                    {
                        if (turnoff)
                        {
                            Console.WriteLine($"Turning Off: {cluster.Name}");
                        }
                        else
                        {
                            Console.WriteLine($"Stopping: {cluster.Name}...");
                        }

                        await cluster.StopAsync(turnoff?StopMode.TurnOff : StopMode.Graceful);

                        Console.WriteLine($"STOPPED:  {cluster.Name}");
                    }
                    catch (TimeoutException)
                    {
                        Console.WriteLine();
                        Console.WriteLine($"*** ERROR: Timeout waiting for cluster.");
                    }
                    break;

                default:

                    Console.Error.WriteLine($"*** ERROR: Cluster is already stopped.");
                    Program.Exit(1);
                    break;
                }
            }
        }