use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class PowerOff method powerOff.
private boolean powerOff(final Run<?, ?> run, Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
EnvVars env;
String expandedVm = vm;
if (run instanceof AbstractBuild) {
try {
env = run.getEnvironment(listener);
} catch (Exception e) {
throw new VSphereException(e);
}
// Add in matrix axes..
env.overrideAll(((AbstractBuild) run).getBuildVariables());
expandedVm = env.expand(vm);
}
VSphereLogger.vsLogger(jLogger, "Shutting Down VM " + expandedVm + "...");
VirtualMachine vsphereVm = vsphere.getVmByName(expandedVm);
if (vsphereVm == null && !ignoreIfNotExists) {
throw new RuntimeException(Messages.validation_notFound("vm " + expandedVm));
}
if (vsphereVm != null) {
vsphere.powerOffVm(vsphereVm, evenIfSuspended, shutdownGracefully);
VSphereLogger.vsLogger(jLogger, "Successfully shutdown \"" + expandedVm + "\"");
} else {
VSphereLogger.vsLogger(jLogger, "Does not exists, BUT ignore it! \"" + expandedVm + "\"");
}
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class ExposeGuestInfo method exposeInfo.
public boolean exposeInfo(Run<?, ?> run, Launcher launcher, TaskListener listener) throws Exception {
PrintStream jLogger = listener.getLogger();
String vmName = vm;
EnvVars env;
try {
env = run.getEnvironment(listener);
} catch (Exception e) {
throw new VSphereException(e);
}
if (run instanceof AbstractBuild) {
// Add in matrix axes..
env.overrideAll(((AbstractBuild) run).getBuildVariables());
vmName = env.expand(vm);
resolvedEnvVariablePrefix = env.expand(envVariablePrefix).replace("-", "_");
}
VSphereLogger.vsLogger(jLogger, "Exposing guest info for VM \"" + vmName + "\" as environment variables");
VirtualMachine vsphereVm = vsphere.getVmByName(vmName);
if (vsphereVm == null) {
throw new RuntimeException(Messages.validation_notFound("vm " + vmName));
}
VSphereEnvAction envAction = createGuestInfoEnvAction(vsphereVm, jLogger);
if (waitForIp4) {
String prefix = resolvedEnvVariablePrefix == null ? envVariablePrefix : resolvedEnvVariablePrefix;
String machineIP = envAction.data.get(prefix + "_IpAddress");
while (!ipv4Pattern.matcher(machineIP).find()) {
try {
TimeUnit.SECONDS.sleep(30);
} catch (InterruptedException e) {
}
envAction = createGuestInfoEnvAction(vsphere.getVmByName(vmName), jLogger);
machineIP = envAction.data.get(prefix + "_IpAddress");
}
}
run.addAction(envAction);
VSphereLogger.vsLogger(jLogger, "Successfully exposed guest info for VM \"" + vmName + "\"");
return true;
}
Aggregations