This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release: com.io7m.waxmill 0.0.6 Change: Add vm-id-of command Change: Use short IDs for compatibility with modern Bhyve (Ticket: #30)
- Loading branch information
Showing
32 changed files
with
480 additions
and
70 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
105 changes: 105 additions & 0 deletions
105
...o7m.waxmill.cmdline/src/main/java/com/io7m/waxmill/cmdline/internal/WXMCommandVMIDOf.java
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,105 @@ | ||
/* | ||
* Copyright © 2020 Mark Raynsford <code@io7m.com> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.waxmill.cmdline.internal; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import com.io7m.claypot.core.CLPCommandContextType; | ||
import com.io7m.waxmill.machines.WXMMachineName; | ||
import com.io7m.waxmill.machines.WXMShortIDs; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
import static com.io7m.claypot.core.CLPCommandType.Status.FAILURE; | ||
import static com.io7m.claypot.core.CLPCommandType.Status.SUCCESS; | ||
|
||
@Parameters(commandDescription = "Find the ID of a virtual machine") | ||
public final class WXMCommandVMIDOf extends WXMAbstractCommandWithConfiguration | ||
{ | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(WXMCommandVMIDOf.class); | ||
|
||
@Parameter( | ||
names = "--name", | ||
description = "The name of the virtual machine", | ||
converter = WXMMachineNameConverter.class, | ||
required = true | ||
) | ||
private WXMMachineName name; | ||
|
||
@Parameter( | ||
names = "--short", | ||
description = "Print the ID as a short ID", | ||
arity = 1, | ||
required = false | ||
) | ||
private boolean shortId; | ||
|
||
@Override | ||
public String extendedHelp() | ||
{ | ||
return this.messages().format("vmIDOfHelp"); | ||
} | ||
|
||
/** | ||
* Construct a command. | ||
* | ||
* @param inContext The command context | ||
*/ | ||
|
||
public WXMCommandVMIDOf( | ||
final CLPCommandContextType inContext) | ||
{ | ||
super(LOG, inContext); | ||
} | ||
|
||
@Override | ||
public String name() | ||
{ | ||
return "vm-id-of"; | ||
} | ||
|
||
@Override | ||
protected Status executeActualWithConfiguration( | ||
final Path configurationPath) | ||
throws Exception | ||
{ | ||
try (var client = WXMServices.clients().open(configurationPath)) { | ||
final var machines = client.vmList(); | ||
for (final var machine : machines.machines().values()) { | ||
if (Objects.equals(machine.name(), this.name)) { | ||
final var machineId = machine.id(); | ||
if (this.shortId) { | ||
System.out.println(WXMShortIDs.encode(machineId)); | ||
} else { | ||
System.out.println(machineId); | ||
} | ||
return SUCCESS; | ||
} | ||
} | ||
} | ||
|
||
LOG.error( | ||
"{}", | ||
this.messages().format("errorNoMachinesWithName", this.name.value()) | ||
); | ||
return FAILURE; | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...cumentation/src/main/resources/com/io7m/waxmill/documentation/cmdline-vm-id-of-output.txt
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,5 @@ | ||
$ waxmill vm-id-of --name example | ||
538a90e4-d50d-4511-8643-ae418279bac4 | ||
|
||
$ waxmill vm-id-of --name example --short | ||
U4qQ5NUNRRGGQ65Bgnm6xA |
Oops, something went wrong.