Search in sources :

Example 1 with VSphereException

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;
}
Also used : PrintStream(java.io.PrintStream) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) IOException(java.io.IOException) VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Example 2 with VSphereException

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();
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) Datastore(com.vmware.vim25.mo.Datastore) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException)

Example 3 with VSphereException

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;
}
Also used : PrintStream(java.io.PrintStream) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) IOException(java.io.IOException)

Example 4 with VSphereException

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;
}
Also used : PrintStream(java.io.PrintStream) AbstractBuild(hudson.model.AbstractBuild) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) ServletException(javax.servlet.ServletException) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) IOException(java.io.IOException)

Example 5 with VSphereException

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;
}
Also used : PrintStream(java.io.PrintStream) AbstractBuild(hudson.model.AbstractBuild) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) SimpleDateFormat(java.text.SimpleDateFormat) VSphereException(org.jenkinsci.plugins.vsphere.tools.VSphereException) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

VSphereException (org.jenkinsci.plugins.vsphere.tools.VSphereException)22 IOException (java.io.IOException)19 PrintStream (java.io.PrintStream)18 AbstractBuild (hudson.model.AbstractBuild)7 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)4 ServletException (javax.servlet.ServletException)4 OptionValue (com.vmware.vim25.OptionValue)1 VirtualMachineConfigInfo (com.vmware.vim25.VirtualMachineConfigInfo)1 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)1 Datastore (com.vmware.vim25.mo.Datastore)1 DistributedVirtualPortgroup (com.vmware.vim25.mo.DistributedVirtualPortgroup)1 DistributedVirtualSwitch (com.vmware.vim25.mo.DistributedVirtualSwitch)1 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)1 Network (com.vmware.vim25.mo.Network)1 Task (com.vmware.vim25.mo.Task)1 FormException (hudson.model.Descriptor.FormException)1 ComputerLauncher (hudson.slaves.ComputerLauncher)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1