2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-09-12 04:26:26 +00:00

Provide nicer message when requested VM does not exist

This commit is contained in:
Jarrod Johnson
2026-07-01 09:55:15 -04:00
parent d761c7e6da
commit 3a6887b4b4
@@ -224,6 +224,8 @@ class PmxApiClient:
async def get_vm(self, vm):
if vm not in self.vmmap:
await self.map_vms()
if vm not in self.vmmap:
raise exc.NotFoundException("VM {} not found on Proxmox server {}".format(vm, self.server))
return self.vmmap[vm]
@@ -405,6 +407,11 @@ async def retrieve(nodes, element, configmanager, inputdata):
if isinstance(currclient, Exception):
yield msg.ConfluentNodeError(node, str(currclient))
continue
try:
await currclient.get_vm(node)
except Exception as e:
yield msg.ConfluentNodeError(node, str(e))
continue
if element == ['power', 'state']:
yield msg.PowerState(node, await currclient.get_vm_power(node))
elif element == ['boot', 'nextdevice']:
@@ -429,6 +436,11 @@ async def update(nodes, element, configmanager, inputdata):
if isinstance(currclient, Exception):
yield msg.ConfluentNodeError(node, str(currclient))
continue
try:
await currclient.get_vm(node)
except Exception as e:
yield msg.ConfluentNodeError(node, str(e))
continue
if element == ['power', 'state']:
newstate, oldstate = await currclient.set_vm_power(node, inputdata.powerstate(node))
yield msg.PowerState(node, newstate, oldstate)
@@ -452,6 +464,11 @@ async def create(nodes, element, configmanager, inputdata):
if isinstance(clientsbynode[node], Exception):
yield msg.ConfluentNodeError(node, str(clientsbynode[node]))
continue
try:
await clientsbynode[node].get_vm(node)
except Exception as e:
yield msg.ConfluentNodeError(node, str(e))
continue
if element == ['console', 'ikvm']:
try:
currclient = clientsbynode[node]