/** * Detroys the VM in vSphere * * @param name - VM object to destroy * @throws VSphereException */ public void destroyVm(String name, boolean failOnNoExist) throws VSphereException { try { VirtualMachine vm = getVmByName(name); if (vm == null) { if (failOnNoExist) throw new VSphereException("VM does not exist"); System.out.println("VM does not exist, or already deleted!"); return; } if (!vm.getConfig().template) { powerOffVm(vm, true, false); } String status = vm.destroy_Task().waitForTask(); if (status.equals(Task.SUCCESS)) { System.out.println("VM was deleted successfully."); return; } } catch (Exception e) { throw new VSphereException(e.getMessage()); } throw new VSphereException("Could not delete VM!"); }
public void markAsTemplate(String vmName, String snapName, boolean force) throws VSphereException { try { VirtualMachine vm = getVmByName(vmName); if (vm.getConfig().template) return; if (isPoweredOff(vm) || force) { powerOffVm(vm, force, false); vm.markAsTemplate(); return; } } catch (Exception e) { throw new VSphereException("Could not convert to Template", e); } throw new VSphereException( "Could not mark as Template. Check it's power state or select \"force.\""); }