So auto login according to pool setting.

This commit is contained in:
Michael Lipp 2025-03-03 21:26:10 +01:00
parent 701194799f
commit dfe3038463
5 changed files with 36 additions and 34 deletions

View file

@ -25,6 +25,12 @@ spec:
type: string
pattern: '^(?:\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,9})?(?:Z|[+-](?:[01]\d|2[0-3])(?:|:?[0-5]\d))|P(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?:\d+[Hh])?(?:\d+[Mm])?(?:\d+(?:\.\d{1,9})?[Ss])?)?)$'
default: "PT1h"
loginOnAssignment:
description: >-
If set to true, the user will be automatically logged in
to the VM's console when the VM is assigned to him.
type: boolean
default: false
permissions:
type: array
description: >-

View file

@ -5,6 +5,7 @@ metadata:
name: test-vms
spec:
retention: "PT1m"
loginOnAssignment: true
permissions:
- user: admin
may:

View file

@ -37,8 +37,9 @@ import org.jdrupes.vmoperator.util.DataPath;
@SuppressWarnings({ "PMD.DataClass" })
public class VmPool {
private String name;
private final String name;
private String retention;
private boolean loginOnAssignment;
private boolean defined;
private List<Grant> permissions = Collections.emptyList();
private final Set<String> vms
@ -53,6 +54,19 @@ public class VmPool {
this.name = name;
}
/**
* Fill the properties of a provisionally created pool from
* the definition.
*
* @param definition the definition
*/
public void defineFrom(VmPool definition) {
retention = definition.retention();
permissions = definition.permissions();
loginOnAssignment = definition.loginOnAssignment();
defined = true;
}
/**
* Returns the name.
*
@ -63,12 +77,12 @@ public class VmPool {
}
/**
* Sets the name.
* Checks if is login on assignment.
*
* @param name the name to set
* @return the loginOnAssignment
*/
public void setName(String name) {
this.name = name;
public boolean loginOnAssignment() {
return loginOnAssignment;
}
/**
@ -81,12 +95,10 @@ public class VmPool {
}
/**
* Sets if is.
*
* @param defined the defined to set
* Marks the pool as undefined.
*/
public void setDefined(boolean defined) {
this.defined = defined;
public void setUndefined() {
defined = false;
}
/**
@ -98,15 +110,6 @@ public class VmPool {
return retention;
}
/**
* Sets the retention.
*
* @param retention the retention to set
*/
public void setRetention(String retention) {
this.retention = retention;
}
/**
* Permissions granted for a VM from the pool.
*
@ -116,15 +119,6 @@ public class VmPool {
return permissions;
}
/**
* Sets the permissions.
*
* @param permissions the permissions to set
*/
public void setPermissions(List<Grant> permissions) {
this.permissions = permissions;
}
/**
* Returns the VM names.
*

View file

@ -105,7 +105,7 @@ public class PoolMonitor extends
// When pool is deleted, save VMs in pending
if (type == ResponseType.DELETED) {
Optional.ofNullable(pools.get(poolName)).ifPresent(pool -> {
pool.setDefined(false);
pool.setUndefined();
if (pool.vms().isEmpty()) {
pools.remove(poolName);
}
@ -129,11 +129,8 @@ public class PoolMonitor extends
// Get pool and merge changes
var vmPool = pools.computeIfAbsent(poolName, k -> new VmPool(poolName));
var newData = client().getJSON().getGson().fromJson(
GsonPtr.to(poolModel.data()).to("spec").get(), VmPool.class);
vmPool.setRetention(newData.retention());
vmPool.setPermissions(newData.permissions());
vmPool.setDefined(true);
vmPool.defineFrom(client().getJSON().getGson().fromJson(
GsonPtr.to(poolModel.data()).to("spec").get(), VmPool.class));
poolPipeline.fire(new VmPoolChanged(vmPool));
}

View file

@ -301,6 +301,10 @@ public class VmMonitor extends
// Make sure that a newly assigned VM is running.
chosenVm.pipeline().fire(new ModifyVm(vmDef.name(),
"state", "Running", chosenVm));
if (vmPool.loginOnAssignment()) {
chosenVm.pipeline().fire(new ModifyVm(vmDef.name(),
"display/loggedInUser", event.toUser(), chosenVm));
}
return;
}
}