summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-simulator
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-12 13:25:41 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 17:45:13 +0200
commit6a1aea440c3066edc2ea6b79a65adb5313f4dd48 (patch)
tree73c4adc0d5c8ad3d97c992424a5f998dd2c08263 /opendc-compute/opendc-compute-simulator
parentb4bf7268cbb6d22d3966f469a6b7721b04d91907 (diff)
feat(compute): Support filtering hosts based on CPU capacity
This change allows users to create servers with a smaller CPU capacity than the host, by specifying the CPU capacity via metadata. This also allows filtering hosts based on their available CPU capacity.
Diffstat (limited to 'opendc-compute/opendc-compute-simulator')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt7
1 files changed, 4 insertions, 3 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 b9d02185..10faeb5b 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
@@ -121,7 +121,7 @@ public class SimHost(
field = value
}
- override val model: HostModel = HostModel(model.cpus.size, model.memory.sumOf { it.size })
+ override val model: HostModel = HostModel(model.cpus.sumOf { it.frequency }, model.cpus.size, model.memory.sumOf { it.size })
/**
* The [GuestListener] that listens for guest events.
@@ -188,7 +188,7 @@ public class SimHost(
}
override fun canFit(server: Server): Boolean {
- val sufficientMemory = model.memorySize >= server.flavor.memorySize
+ val sufficientMemory = model.memoryCapacity >= server.flavor.memorySize
val enoughCpus = model.cpuCount >= server.flavor.cpuCount
val canFit = hypervisor.canFit(server.flavor.toMachineModel())
@@ -319,8 +319,9 @@ public class SimHost(
*/
private fun Flavor.toMachineModel(): MachineModel {
val originalCpu = machine.model.cpus[0]
+ val cpuCapacity = (this.meta["cpu-capacity"] as? Double ?: Double.MAX_VALUE).coerceAtMost(originalCpu.frequency)
val processingNode = originalCpu.node.copy(coreCount = cpuCount)
- val processingUnits = (0 until cpuCount).map { originalCpu.copy(id = it, node = processingNode) }
+ val processingUnits = (0 until cpuCount).map { originalCpu.copy(id = it, node = processingNode, frequency = cpuCapacity) }
val memoryUnits = listOf(MemoryUnit("Generic", "Generic", 3200.0, memorySize))
return MachineModel(processingUnits, memoryUnits).optimize()