示例#1
0
  /* (non-Javadoc)
   * @see hudson.tasks.BuildWrapper#setUp(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener)
   */
  private boolean markVm(
      final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
      throws VSphereException {
    PrintStream jLogger = listener.getLogger();
    VSphereLogger.vsLogger(jLogger, "Converting template to VM. Please wait ...");

    EnvVars env;
    try {
      env = build.getEnvironment(listener);
    } catch (Exception e) {
      throw new VSphereException(e);
    }

    // TODO:  take in a comma delimited list and convert all
    env.overrideAll(build.getBuildVariables()); // Add in matrix axes..
    String expandedTemplate = env.expand(template);

    VirtualMachine vm = vsphere.markAsVm(expandedTemplate);
    VSphereLogger.vsLogger(jLogger, "\"" + expandedTemplate + "\" is a VM!");

    if (powerOn) {
      vsphere.startVm(expandedTemplate);
      String vmIP = vsphere.getIp(vm);
      if (vmIP != null) {
        VSphereLogger.vsLogger(jLogger, "Got IP for \"" + expandedTemplate + "\" ");
        VSphereEnvAction envAction = new VSphereEnvAction();
        envAction.add("VSPHERE_IP", vmIP);
        build.addAction(envAction);
        return true;
      }

      VSphereLogger.vsLogger(jLogger, "Error: Could not get IP for \"" + expandedTemplate + "\" ");
      return false;
    }

    return true;
  }
示例#2
0
  @Override
  public boolean perform(
      final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) {

    PrintStream jLogger = listener.getLogger();
    VSphereLogger.vsLogger(jLogger, "Attempting to use server configuration: " + serverName);
    boolean changed = false;

    try {
      Server server = VSpherePlugin.DescriptorImpl.get().getServer(serverName);
      // Need to ensure this server still exists.  If it's deleted
      // and a job is not opened, it will still try to connect
      VSpherePlugin.DescriptorImpl.get().checkServerExistence(server);

      vsphere = VSphere.connect(server);
      changed = markVm(build, launcher, listener);

    } catch (VSphereException e) {
      VSphereLogger.vsLogger(jLogger, e.getMessage());
      e.printStackTrace(jLogger);
    }

    return changed;
  }
示例#3
0
 /** This human readable name is used in the configuration screen. */
 @Override
 public String getDisplayName() {
   return VSphere.vSphereOutput(Messages.vm_title_MarkVM());
 }