use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class Reconfigure method reconfigureVm.
private boolean reconfigureVm(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException, IOException, InterruptedException {
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);
}
VirtualMachine realVM = vsphere.getVmByName(expandedVm);
VSphereLogger.vsLogger(jLogger, "Reconfiguring VM \"" + expandedVm + "\". Please wait ...");
VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
for (ReconfigureStep actionStep : reconfigureSteps) {
actionStep.setVsphere(getVsphere());
actionStep.setVM(realVM);
actionStep.setVirtualMachineConfigSpec(spec);
actionStep.perform(run, null, launcher, listener);
}
vsphere.reconfigureVm(expandedVm, spec);
VSphereLogger.vsLogger(jLogger, "Finished!");
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class ReconfigureDisk method selectDatastore.
private String selectDatastore(int sizeInKB, PrintStream jLogger) throws Exception {
Datastore datastore = null;
long freeSpace = 0;
for (ManagedEntity entity : vsphere.getDatastores()) {
if (entity instanceof Datastore) {
Datastore ds = (Datastore) entity;
long fs = ds.getSummary().getFreeSpace();
if (this.datastore != null && this.datastore.length() > 0 && !ds.getName().equals(this.datastore)) {
continue;
}
if (fs > sizeInKB && fs > freeSpace) {
datastore = ds;
freeSpace = fs;
}
}
}
if (datastore == null) {
throw new VSphereException("No datastore with enough space found");
}
VSphereLogger.vsLogger(jLogger, String.format("Selected datastore `%s` with free size: %dGB", datastore.getName(), freeSpace / 1024 / 1024 / 1024));
return datastore.getName();
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class Rename method rename.
public boolean rename(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
String expandedOldName = oldName;
String expandedNewName = newName;
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());
expandedOldName = env.expand(oldName);
expandedNewName = env.expand(newName);
}
VSphereLogger.vsLogger(jLogger, "Renaming VM \"" + expandedOldName + ".\" to \"" + expandedNewName + "\" Please wait ...");
vsphere.renameVm(expandedOldName, expandedNewName);
VSphereLogger.vsLogger(jLogger, "Renamed!");
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class ReconfigureCpu method reconfigureCPU.
public boolean reconfigureCPU(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
String expandedCPUCores = cpuCores;
String expandedCoresPerSocket = coresPerSocket;
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());
expandedCPUCores = env.expand(cpuCores);
expandedCoresPerSocket = env.expand(coresPerSocket);
}
VSphereLogger.vsLogger(jLogger, "Preparing reconfigure: CPU");
spec.setNumCPUs(Integer.valueOf(expandedCPUCores));
spec.setNumCoresPerSocket(Integer.valueOf(expandedCoresPerSocket));
VSphereLogger.vsLogger(jLogger, "Finished!");
return true;
}
use of org.jenkinsci.plugins.vsphere.tools.VSphereException in project vsphere-cloud-plugin by jenkinsci.
the class ConvertToTemplate method convert.
private boolean convert(final Run<?, ?> run, final Launcher launcher, final TaskListener listener) throws VSphereException {
PrintStream jLogger = listener.getLogger();
VSphereLogger.vsLogger(jLogger, "Converting VM to template. Please wait ...");
String expandedVm = vm;
EnvVars env;
try {
env = run.getEnvironment(listener);
} catch (Exception e) {
throw new VSphereException(e);
}
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss aaa");
if (run instanceof AbstractBuild) {
// Add in matrix axes..
env.overrideAll(((AbstractBuild) run).getBuildVariables());
expandedVm = env.expand(vm);
}
vsphere.markAsTemplate(expandedVm, df.format(date), force);
VSphereLogger.vsLogger(jLogger, "\"" + expandedVm + "\" is now a template.");
return true;
}
Aggregations