Skip to content

Commit

Permalink
Add reset action to VM management.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed Jan 29, 2025
1 parent af41c78 commit 8d96307
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,20 @@ protected void doUpdateConletState(NotifyConletModel event,
}
}

private void confirmReset(NotifyConletModel event,
ConsoleConnection channel, ResourceModel model,
ResourceBundle resourceBundle) throws TemplateNotFoundException,
MalformedTemplateNameException, ParseException, IOException {
Template tpl = freemarkerConfig()
.getTemplate("VmAccess-confirmReset.ftl.html");
channel.respond(new OpenModalDialog(type(), model.getConletId(),
processTemplate(event, tpl,
fmModel(event, channel, model.getConletId(), model)))
.addOption("cancelable", true).addOption("closeLabel", "")
.addOption("title",
resourceBundle.getString("confirmResetTitle")));
}

private void openConsole(ConsoleConnection channel, ResourceModel model,
VmChannel vmChannel, VmDefinition vmDef, Set<Permission> perms) {
var resourceBundle = resourceBundle(channel.locale());
Expand Down Expand Up @@ -828,20 +842,6 @@ private void selectResource(NotifyConletModel event,
}
}

private void confirmReset(NotifyConletModel event,
ConsoleConnection channel, ResourceModel model,
ResourceBundle resourceBundle) throws TemplateNotFoundException,
MalformedTemplateNameException, ParseException, IOException {
Template tpl = freemarkerConfig()
.getTemplate("VmAccess-confirmReset.ftl.html");
channel.respond(new OpenModalDialog(type(), model.getConletId(),
processTemplate(event, tpl,
fmModel(event, channel, model.getConletId(), model)))
.addOption("cancelable", true).addOption("closeLabel", "")
.addOption("title",
resourceBundle.getString("confirmResetTitle")));
}

