public DeleteVMAction() { super(VMNode.this, String.format("This operation will delete virtual machine %s.\nThe associated disks will not be deleted " + "from your storage account.\n\nAre you sure you want to continue?", virtualMachine.name()), "Deleting VM"); }
public ShutdownVMAction() { super(VMNode.this, String.format( "This operation will result in losing the virtual IP address\nthat was assigned to this virtual machine.\n\n" + "Are you sure that you want to shut down virtual machine %s?", virtualMachine.name()), "Shutting down VM"); }
@Override public Void call() throws Exception { try { vm.deallocate(); } catch (CloudException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } }));
@Override public Void call() throws Exception { try { vm.start(); } catch (CloudException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } }));
@Override public Void call() throws Exception { try { vm.restart(); } catch (CloudException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } }));
@Override public Future<Void> stopAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { stop(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
@Override public Future<Void> startAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call" + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { start(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
@Override public Future<Void> restartAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { restart(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
@Override public boolean startIfStopped(final String id, final Timeout timeout) throws InterruptedException { VirtualMachine vm = getById(id); switch (vm.powerState()) { case RUNNING: case DEALLOCATING: case STARTING: return false; case DEALLOCATED: log.info(vm.resourceGroupName() + " - " + vm.name() + " is deallocated, starting"); start(id, timeout); return true; default: throw new IllegalArgumentException("Unknown power state"); } }
@Override public boolean requestStopIfRunning(final String id) { VirtualMachine vm = getById(id); switch (vm.powerState()) { case DEALLOCATING: case STARTING: case DEALLOCATED: return false; case RUNNING: log.info(vm.resourceGroupName() + " - " + vm.name() + " is running, stopping"); stopAsync(id); return true; default: throw new IllegalArgumentException("Unknown power state"); } }
private void refreshItemsInternal() { // update vm name and status icon setName(virtualMachine.name()); setIconPath(getVMIconPath()); }
public VMNode(Node parent, String subscriptionId, VirtualMachine virtualMachine) throws AzureCmdException { super(virtualMachine.id(), virtualMachine.name(), parent, WAIT_ICON_PATH, true); this.virtualMachine = virtualMachine; this.subscriptionId = subscriptionId; loadActions(); // update vm icon based on vm status refreshItemsInternal(); }
@Override public boolean requestStartIfStopped(final String id) { VirtualMachine vm = getById(id); switch (vm.powerState()) { case RUNNING: case DEALLOCATING: case STARTING: return false; case DEALLOCATED: log.info(vm.resourceGroupName() + " - " + vm.name() + " is deallocated, starting"); startAsync(id); return true; default: throw new IllegalArgumentException("Unknown power state"); } }
@Override public boolean stopIfRunning(final String id, final Timeout timeout) throws InterruptedException { VirtualMachine vm = getById(id); switch (vm.powerState()) { case DEALLOCATING: case STARTING: case DEALLOCATED: return false; case RUNNING: log.info(vm.resourceGroupName() + " - " + vm.name() + " is running, stopping"); stop(id, timeout); return true; default: throw new IllegalArgumentException("Unknown power state"); } }
private void stop(final VirtualMachine vm, final Timeout timeout) throws InterruptedException { final String threadName = "Azure VM Stop - " + vm.resourceGroupName() + " - " + vm.name(); ListenableFuture<Void> future = synchronous.submit(new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { try { vm.deallocate(); } catch (CloudException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } })); waitForResult(future, timeout); }
private void restart(final VirtualMachine vm, final Timeout timeout) throws InterruptedException { //start some work final String threadName = "Azure VM Restart - " + vm.resourceGroupName() + " - " + vm.name(); ListenableFuture<Void> future = synchronous.submit(new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { try { vm.restart(); } catch (CloudException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } })); waitForResult(future, timeout); }
private void start(final VirtualMachine vm, final Timeout timeout) throws InterruptedException { //start some work final String threadName = "Azure VM Start - " + vm.resourceGroupName() + " - " + vm.name(); ListenableFuture<Void> future = synchronous.submit(new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { try { vm.start(); } catch (CloudException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } })); waitForResult(future, timeout); }
@Override protected void azureNodeAction(NodeActionEvent e) throws AzureCmdException { try { AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); // not signed in if (azureManager == null) { return; } azureManager.getAzure(subscriptionId).virtualMachines().deleteByResourceGroup(virtualMachine.resourceGroupName(), virtualMachine.name()); } catch (Exception ex) { } DefaultLoader.getIdeHelper().invokeLater(new Runnable() { @Override public void run() { // instruct parent node to remove this node getParent().removeDirectChildNode(VMNode.this); } }); }
AzureDockerVM dockerVM = new AzureDockerVM(); dockerVM.name = vm.name();