Skip to content

Commit

Permalink
try to use uuid to find crd
Browse files Browse the repository at this point in the history
  • Loading branch information
h56983577 committed Dec 31, 2023
1 parent 0fbfec8 commit 1100c79
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Vm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class VmService(val call: ApplicationCall) : IService {
?: throw NotFoundException("VirtualMachine($uuid) is not found")
}

fun getVmByUUid(uuid: String): VirtualMachineCrd {
return vmKubeClient.inAnyNamespace().withField("status.uuid", uuid).list().items.filterNot { it.spec.deleted }
.firstOrNull()
?: throw NotFoundException("VirtualMachine($uuid) is not found")
}

fun deleteVm(id: String) {
val vm = getVmByUUID(id)
vm.spec = vm.spec.copy(deleted = true)
Expand Down Expand Up @@ -346,7 +352,7 @@ class VmService(val call: ApplicationCall) : IService {
// if (mysql.virtualMachines.exists { it.isTemplate.eq(true) and it.name.eq(name) }) {
// throw BadRequestException("template name already exists")
// }
val vmCrd = getVmByUUID(crdId)
val vmCrd = getVmByUUid(uuid)
vmCrd.spec = vmCrd.spec.copy(template = true)
vmKubeClient.resource(vmCrd).patch()
val owner = call.user()
Expand Down

0 comments on commit 1100c79

Please sign in to comment.