Add used by information.
This commit is contained in:
parent
4ea568ea17
commit
0ba8d922ef
7 changed files with 47 additions and 7 deletions
|
|
@ -1467,6 +1467,12 @@ spec:
|
||||||
The hostname of the currently connected client.
|
The hostname of the currently connected client.
|
||||||
type: string
|
type: string
|
||||||
default: ""
|
default: ""
|
||||||
|
consoleUser:
|
||||||
|
description: >-
|
||||||
|
The id of the user who has last requested a console
|
||||||
|
connection.
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
displayPasswordSerial:
|
displayPasswordSerial:
|
||||||
description: >-
|
description: >-
|
||||||
Counts changes of the display password. Set to -1
|
Counts changes of the display password. Set to -1
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,17 @@ import org.jgrapes.core.Event;
|
||||||
public class GetDisplayPassword extends Event<String> {
|
public class GetDisplayPassword extends Event<String> {
|
||||||
|
|
||||||
private final VmDefinition vmDef;
|
private final VmDefinition vmDef;
|
||||||
|
private final String user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new returns the display secret.
|
* Instantiates a new request for the display secret.
|
||||||
*
|
*
|
||||||
* @param vmDef the vm name
|
* @param vmDef the vm name
|
||||||
|
* @param user the requesting user
|
||||||
*/
|
*/
|
||||||
public GetDisplayPassword(VmDefinition vmDef) {
|
public GetDisplayPassword(VmDefinition vmDef, String user) {
|
||||||
this.vmDef = vmDef;
|
this.vmDef = vmDef;
|
||||||
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -48,6 +51,15 @@ public class GetDisplayPassword extends Event<String> {
|
||||||
return vmDef;
|
return vmDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the id of the user who has requested the password.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public String user() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the password. May only be called when the event is completed.
|
* Return the password. May only be called when the event is completed.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package org.jdrupes.vmoperator.manager;
|
package org.jdrupes.vmoperator.manager;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import io.kubernetes.client.apimachinery.GroupVersionKind;
|
||||||
import io.kubernetes.client.custom.V1Patch;
|
import io.kubernetes.client.custom.V1Patch;
|
||||||
import io.kubernetes.client.openapi.ApiException;
|
import io.kubernetes.client.openapi.ApiException;
|
||||||
import io.kubernetes.client.openapi.models.V1Secret;
|
import io.kubernetes.client.openapi.models.V1Secret;
|
||||||
|
|
@ -37,10 +39,13 @@ import java.util.Optional;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
|
||||||
|
import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
|
||||||
|
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
|
||||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_NAME;
|
import static org.jdrupes.vmoperator.common.Constants.VM_OP_NAME;
|
||||||
import org.jdrupes.vmoperator.common.K8sClient;
|
import org.jdrupes.vmoperator.common.K8sClient;
|
||||||
import org.jdrupes.vmoperator.common.K8sV1PodStub;
|
import org.jdrupes.vmoperator.common.K8sV1PodStub;
|
||||||
import org.jdrupes.vmoperator.common.K8sV1SecretStub;
|
import org.jdrupes.vmoperator.common.K8sV1SecretStub;
|
||||||
|
import org.jdrupes.vmoperator.common.VmDefinitionStub;
|
||||||
import static org.jdrupes.vmoperator.manager.Constants.COMP_DISPLAY_SECRET;
|
import static org.jdrupes.vmoperator.manager.Constants.COMP_DISPLAY_SECRET;
|
||||||
import static org.jdrupes.vmoperator.manager.Constants.DATA_DISPLAY_PASSWORD;
|
import static org.jdrupes.vmoperator.manager.Constants.DATA_DISPLAY_PASSWORD;
|
||||||
import static org.jdrupes.vmoperator.manager.Constants.DATA_PASSWORD_EXPIRY;
|
import static org.jdrupes.vmoperator.manager.Constants.DATA_PASSWORD_EXPIRY;
|
||||||
|
|
@ -181,12 +186,22 @@ public class DisplaySecretMonitor
|
||||||
+ "app.kubernetes.io/instance="
|
+ "app.kubernetes.io/instance="
|
||||||
+ event.vmDefinition().metadata().getName());
|
+ event.vmDefinition().metadata().getName());
|
||||||
var stubs = K8sV1SecretStub.list(client(),
|
var stubs = K8sV1SecretStub.list(client(),
|
||||||
event.vmDefinition().metadata().getNamespace(), options);
|
event.vmDefinition().namespace(), options);
|
||||||
if (stubs.isEmpty()) {
|
if (stubs.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var stub = stubs.iterator().next();
|
var stub = stubs.iterator().next();
|
||||||
|
|
||||||
|
// Valid request, update console user in status
|
||||||
|
var vmStub = VmDefinitionStub.get(client(),
|
||||||
|
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
|
||||||
|
event.vmDefinition().namespace(), event.vmDefinition().name());
|
||||||
|
vmStub.updateStatus(from -> {
|
||||||
|
JsonObject status = from.status();
|
||||||
|
status.addProperty("consoleUser", event.user());
|
||||||
|
return status;
|
||||||
|
});
|
||||||
|
|
||||||
// Check validity
|
// Check validity
|
||||||
var model = stub.model().get();
|
var model = stub.model().get();
|
||||||
@SuppressWarnings("PMD.StringInstantiation")
|
@SuppressWarnings("PMD.StringInstantiation")
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ nodeName = Node
|
||||||
requestedCpus = Requested CPUs
|
requestedCpus = Requested CPUs
|
||||||
requestedRam = Requested RAM
|
requestedRam = Requested RAM
|
||||||
running = Running
|
running = Running
|
||||||
|
usedBy = Used by
|
||||||
usedFrom = Used from
|
usedFrom = Used from
|
||||||
vmActions = Actions
|
vmActions = Actions
|
||||||
vmname = Name
|
vmname = Name
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ maximumRam = Maximales RAM
|
||||||
nodeName = Knoten
|
nodeName = Knoten
|
||||||
requestedCpus = Angeforderte CPUs
|
requestedCpus = Angeforderte CPUs
|
||||||
requestedRam = Angefordertes RAM
|
requestedRam = Angefordertes RAM
|
||||||
|
usedBy = Benutzt durch
|
||||||
usedFrom = Benutzt von
|
usedFrom = Benutzt von
|
||||||
vmActions = Aktionen
|
vmActions = Aktionen
|
||||||
vmname = Name
|
vmname = Name
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,8 @@ window.orgJDrupesVmOperatorVmConlet.initView = (viewDom: HTMLElement,
|
||||||
["currentCpus", "currentCpus"],
|
["currentCpus", "currentCpus"],
|
||||||
["currentRam", "currentRam"],
|
["currentRam", "currentRam"],
|
||||||
["nodeName", "nodeName"],
|
["nodeName", "nodeName"],
|
||||||
["usedFrom", "usedFrom"]
|
["usedFrom", "usedFrom"],
|
||||||
|
["usedBy", "usedBy"]
|
||||||
], {
|
], {
|
||||||
sortKey: "name",
|
sortKey: "name",
|
||||||
sortOrder: "up"
|
sortOrder: "up"
|
||||||
|
|
@ -181,6 +182,7 @@ JGConsole.registerConletFunction("org.jdrupes.vmoperator.vmconlet.VmConlet",
|
||||||
vmDefinition.currentCpus = vmDefinition.status.cpus;
|
vmDefinition.currentCpus = vmDefinition.status.cpus;
|
||||||
vmDefinition.currentRam = Number(vmDefinition.status.ram);
|
vmDefinition.currentRam = Number(vmDefinition.status.ram);
|
||||||
vmDefinition.usedFrom = vmDefinition.status.consoleClient || "";
|
vmDefinition.usedFrom = vmDefinition.status.consoleClient || "";
|
||||||
|
vmDefinition.usedBy = vmDefinition.status.consoleUser || "";
|
||||||
for (const condition of vmDefinition.status.conditions) {
|
for (const condition of vmDefinition.status.conditions) {
|
||||||
if (condition.type === "Running") {
|
if (condition.type === "Running") {
|
||||||
vmDefinition.running = condition.status === "True";
|
vmDefinition.running = condition.status === "True";
|
||||||
|
|
|
||||||
|
|
@ -527,7 +527,10 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
||||||
break;
|
break;
|
||||||
case "openConsole":
|
case "openConsole":
|
||||||
if (perms.contains(Permission.ACCESS_CONSOLE)) {
|
if (perms.contains(Permission.ACCESS_CONSOLE)) {
|
||||||
var pwQuery = Event.onCompletion(new GetDisplayPassword(vmDef),
|
var user = WebConsoleUtils.userFromSession(channel.session())
|
||||||
|
.map(ConsoleUser::getName).orElse("");
|
||||||
|
var pwQuery
|
||||||
|
= Event.onCompletion(new GetDisplayPassword(vmDef, user),
|
||||||
e -> openConsole(vmName, channel, model,
|
e -> openConsole(vmName, channel, model,
|
||||||
e.password().orElse(null)));
|
e.password().orElse(null)));
|
||||||
fire(pwQuery, vmChannel);
|
fire(pwQuery, vmChannel);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue