Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
Release: com.io7m.waxmill 0.0.2
Change: Add the vm-kill command
  • Loading branch information
io7m committed Jul 11, 2020
2 parents bb8d476 + e4ab0fa commit 1de92a4
Show file tree
Hide file tree
Showing 46 changed files with 671 additions and 46 deletions.
9 changes: 7 additions & 2 deletions README-CHANGES.xml
@@ -1,9 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<c:changelog project="com.io7m.waxmill" xmlns:c="urn:com.io7m.changelog:4.0">
<c:releases>
<c:release date="2020-07-11T17:33:12+00:00" ticket-system="com.github.io7m.waxmill" version="0.0.1">
<c:release date="2020-07-11T00:00:00+00:00" ticket-system="com.github.io7m.waxmill" version="0.0.1">
<c:changes>
<c:change date="2020-07-11T17:33:12+00:00" summary="Initial testing release"/>
<c:change date="2020-07-11T00:00:00+00:00" summary="Initial testing release"/>
</c:changes>
</c:release>
<c:release date="2020-07-11T18:36:10+00:00" ticket-system="com.github.io7m.waxmill" version="0.0.2">
<c:changes>
<c:change date="2020-07-11T18:36:10+00:00" summary="Add the vm-kill command"/>
</c:changes>
</c:release>
</c:releases>
Expand Down
2 changes: 1 addition & 1 deletion com.io7m.waxmill.boot/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.boot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion com.io7m.waxmill.client.api/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.client.api</artifactId>
Expand Down
Expand Up @@ -61,6 +61,18 @@ default Path bhyveExecutable()
.getPath("/usr/sbin/bhyve");
}

/**
* @return The "bhyvectl" executable path, such as {@code /usr/sbin/bhyvectl}
*/

@Value.Default
default Path bhyveCtlExecutable()
{
return this.virtualMachineConfigurationDirectory()
.getFileSystem()
.getPath("/usr/sbin/bhyvectl");
}

/**
* @return The "grub-bhyve" executable path, such as {@code /usr/local/sbin/grub-bhyve}
*/
Expand Down
Expand Up @@ -192,4 +192,16 @@ void vmRealize(
WXMVirtualMachine machine,
WXMDryRun dryRun)
throws WXMException;

/**
* Kill a running virtual machine.
*
* @param dryRun Whether or not the operation is a dry run
* @param machine The virtual machine
*/

void vmKill(
WXMVirtualMachine machine,
WXMDryRun dryRun)
throws WXMException;
}
2 changes: 1 addition & 1 deletion com.io7m.waxmill.client.vanilla/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.client.vanilla</artifactId>
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -150,6 +151,38 @@ public void vmRun(
}
}


@Override
public void vmKill(
final WXMVirtualMachine machine,
final WXMDryRun dryRun)
throws WXMException
{
final var processDescription =
WXMProcessDescription.builder()
.setExecutable(this.configuration.bhyveCtlExecutable())
.addArguments(String.format("--vm=%s", machine.id()))
.addArguments("--destroy")
.build();

switch (dryRun) {
case DRY_RUN:
System.out.printf(
"%s %s%n",
processDescription.executable(),
String.join(" ", processDescription.arguments())
);
break;
case EXECUTE:
try {
this.processes.processReplaceCurrent(processDescription);
} catch (final IOException e) {
throw new WXMException(e);
}
break;
}
}

