private void postConfiguration(VirtualMachine vm, String name, String group, Set<NetworkConfig> networkConfigs) { if (!vm.getConfig().isTemplate()) VSpherePredicate.WAIT_FOR_VMTOOLS(10 * 1000 * 60, TimeUnit.MILLISECONDS).apply(vm); GuestOperationsManager gom = serviceInstance.get().getInstance().getGuestOperationsManager(); NamePasswordAuthentication npa = new NamePasswordAuthentication(); npa.setUsername("root"); npa.setPassword(vmInitPassword); GuestProgramSpec gps = new GuestProgramSpec(); InputStream in = VSphereComputeServiceAdapter.class.getResourceAsStream("/postConfigurationScript.sh"); GuestFilesUtils.loadFileToGuest(vm, in, npa, serviceInstance.get(), "/tmp/ping_dns.sh"); gps.programPath = "/bin/sh"; StringBuilder ethScript = new StringBuilder(); ethScript.append("/tmp/ping_dns.sh > jclouds.log 2>&1"); gps.arguments = "-c \"" + ethScript.toString() + "\""; List<String> env = Lists.newArrayList("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin", "SHELL=/bin/bash"); waitForStateToChange(); if (!vm.getConfig().isTemplate()) VSpherePredicate.WAIT_FOR_VMTOOLS(10 * 1000 * 60, TimeUnit.MILLISECONDS).apply(vm); waitForStateToChange(); gps.setEnvVariables(env.toArray(new String[env.size()])); GuestProcessManager gpm = gom.getProcessManager(vm); try { long pid = gpm.startProgramInGuest(npa, gps); GuestProcessInfo[] processInfos = gpm.listProcessesInGuest(npa, new long[]{pid}); if (null != processInfos) { for (GuestProcessInfo processInfo : processInfos) { while (processInfo.getExitCode() == null) { processInfos = gpm.listProcessesInGuest(npa, new long[]{pid}); processInfo = processInfos[0]; } if (processInfo.getExitCode() != 0) { logger.warn("failed to run init script on node ( " + name + " ) exit code : " + processInfo.getExitCode()); //Throwables.propagate(new Exception("Failed to customize vm ( " + name + " )")); } } } logger.trace("<< process pid : " + pid); } catch (Exception e) { } }
public GuestProcessInfo[] listProcessesInGuest(GuestAuthentication auth, long[] pids) throws GuestOperationsFault, InvalidState, TaskInProgress, RuntimeFault, RemoteException { return getVimService().listProcessesInGuest(getMOR(), vm.getMOR(), auth, pids); }