/** * Attempts to delete the VM from disk. * @throws RemoteException * @throws InterruptedException */ public void removeVm() throws RemoteException, InterruptedException { try { Task task = vm.destroy_Task(); String status = task.waitForTask(); if (!status.equals("success")) { String message = task.getTaskInfo().getError() .getLocalizedMessage(); throw new RemoteException("Failed: " + message); } } catch (NotFound e) { log.warn("VM not found before attempting to delete it", e); } }
public static void main(String[] args) throws Exception { String urlStr ="http://dev:8000/vmAction.cgi?cmd=powerOn&moref=VirtualMachine:16&sessionId=9241E7B8-A37B-4264-A8D1-945628F9E0D6&locale=en&serviceUrl=https://localhost/sdk"; Map<String, String> kvPairs = parseURL(urlStr); String morStr = kvPairs.get(MOREF); String type = morStr.substring(0, morStr.indexOf(":")); String value = morStr.substring(morStr.indexOf(":")+1); ManagedObjectReference mor = new ManagedObjectReference(); mor.setType(type); mor.set_value(value); String sesssionStr = "vmware_soap_session=\"" + kvPairs.get(SESSION_ID) + "\""; ServiceInstance si = new ServiceInstance(new URL(kvPairs.get(SERVICE_URL)),sesssionStr, true); ManagedEntity me = MorUtil.createExactManagedEntity(si.getServerConnection(), mor); String name = me.getName(); System.out.println("name:" + name); if(me instanceof VirtualMachine) { Task task = ((VirtualMachine)me).powerOffVM_Task(); task.waitForMe(); } // si.getServerConnection().logout(); if you get access via sessionID, pls don't log out... }
public Task moveInto_Task(HostSystem[] hosts) throws TooManyHosts, DuplicateName, InvalidState, RuntimeFault, RemoteException { if(hosts==null) { throw new IllegalArgumentException("hosts must not be null."); } ManagedObjectReference taskMOR = getVimService().moveInto_Task(getMOR(), MorUtil.createMORs(hosts)); return new Task(getServerConnection(), taskMOR); }
/** @since SDK4.0 */ public void setTaskDescription(LocalizableMessage description) throws RuntimeFault, RemoteException { getVimService().setTaskDescription(getMOR(), description); }
Object[] result = waitForValues( new String[] { "info.state", "info.error" }, new String[] { "state" }, TaskInfo tinfo = (TaskInfo) getCurrentProperty(PROPNAME_INFO); LocalizedMethodFault fault = tinfo.getError(); String error = "Error Occured";
VirtualMachinePowerState.poweredOn); if(task.waitForMe()==Task.SUCCESS) TaskInfo info = task.getTaskInfo(); System.out.println(info.getError().getFault());
/** * Copyright 2009 NetApp, contribution by Eric Forgette * * This is a "drop-in" replacement for waitForMe() that uses a timed polling * in place of waitForValues. * * This method will eat 3 exceptions while trying to get TaskInfo and TaskState. * On the fourth try, the captured exception is thrown. * * @return String based on TaskInfoState * @throws RuntimeFault * @throws RemoteException * @throws InterruptedException * @throws RuntimeException if the third exception is not RuntimeFault or RemoteException * * @author Eric Forgette (forgette@netapp.com) */ public String waitForTask() throws RuntimeFault, RemoteException, InterruptedException { return waitForTask(500,1000); }
private static TaskInfo waitFor(Task task) throws RemoteException, InterruptedException { while(true) { TaskInfo ti = task.getTaskInfo(); TaskInfoState state = ti.getState(); if(state == TaskInfoState.success || state == TaskInfoState.error) { return ti; } Thread.sleep(1000); } } }
public TaskInfo getTaskInfo() throws InvalidProperty, RuntimeFault, RemoteException { return (TaskInfo) getCurrentProperty(PROPNAME_INFO); }
VirtualMachinePowerState.poweredOn); if(task.waitForMe()==Task.SUCCESS) TaskInfo info = task.getTaskInfo(); System.out.println(info.getError().getFault());
/** * Takes a snapshot of this VM. THe name of the snapshot is the current date and time. * The format of the name is yyyy-mm-dd hh:mm:ss * @throws VimFault * @throws RemoteException * @throws InterruptedException */ public void takeSnapshotOfVm() throws VimFault, RemoteException, InterruptedException { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); String name = dateFormat.format(date); String description = "created by Terraform's take-snapshot command"; Task task = vm.createSnapshot_Task(name, description, false, false); if (task.waitForTask() == Task.SUCCESS) { log.info("Created snapshot with name : " + name + " on virtual machine " + instanceName); } }
private static TaskInfo waitFor(Task task) throws RemoteException, InterruptedException { while(true) { TaskInfo ti = task.getTaskInfo(); TaskInfoState state = ti.getState(); if(state == TaskInfoState.success || state == TaskInfoState.error) { return ti; } Thread.sleep(1000); } } }
public void cancelTask() throws RuntimeFault, RemoteException { getVimService().cancelTask(getMOR()); }
private void handleTask(Task task) throws DestructionException, InterruptedException, RemoteException { task.waitForTask(); TaskInfo taskInfo = task.getTaskInfo(); if (TaskInfoState.error == taskInfo.getState()) { throw new DestructionException(taskInfo.getError().getLocalizedMessage()); } }
VirtualMachineMovePriority.highPriority, VirtualMachinePowerState.poweredOn); if (task.waitForMe() == Task.SUCCESS) { long end = System.currentTimeMillis(); log("vMotion of " + targetVMName + " to " + newHostName + " completed in " + (end - start) + "ms. Task result: " + task.getTaskInfo().getResult()); return true; } else { TaskInfo info = task.getTaskInfo(); log(WARNING, "vMotion of " + targetVMName + " to " + newHostName + " failed. Error details: " + info.getError().getFault());
public void addNewNetworkCard(VirtualMachine vm, String netName, String nicName, String nicType) throws NetworkConfigurationException { try { VirtualMachineConfigSpec vmSpec = new VirtualMachineConfigSpec(); VirtualDeviceConfigSpec nicSpec = createNicSpec(netName, nicName, nicType); vmSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {nicSpec}); Task task = vm.reconfigVM_Task(vmSpec); @SuppressWarnings("unused") String result = task.waitForTask(); } catch(Exception e) { throw new NetworkConfigurationException("Exception while adding network card to VM: " + e.getClass().getCanonicalName(), e); } }
public static void main(String[] args) throws Exception { String urlStr ="http://dev:8000/vmAction.cgi?cmd=powerOn&moref=VirtualMachine:16&sessionId=9241E7B8-A37B-4264-A8D1-945628F9E0D6&locale=en&serviceUrl=https://localhost/sdk"; Map<String, String> kvPairs = parseURL(urlStr); String morStr = kvPairs.get(MOREF); String type = morStr.substring(0, morStr.indexOf(":")); String value = morStr.substring(morStr.indexOf(":")+1); ManagedObjectReference mor = new ManagedObjectReference(); mor.setType(type); mor.set_value(value); String sesssionStr = "vmware_soap_session=\"" + kvPairs.get(SESSION_ID) + "\""; ServiceInstance si = new ServiceInstance(new URL(kvPairs.get(SERVICE_URL)),sesssionStr, true); ManagedEntity me = MorUtil.createExactManagedEntity(si.getServerConnection(), mor); String name = me.getName(); System.out.println("name:" + name); if(me instanceof VirtualMachine) { Task task = ((VirtualMachine)me).powerOffVM_Task(); task.waitForMe(); } // si.getServerConnection().logout(); if you get access via sessionID, pls don't log out... }
for(int i=0; recentTasks!=null && i<recentTasks.length; i++) TaskInfo ti = recentTasks[i].getTaskInfo(); System.out.println("\nName:" + ti.getName()); System.out.println("Key:" + ti.getKey());
/** @since SDK5.1 */ public Task updateDVSHealthCheckConfig_Task(DVSHealthCheckConfig[] healthCheckConfig) throws DvsFault, RuntimeFault, RemoteException { ManagedObjectReference taskMor = getVimService().updateDVSHealthCheckConfig_Task(getMOR(), healthCheckConfig); return new Task(getServerConnection(), taskMor); }
public void updateProgress(int percentDone) throws InvalidState, OutOfBounds, RuntimeFault, RemoteException { getVimService().updateProgress(getMOR(), percentDone); }