summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-08-24 17:06:35 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-07 14:24:41 +0200
commit83d7e45a6b749df0c208e56885402c66e54c4b23 (patch)
tree064249e2c953179cf1a452843836dff31ccb7f0b /opendc-compute/opendc-compute-simulator
parentd097d65851619483a85ce16ab56f61a726bbe756 (diff)
fix(compute): Start host even if it already exists on host
Diffstat (limited to 'opendc-compute/opendc-compute-simulator')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt12
1 files changed, 4 insertions, 8 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
index 76cc7dfe..4526537d 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt
@@ -294,16 +294,12 @@ public class SimHost(
}
override suspend fun spawn(server: Server, start: Boolean) {
- // Return if the server already exists on this host
- if (server in this) {
- return
+ val guest = guests.computeIfAbsent(server) { key ->
+ require(canFit(key)) { "Server does not fit" }
+ _guests.add(1)
+ Guest(key, hypervisor.createMachine(key.flavor.toMachineModel(), key.name))
}
- require(canFit(server)) { "Server does not fit" }
- val guest = Guest(server, hypervisor.createMachine(server.flavor.toMachineModel(), server.name))
- guests[server] = guest
- _guests.add(1)
-
if (start) {
guest.start()
}