Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2015-10-20 14:47:31 -0400
committerRoland Grunberg2015-10-21 15:15:16 -0400
commit22bfdcf7e3fd7fffe924bbf536a426f1e52d318f (patch)
tree6b223d69a16baf5ecbe7c63c7715a6a7e8ce77a4
parente679ecaae339d3e8180c715fc5dd6e482456fcfc (diff)
downloadorg.eclipse.linuxtools-22bfdcf7e3fd7fffe924bbf536a426f1e52d318f.tar.gz
org.eclipse.linuxtools-22bfdcf7e3fd7fffe924bbf536a426f1e52d318f.tar.xz
org.eclipse.linuxtools-22bfdcf7e3fd7fffe924bbf536a426f1e52d318f.zip
Add functionality to start existing VMs.
Change-Id: Iaf2564a5a53676ba414a211fe5a0566aca462718 Reviewed-on: https://git.eclipse.org/r/58657 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/plugin.xml45
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/BaseVMCommandHandler.java4
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/DestroyVMCommandHandler.java3
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/SSHVMCommandHandler.java3
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StartVMCommandHandler.java64
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StopVMCommandHandler.java3
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/views/DVMessages.properties5
7 files changed, 121 insertions, 6 deletions
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/plugin.xml b/vagrant/org.eclipse.linuxtools.vagrant.ui/plugin.xml
index 69bed59972..eba325d890 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/plugin.xml
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/plugin.xml
@@ -97,6 +97,11 @@
id="org.eclipse.linuxtools.vagrant.ui.commands.createVM"
name="Create VM">
</command>
+ <command
+ description="Start selected VMs"
+ id="org.eclipse.linuxtools.vagrant.ui.commands.startVM"
+ name="Start VMs">
+ </command>
</extension>
<extension
point="org.eclipse.ui.handlers">
@@ -215,6 +220,35 @@
</with>
</enabledWhen>
</handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.vagrant.ui.commands.StartVMCommandHandler"
+ commandId="org.eclipse.linuxtools.vagrant.ui.commands.startVM">
+ <enabledWhen>
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false">
+ <and>
+ <instanceof
+ value="org.eclipse.linuxtools.vagrant.core.IVagrantVM">
+ </instanceof>
+ <or>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.linuxtools.vagrant.propertytesters.vm.isShutoff"
+ value="true">
+ </test>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.linuxtools.vagrant.propertytesters.vm.isUnknown"
+ value="true">
+ </test>
+ </or>
+ </and>
+ </iterate>
+ </with>
+ </enabledWhen>
+ </handler>
</extension>
<extension
point="org.eclipse.ui.menus">
@@ -302,6 +336,17 @@
style="push">
</command>
</menuContribution>
+ <menuContribution
+ locationURI="toolbar:org.eclipse.linuxtools.vagrant.ui.vagrantVMView">
+ <command
+ commandId="org.eclipse.linuxtools.vagrant.ui.commands.startVM"
+ disabledIcon="icons/runningd.gif"
+ icon="icons/running.gif"
+ id="org.eclipse.linuxtools.vagrant.ui.commands.startVM"
+ mnemonic="S"
+ style="push">
+ </command>
+ </menuContribution>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/BaseVMCommandHandler.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/BaseVMCommandHandler.java
index 100913c778..bf7e08359b 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/BaseVMCommandHandler.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/BaseVMCommandHandler.java
@@ -40,7 +40,7 @@ public abstract class BaseVMCommandHandler extends AbstractHandler {
selectedContainers.size());
for (final IVagrantVM container : selectedContainers) {
monitor.setTaskName(getTaskName(container));
- executeInJob(container);
+ executeInJob(container, monitor);
monitor.worked(1);
}
}
@@ -74,5 +74,5 @@ public abstract class BaseVMCommandHandler extends AbstractHandler {
abstract String getTaskName(final IVagrantVM container);
- abstract void executeInJob(final IVagrantVM container);
+ abstract void executeInJob(final IVagrantVM container, IProgressMonitor monitor);
}
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/DestroyVMCommandHandler.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/DestroyVMCommandHandler.java
index 252e61c0a7..c51a41a2fd 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/DestroyVMCommandHandler.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/DestroyVMCommandHandler.java
@@ -14,6 +14,7 @@ import java.io.File;
import java.nio.file.Paths;
import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.linuxtools.internal.vagrant.core.Activator;
import org.eclipse.linuxtools.internal.vagrant.core.VagrantConnection;
import org.eclipse.linuxtools.vagrant.core.IVagrantConnection;
@@ -33,7 +34,7 @@ public class DestroyVMCommandHandler extends BaseVMCommandHandler {
}
@Override
- void executeInJob(IVagrantVM vm) {
+ void executeInJob(IVagrantVM vm, IProgressMonitor monitor) {
IVagrantConnection connection = VagrantConnection.getInstance();
try {
connection.destroyVM(vm.id());
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/SSHVMCommandHandler.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/SSHVMCommandHandler.java
index 4879308a16..c059491847 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/SSHVMCommandHandler.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/SSHVMCommandHandler.java
@@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.linuxtools.internal.vagrant.core.VagrantConnection;
@@ -23,7 +24,7 @@ import org.eclipse.tm.terminal.connector.ssh.launcher.SshLauncherDelegate;
public class SSHVMCommandHandler extends BaseVMCommandHandler {
@Override
- void executeInJob(final IVagrantVM vm) {
+ void executeInJob(final IVagrantVM vm, IProgressMonitor monitor) {
// org.eclipse.tm.terminal.connector.ssh.controls.SshWizardConfigurationPanel
Map<String, Object> properties = new HashMap<>();
properties.put("ssh.keep_alive", 300);
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StartVMCommandHandler.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StartVMCommandHandler.java
new file mode 100644
index 0000000000..90a40f8614
--- /dev/null
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StartVMCommandHandler.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.vagrant.ui.commands;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.linuxtools.internal.vagrant.core.Activator;
+import org.eclipse.linuxtools.internal.vagrant.core.VagrantConnection;
+import org.eclipse.linuxtools.internal.vagrant.ui.views.DVMessages;
+import org.eclipse.linuxtools.vagrant.core.IVagrantConnection;
+import org.eclipse.linuxtools.vagrant.core.IVagrantVM;
+
+public class StartVMCommandHandler extends BaseVMCommandHandler {
+
+ private static final String START_VM_MSG = "StartVM.msg"; //$NON-NLS-1$
+ private static final String START_VM_TITLE = "StartVM.title"; //$NON-NLS-1$
+
+ @Override
+ String getJobName(List<IVagrantVM> selectedvms) {
+ return DVMessages.getFormattedString(START_VM_MSG);
+ }
+
+ @Override
+ String getTaskName(IVagrantVM vm) {
+ return DVMessages.getFormattedString(START_VM_TITLE, vm.name());
+ }
+
+ @Override
+ void executeInJob(IVagrantVM vm, IProgressMonitor monitor) {
+ IVagrantConnection connection = VagrantConnection.getInstance();
+ String stateLoc = Activator.getDefault().getStateLocation().toOSString();
+ File vagrantDir = Paths.get(stateLoc, vm.name()).toFile();
+ Process p = connection.up(vagrantDir);
+ BufferedReader buff = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line;
+ try {
+ while ((line = buff.readLine()) != null) {
+ if (monitor.isCanceled()) {
+ p.destroy();
+ break;
+ }
+ line = line.replaceAll("(=)+>", "");
+ monitor.subTask(line);
+ }
+ } catch (IOException e) {
+ }
+ connection.getVMs(true);
+ }
+
+}
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StopVMCommandHandler.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StopVMCommandHandler.java
index 94dca769c9..28488df139 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StopVMCommandHandler.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/StopVMCommandHandler.java
@@ -12,6 +12,7 @@ package org.eclipse.linuxtools.internal.vagrant.ui.commands;
import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.linuxtools.internal.vagrant.core.VagrantConnection;
import org.eclipse.linuxtools.internal.vagrant.ui.views.DVMessages;
import org.eclipse.linuxtools.vagrant.core.IVagrantConnection;
@@ -25,7 +26,7 @@ public class StopVMCommandHandler extends BaseVMCommandHandler {
private static final String CONTAINER_STOP_ERROR_MSG = "ContainerStopError.msg"; //$NON-NLS-1$
@Override
- void executeInJob(final IVagrantVM vm) {
+ void executeInJob(final IVagrantVM vm, IProgressMonitor monitor) {
IVagrantConnection connection = VagrantConnection.getInstance();
try {
connection.haltVM(vm.id());
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/views/DVMessages.properties b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/views/DVMessages.properties
index 4c60e5b320..75d9eaf294 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/views/DVMessages.properties
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/views/DVMessages.properties
@@ -31,5 +31,8 @@ ImagePull.msg=Adding Box
ImagePull.title=Adding {0}
ImagePullError.msg=Error adding box <{0}>
-CreateVM.msg=Creating VM ...
+CreateVM.msg=Creating VMs ...
CreateVM.title=Creating VM {0}
+
+StartVM.msg=Starting VMs ...
+StartVM.title=Starting VM {0}

Back to the top