use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class Delete method killVm.
private boolean killVm(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
String expandedVm = 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());
expandedVm = env.expand(vm);
}
VSphereLogger.vsLogger(jLogger, "Destroying VM \"" + expandedVm + ".\" Please wait ...");
vsphere.destroyVm(expandedVm, failOnNoExist);
VSphereLogger.vsLogger(jLogger, "Destroyed!");
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class Deploy method deployFromTemplate.
private boolean deployFromTemplate(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
String expandedClone = clone;
String expandedTemplate = template;
String expandedCluster = cluster;
String expandedDatastore = datastore;
String expandedFolder = folder;
String expandedCustomizationSpec = customizationSpec;
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());
expandedClone = env.expand(clone);
expandedTemplate = env.expand(template);
expandedCluster = env.expand(cluster);
expandedDatastore = env.expand(datastore);
expandedFolder = env.expand(folder);
expandedCustomizationSpec = env.expand(customizationSpec);
}
String resourcePoolName;
if ("".equals(resourcePool) || (resourcePool.length() == 0)) {
// Not all installations are using resource pools. But there is always a hidden "Resources" resource
// pool, even if not visible in the vSphere Client.
resourcePoolName = "Resources";
} else {
resourcePoolName = env.expand(resourcePool);
}
vsphere.deployVm(expandedClone, expandedTemplate, linkedClone, resourcePoolName, expandedCluster, expandedDatastore, expandedFolder, powerOn, expandedCustomizationSpec, jLogger);
VSphereLogger.vsLogger(jLogger, "\"" + expandedClone + "\" successfully deployed!");
if (!powerOn) {
// don't try to obtain IP if VM isn't being turned on.
return true;
}
final int timeoutInSecondsForGetIp = getTimeoutInSeconds();
if (timeoutInSecondsForGetIp <= 0) {
// don't try to obtain IP if disabled
return true;
}
VSphereLogger.vsLogger(jLogger, "Trying to get the IP address of \"" + expandedClone + "\" for the next " + timeoutInSecondsForGetIp + " seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSecondsForGetIp);
if (IP != null) {
VSphereLogger.vsLogger(jLogger, "Successfully retrieved IP for \"" + expandedClone + "\" : " + IP);
VSphereLogger.vsLogger(jLogger, "Exposing " + IP + " as environment variable VSPHERE_IP");
if (run instanceof AbstractBuild) {
VSphereEnvAction envAction = new VSphereEnvAction();
envAction.add("VSPHERE_IP", IP);
run.addAction(envAction);
}
return true;
} else {
VSphereLogger.vsLogger(jLogger, "Error: Timed out after waiting " + timeoutInSecondsForGetIp + " seconds to get IP for \"" + expandedClone + "\" ");
return false;
}
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class Clone method cloneFromSource.
private boolean cloneFromSource(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
String expandedClone = clone;
String expandedSource = sourceName;
String expandedCluster = cluster;
String expandedDatastore = datastore;
String expandedFolder = folder;
String expandedResourcePool = resourcePool;
String expandedCustomizationSpec = customizationSpec;
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());
expandedClone = env.expand(clone);
expandedSource = env.expand(sourceName);
expandedCluster = env.expand(cluster);
expandedDatastore = env.expand(datastore);
expandedFolder = env.expand(folder);
expandedResourcePool = env.expand(resourcePool);
expandedCustomizationSpec = env.expand(customizationSpec);
}
vsphere.cloneVm(expandedClone, expandedSource, linkedClone, expandedResourcePool, expandedCluster, expandedDatastore, expandedFolder, powerOn, expandedCustomizationSpec, jLogger);
final int timeoutInSecondsForGetIp = getTimeoutInSeconds();
if (powerOn && timeoutInSecondsForGetIp > 0) {
VSphereLogger.vsLogger(jLogger, "Powering on VM \"" + expandedClone + "\". Waiting for its IP for the next " + timeoutInSecondsForGetIp + " seconds.");
IP = vsphere.getIp(vsphere.getVmByName(expandedClone), timeoutInSecondsForGetIp);
}
VSphereLogger.vsLogger(jLogger, "\"" + expandedClone + "\" successfully cloned " + (powerOn ? "and powered on" : "") + "!");
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class ConvertToVm method convert.
private boolean convert(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
VSphereLogger.vsLogger(jLogger, "Converting template to VM. Please wait ...");
String expandedTemplate = template;
String expandedCluster = cluster;
String expandedResourcePool = resourcePool;
EnvVars env;
try {
env = run.getEnvironment(listener);
} catch (Exception e) {
throw new VSphereException(e);
}
// TODO: take in a comma delimited list and convert all
if (run instanceof AbstractBuild) {
// Add in matrix axes..
env.overrideAll(((AbstractBuild) run).getBuildVariables());
expandedTemplate = env.expand(template);
expandedCluster = env.expand(cluster);
expandedResourcePool = env.expand(resourcePool);
}
vsphere.markAsVm(expandedTemplate, expandedResourcePool, expandedCluster);
VSphereLogger.vsLogger(jLogger, "\"" + expandedTemplate + "\" is a VM!");
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class DeleteSnapshot method deleteSnapshot.
private boolean deleteSnapshot(final Run<?, ?> run, Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
String expandedSnap = snapshotName;
String expandedVm = 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());
expandedSnap = env.expand(snapshotName);
expandedVm = env.expand(vm);
}
VSphereLogger.vsLogger(jLogger, "Deleting snapshot \"" + expandedSnap + "\" of VM " + expandedVm + "...");
vsphere.deleteSnapshot(expandedVm, expandedSnap, consolidate, failOnNoExist);
VSphereLogger.vsLogger(jLogger, "Complete.");
return true;
}
Aggregations