/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ * Copyright (C) 2007-2012 Argeo GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.argeo.slc.lib.vbox;
import java.io.IOException;
startVm("gui");
}
+ public void startVmHeadless() {
+ startVm("vrdp");
+ }
+
public void startVm(String type) {
List<Object> cmd = new ArrayList<Object>();
cmd.add(executable);
for (VBoxNat vBoxNat : nats) {
for (String id : vBoxNat.getMappings().keySet()) {
VBoxPortMapping mapping = vBoxNat.getMappings().get(id);
- new SystemCall(createNatCommand(id, vBoxNat.getDevice(),
- "Protocol", mapping.getProtocol(), script)).run();
- script.append('\n');
- new SystemCall(createNatCommand(id, vBoxNat.getDevice(),
- "GuestPort", mapping.getGuest(), script)).run();
- script.append('\n');
- new SystemCall(createNatCommand(id, vBoxNat.getDevice(),
- "HostPort", mapping.getHost(), script)).run();
- script.append('\n');
- script.append('\n');
+
+ // Try to delete rule first
+ try {
+ StringBuffer delCmd = new StringBuffer(
+ "VBoxManage modifyvm");
+ delCmd.append(" \"").append(vm.getName()).append("\"");
+ delCmd.append(" --natpf").append(vBoxNat.getDevice())
+ .append(" ");
+ delCmd.append(" delete ");
+ delCmd.append("\"").append(id).append("\"");
+ new SystemCall(delCmd.toString()).run();
+ script.append(delCmd).append("\n");
+ } catch (Exception e) {
+ // silent
+ }
+
+ StringBuffer cmd = new StringBuffer("VBoxManage modifyvm");
+ cmd.append(" \"").append(vm.getName()).append("\"");
+ cmd.append(" --natpf").append(vBoxNat.getDevice()).append(" ");
+ cmd.append("\"");
+ cmd.append(id).append(",");
+ cmd.append(mapping.getProtocol()).append(",");
+ cmd.append(",");
+ cmd.append(mapping.getHostPort()).append(",");
+ cmd.append(vBoxNat.getGuestIp()).append(",");
+ cmd.append(mapping.getGuestPort());
+ cmd.append("\"");
+
+ new SystemCall(cmd.toString()).run();
+ script.append(cmd).append("\n");
+
+ // Older VirtualBox
+ // new SystemCall(createNatCommand(id, vBoxNat.getDevice(),
+ // "Protocol", mapping.getProtocol(), script)).run();
+ // script.append('\n');
+ // new SystemCall(createNatCommand(id, vBoxNat.getDevice(),
+ // "GuestPort", mapping.getGuest(), script)).run();
+ // script.append('\n');
+ // new SystemCall(createNatCommand(id, vBoxNat.getDevice(),
+ // "HostPort", mapping.getHost(), script)).run();
+ // script.append('\n');
+ // script.append('\n');
}
script.append('\n');
}