Search in sources :

Example 6 with IVagrantConnection

use of org.eclipse.linuxtools.vagrant.core.IVagrantConnection in project linuxtools by eclipse.

the class DestroyVMCommandHandler method executeInJob.

@Override
void executeInJob(IVagrantVM vm, IProgressMonitor monitor) {
    IVagrantConnection connection = VagrantService.getInstance();
    try {
        connection.destroyVM(vm);
        String stateLoc = Activator.getDefault().getStateLocation().toOSString();
        File vagrantDir = Paths.get(stateLoc, vm.name()).toFile();
        CommandUtils.delete(vagrantDir);
    } catch (VagrantException | InterruptedException e) {
        final String errorMessage = Messages.DestroyVMCommandHandler_error + vm.id();
        openError(errorMessage, e);
    } finally {
        // always get images as we sometimes get errors on intermediate
        // images
        // being removed but we will remove some top ones successfully
        connection.getVMs(true);
    }
}
Also used : VagrantException(org.eclipse.linuxtools.vagrant.core.VagrantException) IVagrantConnection(org.eclipse.linuxtools.vagrant.core.IVagrantConnection) File(java.io.File)

Example 7 with IVagrantConnection

use of org.eclipse.linuxtools.vagrant.core.IVagrantConnection in project linuxtools by eclipse.

the class RefreshVMCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IVagrantConnection connection = VagrantService.getInstance();
    if (connection == null) {
        return null;
    }
    final Job job = new Job(DVMessages.getString(VM_REFRESH_MSG)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(VM_REFRESH_MSG), 1);
            connection.getVMs(true);
            monitor.worked(1);
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setPriority(Job.LONG);
    job.schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IVagrantConnection(org.eclipse.linuxtools.vagrant.core.IVagrantConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 8 with IVagrantConnection

use of org.eclipse.linuxtools.vagrant.core.IVagrantConnection in project linuxtools by eclipse.

the class VagrantVMContentProvider method getElements.

@Override
public Object[] getElements(final Object inputElement) {
    if (inputElement instanceof IVagrantConnection) {
        final IVagrantConnection connection = (IVagrantConnection) inputElement;
        if (connection.isVMsLoaded()) {
            return connection.getVMs().toArray();
        }
        loadContainers(connection);
        return EMPTY;
    }
    return EMPTY;
}
Also used : IVagrantConnection(org.eclipse.linuxtools.vagrant.core.IVagrantConnection)

Example 9 with IVagrantConnection

use of org.eclipse.linuxtools.vagrant.core.IVagrantConnection in project linuxtools by eclipse.

the class AddBoxCommandHandler method performPullImage.

private void performPullImage(final String boxName, final String boxLoc) {
    final Job pullImageJob = new Job(DVMessages.getFormattedString(PULL_IMAGE_JOB_TITLE, boxName)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(PULL_IMAGE_JOB_TASK), IProgressMonitor.UNKNOWN);
            // handler refresh the images when done
            try {
                IVagrantConnection connection = VagrantService.getInstance();
                boolean isValidURL = true;
                try {
                    new URL(boxLoc);
                } catch (MalformedURLException e) {
                    isValidURL = false;
                }
                connection.addBox(boxName, boxLoc, isValidURL);
                connection.getBoxes(true);
            } catch (final VagrantException e) {
                Display.getDefault().syncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), DVMessages.getFormattedString(ERROR_PULLING_IMAGE, boxName), e.getMessage()));
            // for now
            } catch (InterruptedException e) {
            // do nothing
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    pullImageJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MalformedURLException(java.net.MalformedURLException) VagrantException(org.eclipse.linuxtools.vagrant.core.VagrantException) IVagrantConnection(org.eclipse.linuxtools.vagrant.core.IVagrantConnection) Job(org.eclipse.core.runtime.jobs.Job) URL(java.net.URL)

Aggregations

IVagrantConnection (org.eclipse.linuxtools.vagrant.core.IVagrantConnection)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 Job (org.eclipse.core.runtime.jobs.Job)5 VagrantException (org.eclipse.linuxtools.vagrant.core.VagrantException)4 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 IVagrantBox (org.eclipse.linuxtools.vagrant.core.IVagrantBox)1