So auto login according to pool setting.
This commit is contained in:
parent
701194799f
commit
dfe3038463
5 changed files with 36 additions and 34 deletions
|
|
@ -25,6 +25,12 @@ spec:
|
||||||
type: string
|
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])?)?)$'
|
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"
|
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:
|
permissions:
|
||||||
type: array
|
type: array
|
||||||
description: >-
|
description: >-
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ metadata:
|
||||||
name: test-vms
|
name: test-vms
|
||||||
spec:
|
spec:
|
||||||
retention: "PT1m"
|
retention: "PT1m"
|
||||||
|
loginOnAssignment: true
|
||||||
permissions:
|
permissions:
|
||||||
- user: admin
|
- user: admin
|
||||||
may:
|
may:
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,9 @@ import org.jdrupes.vmoperator.util.DataPath;
|
||||||
@SuppressWarnings({ "PMD.DataClass" })
|
@SuppressWarnings({ "PMD.DataClass" })
|
||||||
public class VmPool {
|
public class VmPool {
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
private String retention;
|
private String retention;
|
||||||
|
private boolean loginOnAssignment;
|
||||||
private boolean defined;
|
private boolean defined;
|
||||||
private List<Grant> permissions = Collections.emptyList();
|
private List<Grant> permissions = Collections.emptyList();
|
||||||
private final Set<String> vms
|
private final Set<String> vms
|
||||||
|
|
@ -53,6 +54,19 @@ public class VmPool {
|
||||||
this.name = name;
|
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.
|
* 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) {
|
public boolean loginOnAssignment() {
|
||||||
this.name = name;
|
return loginOnAssignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,12 +95,10 @@ public class VmPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if is.
|
* Marks the pool as undefined.
|
||||||
*
|
|
||||||
* @param defined the defined to set
|
|
||||||
*/
|
*/
|
||||||
public void setDefined(boolean defined) {
|
public void setUndefined() {
|
||||||
this.defined = defined;
|
defined = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -98,15 +110,6 @@ public class VmPool {
|
||||||
return retention;
|
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.
|
* Permissions granted for a VM from the pool.
|
||||||
*
|
*
|
||||||
|
|
@ -116,15 +119,6 @@ public class VmPool {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the permissions.
|
|
||||||
*
|
|
||||||
* @param permissions the permissions to set
|
|
||||||
*/
|
|
||||||
public void setPermissions(List<Grant> permissions) {
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the VM names.
|
* Returns the VM names.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ public class PoolMonitor extends
|
||||||
// When pool is deleted, save VMs in pending
|
// When pool is deleted, save VMs in pending
|
||||||
if (type == ResponseType.DELETED) {
|
if (type == ResponseType.DELETED) {
|
||||||
Optional.ofNullable(pools.get(poolName)).ifPresent(pool -> {
|
Optional.ofNullable(pools.get(poolName)).ifPresent(pool -> {
|
||||||
pool.setDefined(false);
|
pool.setUndefined();
|
||||||
if (pool.vms().isEmpty()) {
|
if (pool.vms().isEmpty()) {
|
||||||
pools.remove(poolName);
|
pools.remove(poolName);
|
||||||
}
|
}
|
||||||
|
|
@ -129,11 +129,8 @@ public class PoolMonitor extends
|
||||||
|
|
||||||
// Get pool and merge changes
|
// Get pool and merge changes
|
||||||
var vmPool = pools.computeIfAbsent(poolName, k -> new VmPool(poolName));
|
var vmPool = pools.computeIfAbsent(poolName, k -> new VmPool(poolName));
|
||||||
var newData = client().getJSON().getGson().fromJson(
|
vmPool.defineFrom(client().getJSON().getGson().fromJson(
|
||||||
GsonPtr.to(poolModel.data()).to("spec").get(), VmPool.class);
|
GsonPtr.to(poolModel.data()).to("spec").get(), VmPool.class));
|
||||||
vmPool.setRetention(newData.retention());
|
|
||||||
vmPool.setPermissions(newData.permissions());
|
|
||||||
vmPool.setDefined(true);
|
|
||||||
poolPipeline.fire(new VmPoolChanged(vmPool));
|
poolPipeline.fire(new VmPoolChanged(vmPool));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -301,6 +301,10 @@ public class VmMonitor extends
|
||||||
// Make sure that a newly assigned VM is running.
|
// Make sure that a newly assigned VM is running.
|
||||||
chosenVm.pipeline().fire(new ModifyVm(vmDef.name(),
|
chosenVm.pipeline().fire(new ModifyVm(vmDef.name(),
|
||||||
"state", "Running", chosenVm));
|
"state", "Running", chosenVm));
|
||||||
|
if (vmPool.loginOnAssignment()) {
|
||||||
|
chosenVm.pipeline().fire(new ModifyVm(vmDef.name(),
|
||||||
|
"display/loggedInUser", event.toUser(), chosenVm));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue