diff --git a/deploy/crds/vmpools-crd.yaml b/deploy/crds/vmpools-crd.yaml index b34d096..2144940 100644 --- a/deploy/crds/vmpools-crd.yaml +++ b/deploy/crds/vmpools-crd.yaml @@ -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: >- diff --git a/dev-example/test-pool.yaml b/dev-example/test-pool.yaml index a72a623..497aaf7 100644 --- a/dev-example/test-pool.yaml +++ b/dev-example/test-pool.yaml @@ -5,6 +5,7 @@ metadata: name: test-vms spec: retention: "PT1m" + loginOnAssignment: true permissions: - user: admin may: diff --git a/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/VmPool.java b/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/VmPool.java index e0817d5..155609f 100644 --- a/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/VmPool.java +++ b/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/VmPool.java @@ -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 permissions = Collections.emptyList(); private final Set 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 permissions) { - this.permissions = permissions; - } - /** * Returns the VM names. * diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java index 1ea15e1..0e25803 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/PoolMonitor.java @@ -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)); } diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmMonitor.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmMonitor.java index 4f8ac77..9e080e6 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmMonitor.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmMonitor.java @@ -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; } }