clone is created and boots sucessfully. still no network on the clone though

This commit is contained in:
David Ribeiro Alves 2012-03-05 04:23:58 +00:00
parent 3a4cd0b4bc
commit 2e1f1e5da8
3 changed files with 16 additions and 14 deletions

View File

@ -121,14 +121,13 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements
progress.waitForCompletion(-1); progress.waitForCompletion(-1);
logger.debug("clone done"); logger.debug("clone done");
// registering // registering
manager.get().getVBox().registerMachine(clonedMachine); manager.get().getVBox().registerMachine(clonedMachine);
// Bridged# // Bridged#
for (NetworkInterfaceCard nic : cloneSpec.getNetworkSpec().getNetworkInterfaceCards()){ // for (NetworkInterfaceCard nic : cloneSpec.getNetworkSpec().getNetworkInterfaceCards()){
ensureBridgedNetworkingIsAppliedToMachine(clonedMachine.getName(), nic); // ensureBridgedNetworkingIsAppliedToMachine(clonedMachine.getName(), nic);
} // }
return clonedMachine; return clonedMachine;
} }

View File

@ -35,6 +35,7 @@ import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
import org.jclouds.virtualbox.domain.NetworkSpec; import org.jclouds.virtualbox.domain.NetworkSpec;
import org.jclouds.virtualbox.domain.NodeSpec; import org.jclouds.virtualbox.domain.NodeSpec;
import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.util.MachineUtils;
import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.ISession; import org.virtualbox_4_1.ISession;
@ -49,11 +50,13 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
private final Supplier<VirtualBoxManager> manager; private final Supplier<VirtualBoxManager> manager;
private final Function<CloneSpec, IMachine> cloner; private final Function<CloneSpec, IMachine> cloner;
private MachineUtils machineUtils;
@Inject @Inject
public NodeCreator(Supplier<VirtualBoxManager> manager, Function<CloneSpec, IMachine> cloner) { public NodeCreator(Supplier<VirtualBoxManager> manager, Function<CloneSpec, IMachine> cloner, MachineUtils machineUtils) {
this.manager = manager; this.manager = manager;
this.cloner = cloner; this.cloner = cloner;
this.machineUtils = machineUtils;
} }
@Override @Override
@ -79,19 +82,21 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full) VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
.forceOverwrite(true).build(); .forceOverwrite(true).build();
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged) NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT)
.build(); .tcpRedirectRule("127.0.0.1", 2222, "", 22).build();
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
.build(); .build();
NetworkSpec cloneNetworkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build(); NetworkSpec networkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build();
CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()) CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()).network(networkSpec)
.network(cloneNetworkSpec).vm(cloneVmSpec).build(); .vm(cloneVmSpec).build();
IMachine cloned = cloner.apply(cloneSpec); IMachine cloned = cloner.apply(cloneSpec);
new AttachNicToMachine(cloneName, machineUtils).apply(networkInterfaceCard);
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(cloned); new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(cloned);
// TODO get credentials from somewhere else (they are also HC in IMachineToSshClient) // TODO get credentials from somewhere else (they are also HC in IMachineToSshClient)

View File

@ -26,12 +26,10 @@ import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.functions.IMachineToSshClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
@ -71,7 +69,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
} }
protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) {
SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds); SshClient ssh = context.utils().injector().getInstance(IMachineToSshClient.class).apply(machine);
try { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");