-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- parameter for running custom script command after vm creation - cpu cores option - more distros. arch, fedora, centos, alma - lost command shows more info: - vm state - cpu cores - memory - disk used - ping interface
- Loading branch information
Showing
9 changed files
with
266 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Completions; | ||
using Spectre.Console; | ||
using VmChamp; | ||
|
||
public class RestartCommand : Command | ||
{ | ||
private readonly AppConfig _appConfig; | ||
|
||
public RestartCommand(AppConfig appConfig) : base("restart", "force restarts a vm") | ||
{ | ||
_appConfig = appConfig; | ||
|
||
Argument<string> nameArgument = new("name", | ||
() => appConfig.DefaultVmName, | ||
"Name of the VM to restart."); | ||
|
||
this.AddAlias("reboot"); | ||
this.AddAlias("reset"); | ||
this.AddArgument(nameArgument); | ||
|
||
nameArgument.AddCompletions((ctx) => | ||
Helper.GetAllVmInDirectory(_appConfig.DataDir) | ||
.Select(vmName => new CompletionItem(vmName ?? ""))); | ||
|
||
nameArgument.AddCompletions((ctx) => | ||
Helper.GetAllVmInDirectory(_appConfig.DataDir) | ||
.Select(vmName => new CompletionItem(vmName ?? ""))); | ||
|
||
this.SetHandler((vmName) => | ||
{ | ||
using var libvirtConnection = LibvirtConnection.Create("qemu:///session"); | ||
var vmId = Interop.virDomainLookupByName(libvirtConnection.NativePtr, vmName); | ||
AnsiConsole.MarkupLine($"[yellow]🔄 Restart VM: {vmName}[/]"); | ||
Interop.virDomainReset(vmId); | ||
}, nameArgument); | ||
} | ||
} |
Oops, something went wrong.