@Override
protected boolean doSetLocale(SetLocale event, ConsoleConnection channel,
String conletId) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div
class="jdrupes-vmoperator-vmmgmt jdrupes-vmoperator-vmmgmt-confirm-reset">
<p>${_("confirmResetMsg")}</p>
<p>
<span role="button" tabindex="0" class="svg-icon"
onclick="orgJDrupesVmOperatorVmMgmt.confirmReset('${conletType}', '${conletId}', '${vmName}')">
<svg viewBox="0 0 1541.33 1535.5083">
<path d="m 0,127.9968 v 448 c 0,35 29,64 64,64 h 448 c 35,0 64,-29 64,-64 0,-17 -6.92831,-33.07213 -19,-45 C 264.23058,241.7154 337.19508,314.89599 109,82.996795 c -11.999999,-12 -28,-19 -45,-19 -35,0 -64,29 -64,64.000005 z" />
<path d="m 772.97656,1535.5046 c 117.57061,0.3623 236.06134,-26.2848 345.77544,-81.4687 292.5708,-147.1572 459.8088,-465.37411 415.5214,-790.12504 C 1489.9861,339.15993 1243.597,77.463924 922.29883,14.342498 601.00067,-48.778928 274.05699,100.37563 110.62891,384.39133 c -34.855139,60.57216 -14.006492,137.9313 46.5664,172.78516 60.57172,34.85381 137.92941,14.00532 172.78321,-46.56641 109.97944,-191.12927 327.69604,-290.34657 543.53515,-247.94336 215.83913,42.40321 380.18953,216.77543 410.00973,435.44141 29.8203,218.66598 -81.8657,430.94957 -278.4863,529.84567 -196.6206,98.8962 -432.84043,61.8202 -589.90233,-92.6777 -24.91016,-24.5038 -85.48587,-83.3326 -119.02246,-52.9832 -24.01114,21.7292 -35.41741,29.5454 -59.9209,54.4559 -24.50381,24.9102 -35.33636,36.9034 -57.54543,60.4713 -38.1335,40.4667 34.10761,93.9685 59.01808,118.472 145.96311,143.5803 339.36149,219.2087 535.3125,219.8125 z"/>
</svg>
</span>
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
v-on:click="vmAction(entry.name, 'stop')"></span>
<span role="button" v-else class="fa fa-stop"
aria-disabled="true" :title="localize('Stop VM')"></span>
<span role="button"
:aria-disabled="!entry['running']
|| !entry.permissions.includes('reset')"
tabindex="0" class="svg-icon" :title="localize('Reset VM')"
v-on:click="vmAction(entry.name, 'reset')">
<svg viewBox="0 0 1541.33 1535.5083">
<path d="m 0,127.9968 v 448 c 0,35 29,64 64,64 h 448 c 35,0 64,-29 64,-64 0,-17 -6.92831,-33.07213 -19,-45 C 264.23058,241.7154 337.19508,314.89599 109,82.996795 c -11.999999,-12 -28,-19 -45,-19 -35,0 -64,29 -64,64.000005 z" />
<path d="m 772.97656,1535.5046 c 117.57061,0.3623 236.06134,-26.2848 345.77544,-81.4687 292.5708,-147.1572 459.8088,-465.37411 415.5214,-790.12504 C 1489.9861,339.15993 1243.597,77.463924 922.29883,14.342498 601.00067,-48.778928 274.05699,100.37563 110.62891,384.39133 c -34.855139,60.57216 -14.006492,137.9313 46.5664,172.78516 60.57172,34.85381 137.92941,14.00532 172.78321,-46.56641 109.97944,-191.12927 327.69604,-290.34657 543.53515,-247.94336 215.83913,42.40321 380.18953,216.77543 410.00973,435.44141 29.8203,218.66598 -81.8657,430.94957 -278.4863,529.84567 -196.6206,98.8962 -432.84043,61.8202 -589.90233,-92.6777 -24.91016,-24.5038 -85.48587,-83.3326 -119.02246,-52.9832 -24.01114,21.7292 -35.41741,29.5454 -59.9209,54.4559 -24.50381,24.9102 -35.33636,36.9034 -57.54543,60.4713 -38.1335,40.4667 34.10761,93.9685 59.01808,118.472 145.96311,143.5803 339.36149,219.2087 535.3125,219.8125 z"/>
</svg>
</span>
<img role="button" :src="resourceBase + (!entry['running']
? 'computer-off.svg' : (entry.usedFrom
? 'computer-in-use.svg' : 'computer.svg'))"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ consoleTakenNotification = Die Konsole wird von einem anderen Benutzer verwendet
Open\ console = Konsole anzeigen
Start\ VM = VM Starten
Stop\ VM = VM Anhalten
Reset\ VM = VM zurücksetzen

Yes = Ja
No = Nein
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.jdrupes.vmoperator.manager.events.ChannelTracker;
import org.jdrupes.vmoperator.manager.events.GetDisplayPassword;
import org.jdrupes.vmoperator.manager.events.ModifyVm;
import org.jdrupes.vmoperator.manager.events.ResetVm;
import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
import org.jdrupes.vmoperator.util.DataPath;
Expand All @@ -64,6 +65,7 @@
import org.jgrapes.webconsole.base.events.DisplayNotification;
import org.jgrapes.webconsole.base.events.NotifyConletModel;
import org.jgrapes.webconsole.base.events.NotifyConletView;
import org.jgrapes.webconsole.base.events.OpenModalDialog;
import org.jgrapes.webconsole.base.events.RenderConlet;
import org.jgrapes.webconsole.base.events.RenderConletRequestBase;
import org.jgrapes.webconsole.base.events.SetLocale;
Expand Down Expand Up @@ -395,7 +397,8 @@ private Summary evaluateSummary(boolean force) {
}