@Override
public void vmDelete(final UUID id)
throws WXMException
Expand Down
2 changes: 1 addition & 1 deletion com.io7m.waxmill.cmdline/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.cmdline</artifactId>
Expand Down
Expand Up @@ -37,6 +37,7 @@
import com.io7m.waxmill.cmdline.internal.WXMCommandVMDeleteDevice;
import com.io7m.waxmill.cmdline.internal.WXMCommandVMExport;
import com.io7m.waxmill.cmdline.internal.WXMCommandVMImport;
import com.io7m.waxmill.cmdline.internal.WXMCommandVMKill;
import com.io7m.waxmill.cmdline.internal.WXMCommandVMList;
import com.io7m.waxmill.cmdline.internal.WXMCommandVMListWithName;
import com.io7m.waxmill.cmdline.internal.WXMCommandVMRealize;
Expand Down Expand Up @@ -88,6 +89,7 @@ public Main(
WXMCommandVMDeleteDevice::new,
WXMCommandVMExport::new,
WXMCommandVMImport::new,
WXMCommandVMKill::new,
WXMCommandVMList::new,
WXMCommandVMListWithName::new,
WXMCommandVMRealize::new,
Expand Down
@@ -0,0 +1,92 @@
/*
* 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.UUID;

import static com.io7m.claypot.core.CLPCommandType.Status.SUCCESS;
import static com.io7m.waxmill.machines.WXMDryRun.DRY_RUN;
import static com.io7m.waxmill.machines.WXMDryRun.EXECUTE;

@Parameters(commandDescription = "Kill a virtual machine.")
public final class WXMCommandVMKill extends WXMAbstractCommandWithConfiguration
{
private static final Logger LOG =
LoggerFactory.getLogger(WXMCommandVMKill.class);

@Parameter(
names = "--machine",
description = "The ID of the virtual machine",
required = true,
converter = WXMUUIDConverter.class
)
private UUID id;

@Parameter(
names = "--dry-run",
description = "Show the commands that would be executed, but do not execute them.",
required = false,
arity = 1
)
private boolean dryRun;

/**
* Construct a command.
*
* @param inContext The command context
*/

public WXMCommandVMKill(
final CLPCommandContextType inContext)
{
super(LOG, inContext);
}

@Override
public String extendedHelp()
{
return this.messages().format("vmKillHelp");
}

@Override
public String name()
{
return "vm-kill";
}

@Override
protected Status executeActualWithConfiguration(
final Path configurationPath)
throws Exception
{
try (var client = WXMServices.clients().open(configurationPath)) {
final var machine = client.vmFind(this.id);
client.vmKill(
machine,
this.dryRun ? DRY_RUN : EXECUTE
);
}
return SUCCESS;
}
}
Expand Up @@ -261,5 +261,9 @@ supporting it.
<entry key="vmAddFramebufferDeviceHelp"><![CDATA[
The vm-add-framebuffer-device command adds a raw framebuffer device to
a virtual machine that is connected to a VNC server.
]]></entry>

<entry key="vmKillHelp"><![CDATA[
The vm-kill command kills any running instance of a given virtual machine.
]]></entry>
</properties>
2 changes: 1 addition & 1 deletion com.io7m.waxmill.database.api/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.database.api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion com.io7m.waxmill.database.vanilla/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.database.vanilla</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion com.io7m.waxmill.documentation/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>com.io7m.waxmill</artifactId>
<groupId>com.io7m.waxmill</groupId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>

<artifactId>com.io7m.waxmill.documentation</artifactId>
Expand Down
@@ -0,0 +1,9 @@
(Formatted for legibility)

$ waxmill vm-kill \
--machine 538a90e4-d50d-4511-8643-ae418279bac4 \
--dry-run true

/usr/sbin/bhyvectl \
--vm=538a90e4-d50d-4511-8643-ae418279bac4 \
--destroy
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Section xmlns="urn:com.io7m.structural:7:0"
id="2ce6975a-cb78-408e-bf0f-1fa10288f049"
xmlns:xi="http://www.w3.org/2001/XInclude"
title="vm-kill">

<Subsection title="Name">
<Paragraph>
<Term type="command">vm-kill</Term>
- Kill a running virtual machine
</Paragraph>
</Subsection>

<Subsection title="Description">
<Paragraph>
The <Term type="command">vm-kill</Term> command kills a running virtual machine.
</Paragraph>

<FormalItem title="Parameters"
type="parametersTable">
<Table type="parametersTable">
<Columns>
<Column>Parameter</Column>
<Column>Type</Column>
<Column>Required</Column>
<Column>Description</Column>
</Columns>
<Row>
<Cell>
<Term type="parameter">--configuration</Term>
</Cell>
<Cell>
<Term type="parameterType">Path</Term>
</Cell>
<Cell>
<Term type="constant">false</Term>
</Cell>
<Cell>The path to the configuration file (environment variable: $WAXMILL_CONFIGURATION_FILE)</Cell>
</Row>
<Row>
<Cell>
<Term type="parameter">--dry-run</Term>
</Cell>
<Cell>
<Term type="parameterType">Boolean</Term>
</Cell>
<Cell>
<Term type="constant">false</Term>
</Cell>
<Cell>Show the commands that would be executed, but do not execute them.</Cell>
</Row>
<Row>
<Cell>
<Term type="parameter">--machine</Term>
</Cell>
<Cell>
<Term type="parameterType">UUID</Term>
</Cell>
<Cell>
<Term type="constant">true</Term>
</Cell>
<Cell>The ID of the virtual machine</Cell>
</Row>
<Row>
<Cell>
<Term type="parameter">--verbose</Term>
</Cell>
<Cell>
<Term type="parameterType">Log Level</Term>
</Cell>
<Cell>
<Term type="constant">false</Term>
</Cell>
<Cell>Set the minimum logging verbosity level.</Cell>
</Row>
</Table>
</FormalItem>
</Subsection>

<Subsection title="Example">
<FormalItem title="Example">
<Verbatim>
<xi:include parse="text"
href="cmdline-vm-kill-output.txt"/>
</Verbatim>
</FormalItem>
</Subsection>

</Section>

0 comments on commit 1de92a4

Please sign in to comment.