@Override
@SuppressWarnings("PMD.AvoidDecimalLiteralsInBigDecimalConstructor")
@SuppressWarnings({ "PMD.AvoidDecimalLiteralsInBigDecimalConstructor",
"PMD.NcssCount" })
protected void doUpdateConletState(NotifyConletModel event,
ConsoleConnection channel, VmsModel model) throws Exception {
event.stop();
Expand All @@ -422,6 +425,16 @@ protected void doUpdateConletState(NotifyConletModel event,
fire(new ModifyVm(vmName, "state", "Stopped", vmChannel));
}
break;
case "reset":
if (perms.contains(VmDefinition.Permission.RESET)) {
confirmReset(event, channel, model, vmName);
}
break;
case "resetConfirmed":
if (perms.contains(VmDefinition.Permission.RESET)) {
fire(new ResetVm(vmName), vmChannel);
}
break;
case "openConsole":
if (perms.contains(VmDefinition.Permission.ACCESS_CONSOLE)) {
openConsole(channel, model, vmChannel, vmDef, user, perms);
Expand All @@ -443,6 +456,22 @@ protected void doUpdateConletState(NotifyConletModel event,
}
}

private void confirmReset(NotifyConletModel event,
ConsoleConnection channel, VmsModel model, String vmName)
throws TemplateNotFoundException,
MalformedTemplateNameException, ParseException, IOException {
Template tpl = freemarkerConfig()
.getTemplate("VmMgmt-confirmReset.ftl.html");
ResourceBundle resourceBundle = resourceBundle(channel.locale());
var fmModel = fmModel(event, channel, model.getConletId(), model);
fmModel.put("vmName", vmName);
channel.respond(new OpenModalDialog(type(), model.getConletId(),
processTemplate(event, tpl, fmModel))
.addOption("cancelable", true).addOption("closeLabel", "")
.addOption("title",
resourceBundle.getString("confirmResetTitle")));
}

private void openConsole(ConsoleConnection channel, VmsModel model,
VmChannel vmChannel, VmDefinition vmDef, String user,
Set<Permission> perms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ declare global {
interface Window {
orgJDrupesVmOperatorVmMgmt: {
initPreview?: (previewDom: HTMLElement, isUpdate: boolean) => void,
initView?: (viewDom: HTMLElement, isUpdate: boolean) => void
initView?: (viewDom: HTMLElement, isUpdate: boolean) => void,
confirmReset?: (conletType: string, conletId: string,
vmName: string) => void
}
}
}
Expand Down Expand Up @@ -236,4 +238,8 @@ JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmmgmt.VmMgmt",
window.open(url, target.id);
});


window.orgJDrupesVmOperatorVmMgmt.confirmReset =
(conletType: string, conletId: string, vmName: string) => {
JGConsole.instance.closeModalDialog(conletType, conletId);
JGConsole.notifyConletModel(conletId, "resetConfirmed", vmName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,24 @@
box-shadow: var(--darkening);
}
}


span[role="button"].svg-icon {
display: inline-block;
line-height: 1;
/* Align with forkawesome */
font-size: 14px;
fill: var(--primary);

&[aria-disabled="true"], &[aria-disabled=""] {
fill: var(--disabled);
}

svg {
height: 2ex;
width: 1em;
}
}

img {
display: inline;
height: 1.5em;
Expand All @@ -125,3 +142,35 @@
}
}
}

.jdrupes-vmoperator-vmmgmt.jdrupes-vmoperator-vmmgmt-confirm-reset {

[role=button] {
padding: 0.25rem;

&:not([aria-disabled]):hover, &[aria-disabled='false']:hover {
box-shadow: var(--darkening);
}
}

span[role="button"].svg-icon {
display: inline-block;
line-height: 1;
/* Align with forkawesome */
font-size: 14px;
fill: var(--danger);

&[aria-disabled="true"], &[aria-disabled=""] {
fill: var(--disabled);
}

svg {
width: 2.5em;
height: 2.5em;
}
}

p {
text-align: center;
}
}

0 comments on commit 8d96307

Please sign in to comment.