stuck on adapter problems

This commit is contained in:
David Ribeiro Alves 2012-03-05 02:28:00 +00:00
parent d0b4d81f9f
commit 3a4cd0b4bc
10 changed files with 180 additions and 148 deletions

View File

@ -62,6 +62,7 @@ import org.jclouds.virtualbox.domain.ExecutionType;
import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.IsoSpec;
import org.jclouds.virtualbox.domain.Master; import org.jclouds.virtualbox.domain.Master;
import org.jclouds.virtualbox.domain.MasterSpec; import org.jclouds.virtualbox.domain.MasterSpec;
import org.jclouds.virtualbox.domain.NodeSpec;
import org.jclouds.virtualbox.domain.YamlImage; import org.jclouds.virtualbox.domain.YamlImage;
import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists; import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists;
import org.jclouds.virtualbox.functions.CreateAndInstallVm; import org.jclouds.virtualbox.functions.CreateAndInstallVm;
@ -140,7 +141,7 @@ public class VirtualBoxComputeServiceContextModule extends
bind(new TypeLiteral<Function<MasterSpec, IMachine>>() { bind(new TypeLiteral<Function<MasterSpec, IMachine>>() {
}).to((Class) CreateAndInstallVm.class); }).to((Class) CreateAndInstallVm.class);
// the machine cloning function // the machine cloning function
bind(new TypeLiteral<Function<IMachine, NodeAndInitialCredentials<IMachine>>>() { bind(new TypeLiteral<Function<NodeSpec, NodeAndInitialCredentials<IMachine>>>() {
}).to((Class) NodeCreator.class); }).to((Class) NodeCreator.class);
bind(new TypeLiteral<Function<CloneSpec, IMachine>>() { bind(new TypeLiteral<Function<CloneSpec, IMachine>>() {
}).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class); }).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class);

View File

@ -64,7 +64,7 @@ public class VmSpec {
private String name; private String name;
private String id; private String id;
private String osTypeId = ""; private String osTypeId = "";
private boolean forceOverwrite; private boolean forceOverwrite = true;
private long memory; private long memory;
private CleanupMode cleanUpMode; private CleanupMode cleanUpMode;

View File

@ -118,8 +118,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements
IProgress progress = currentSnapshot.getMachine().cloneTo( IProgress progress = currentSnapshot.getMachine().cloneTo(
clonedMachine, CloneMode.MachineState, options); clonedMachine, CloneMode.MachineState, options);
if (progress.getCompleted()) progress.waitForCompletion(-1);
logger.debug("clone done"); logger.debug("clone done");
// registering // registering

View File

@ -19,7 +19,6 @@
package org.jclouds.virtualbox.functions; package org.jclouds.virtualbox.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -32,9 +31,6 @@ import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INetworkAdapter; import org.virtualbox_4_1.INetworkAdapter;
import org.virtualbox_4_1.ISystemProperties;
import org.virtualbox_4_1.VirtualBoxManager;
import org.virtualbox_4_1.jaxws.ISystemPropertiesGetMaxNetworkAdapters;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -69,7 +65,6 @@ public class IMachineToSshClient implements Function<IMachine, SshClient> {
String targetPort = Iterables.get(stuff, 5); String targetPort = Iterables.get(stuff, 5);
// TODO: we need a way to align the default login credentials from the iso with the // TODO: we need a way to align the default login credentials from the iso with the
// vmspec // vmspec
logger.warn("PROTOCOLNUMBER: "+nameProtocolnumberAddressInboudportGuestTargetport);
if ("1".equals(protocolNumber) && "22".equals(targetPort)) { if ("1".equals(protocolNumber) && "22".equals(targetPort)) {
client = sshClientFactory.create(new IPSocket(hostAddress, Integer.parseInt(inboundPort)), client = sshClientFactory.create(new IPSocket(hostAddress, Integer.parseInt(inboundPort)),
LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build()); LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build());

View File

@ -151,12 +151,15 @@ public class MastersCache extends AbstractLoadingCache<Image, Master> {
// try and find a master machine in vbox // try and find a master machine in vbox
try { try {
masterMachine = manager.get().getVBox().findMachine(masterSpec.getVmSpec().getVmId()); masterMachine = manager.get().getVBox().findMachine(vmName);
} catch (VBoxException e) { } catch (VBoxException e) {
if (machineNotFoundException(e)) if (machineNotFoundException(e)) {
// create the master machine if it can't be found
masterMachine = masterCreatorAndInstaller.apply(masterSpec); masterMachine = masterCreatorAndInstaller.apply(masterSpec);
else }
else {
throw e; throw e;
}
} }
Master master = Master.builder().machine(masterMachine).spec(masterSpec).build(); Master master = Master.builder().machine(masterMachine).spec(masterSpec).build();

View File

@ -19,19 +19,32 @@
package org.jclouds.virtualbox.functions; package org.jclouds.virtualbox.functions;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.virtualbox.domain.CloneSpec; import org.jclouds.virtualbox.domain.CloneSpec;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.jclouds.virtualbox.domain.Master; import org.jclouds.virtualbox.domain.Master;
import org.jclouds.virtualbox.domain.NetworkAdapter;
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
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.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;
import org.virtualbox_4_1.NetworkAttachmentType;
import org.virtualbox_4_1.VirtualBoxManager; import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@Singleton
public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials<IMachine>> { public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials<IMachine>> {
private final Supplier<VirtualBoxManager> manager; private final Supplier<VirtualBoxManager> manager;
@ -45,16 +58,46 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
@Override @Override
public NodeAndInitialCredentials<IMachine> apply(NodeSpec nodeSpec) { public NodeAndInitialCredentials<IMachine> apply(NodeSpec nodeSpec) {
Master master = nodeSpec.getMaster(); Master master = nodeSpec.getMaster();
if (master.getMachine().getCurrentSnapshot() != null) { if (master.getMachine().getCurrentSnapshot() != null) {
ISession session = manager.get().openMachineSession(master.getMachine()); ISession session;
try {
session = manager.get().openMachineSession(master.getMachine());
} catch (Exception e) {
throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e);
}
session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId()); session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
session.unlockMachine(); session.unlockMachine();
} }
String masterNameWithoutPrefix = master.getSpec().getVmSpec().getVmName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + "-" + nodeSpec.getTag() + "-"
+ nodeSpec.getName();
VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
.forceOverwrite(true).build();
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged)
.build();
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
.build();
NetworkSpec cloneNetworkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build();
CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine())
.network(cloneNetworkSpec).vm(cloneVmSpec).build();
IMachine cloned = cloner.apply(cloneSpec);
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(cloned);
// TODO get credentials from somewhere else (they are also HC in IMachineToSshClient)
NodeAndInitialCredentials<IMachine> nodeAndInitialCredentials = new NodeAndInitialCredentials<IMachine>(cloned,
cloneName, LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build());
return nodeAndInitialCredentials;
} }
} }

View File

@ -31,7 +31,9 @@ import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
@ -82,6 +84,8 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
protected String workingDir; protected String workingDir;
protected String isosDir; protected String isosDir;
protected Supplier<NodeMetadata> host; protected Supplier<NodeMetadata> host;
protected static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate(
new DefaultCredentialsFromImageOrOverridingCredentials());
@Override @Override
protected void setupCredentials() { protected void setupCredentials() {

View File

@ -19,6 +19,7 @@
package org.jclouds.virtualbox.compute; package org.jclouds.virtualbox.compute;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
@ -31,85 +32,78 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket; 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.domain.VmSpec;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
private VirtualBoxComputeServiceAdapter adapter; private VirtualBoxComputeServiceAdapter adapter;
private NodeAndInitialCredentials<IMachine> machine; private NodeAndInitialCredentials<IMachine> machine;
@Override @Override
public void setupClient() { public void setupClient() {
super.setupClient(); super.setupClient();
adapter = context.utils().injector().getInstance(VirtualBoxComputeServiceAdapter.class); adapter = context.utils().injector().getInstance(VirtualBoxComputeServiceAdapter.class);
} }
private static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate( @Test
new DefaultCredentialsFromImageOrOverridingCredentials()); public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() {
String group = "foo";
String name = "foo-ef4";
String machineName = VIRTUALBOX_NODE_PREFIX + "myTestId-" + group + "-" + name;
// get the image from
Image image = Iterables.get(adapter.listImages(), 0);
System.out.println(context.getComputeService().templateBuilder());
Template template = context.getComputeService().templateBuilder().fromImage(image).build();
machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
assertEquals(machine.getNode().getName(), machineName);
// is there a place for group?
// check other things, like cpu correct, mem correct, image/os is correct
// (as possible)
// TODO: what's the IP address?
// assert
// InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) :
// machine;
doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials()));
}
@Test protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) {
public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds);
String group = "foo"; try {
String name = "foo-ef4"; ssh.connect();
// get the image from ExecResponse hello = ssh.exec("echo hello");
Image image = Iterables.get(adapter.listImages(),0); assertEquals(hello.getOutput().trim(), "hello");
System.out.println(context.getComputeService().templateBuilder()); System.err.println(ssh.exec("df -k").getOutput());
Template template = context.getComputeService().templateBuilder().fromImage(image).build(); System.err.println(ssh.exec("mount").getOutput());
machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template); System.err.println(ssh.exec("uname -a").getOutput());
assertEquals(machine.getNode().getName(), name); } finally {
assertEquals(machine.getNodeId(), machine.getNode().getId()); if (ssh != null)
// is there a place for group? ssh.disconnect();
// check other things, like cpu correct, mem correct, image/os is correct }
// (as possible) }
// TODO: what's the IP address?
// assert
// InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) :
// machine;
doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials()));
} @Test
public void testListHardwareProfiles() {
Iterable<IMachine> profiles = adapter.listHardwareProfiles();
assertEquals(1, Iterables.size(profiles));
}
protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { @Test
SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds); public void testListImages() {
try { Iterable<Image> iMageIterable = adapter.listImages();
ssh.connect(); for (Image image : iMageIterable) {
ExecResponse hello = ssh.exec("echo hello"); System.out.println(image);
assertEquals(hello.getOutput().trim(), "hello"); }
System.err.println(ssh.exec("df -k").getOutput()); // check state;
System.err.println(ssh.exec("mount").getOutput()); }
System.err.println(ssh.exec("uname -a").getOutput());
} finally {
if (ssh != null)
ssh.disconnect();
}
}
@Test @Override
public void testListHardwareProfiles() { protected void tearDown() throws Exception {
Iterable<IMachine> profiles = adapter.listHardwareProfiles(); if (machine != null)
assertEquals(1,Iterables.size(profiles)); // adapter.destroyNode(machine.getNodeId() + "");
} super.tearDown();
}
@Test
public void testListImages() {
Iterable<Image> iMageIterable = adapter.listImages();
for (Image image : iMageIterable) {
System.out.println(image);
}
// check state;
}
@Override
protected void tearDown() throws Exception {
if (machine != null)
adapter.destroyNode(machine.getNodeId() + "");
super.tearDown();
}
} }

View File

@ -26,6 +26,7 @@ import static org.testng.Assert.assertEquals;
import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.CloneSpec; import org.jclouds.virtualbox.domain.CloneSpec;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.IsoSpec;
import org.jclouds.virtualbox.domain.MasterSpec; import org.jclouds.virtualbox.domain.MasterSpec;
@ -139,6 +140,11 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
manager, workingDir,machineUtils).apply(cloneSpec); manager, workingDir,machineUtils).apply(cloneSpec);
assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName()); assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName());
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(clone);
// TODO ssh into the node
} finally { } finally {
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(),
sourceMachineSpec.getVmSpec())) sourceMachineSpec.getVmSpec()))

View File

@ -55,78 +55,64 @@ import com.google.inject.Injector;
@Test(groups = "live", singleThreaded = true, testName = "IMachinePredicatesLiveTest") @Test(groups = "live", singleThreaded = true, testName = "IMachinePredicatesLiveTest")
public class IMachinePredicatesLiveTest extends BaseVirtualBoxClientLiveTest { public class IMachinePredicatesLiveTest extends BaseVirtualBoxClientLiveTest {
private String osTypeId = ""; private String osTypeId = "";
private String ideControllerName = "IDE Controller"; private String ideControllerName = "IDE Controller";
private String cloneName; private String cloneName;
private String vmName; private String vmName;
private StorageController masterStorageController; private StorageController masterStorageController;
private MasterSpec masterMachineSpec; private MasterSpec masterMachineSpec;
private CloneSpec cloneSpec; private NetworkSpec networkSpec;
private CloneSpec cloneSpec;
@Override @Override
@BeforeClass(groups = "live") @BeforeClass(groups = "live")
public void setupClient() { public void setupClient() {
super.setupClient(); super.setupClient();
vmName = VIRTUALBOX_IMAGE_PREFIX vmName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass()
.getSimpleName());
cloneName = VIRTUALBOX_IMAGE_PREFIX cloneName = VIRTUALBOX_IMAGE_PREFIX + "Clone#"
+ "Clone#" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass()
.getSimpleName());
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk) HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1).build();
.autoDelete(true).controllerPort(0).deviceSlot(1).build(); masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
masterStorageController = StorageController.builder() .attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
.name(ideControllerName).bus(StorageBus.IDE) VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).osTypeId(osTypeId)
.attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk) .controller(masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
.attachISO(1, 1, guestAdditionsIso).build(); masterMachineSpec = MasterSpec.builder()
VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName) .iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(masterSpec)
.memoryMB(512).osTypeId(osTypeId) .network(NetworkSpec.builder().build()).build();
.controller(masterStorageController).forceOverwrite(true)
.cleanUpMode(CleanupMode.Full).build();
masterMachineSpec = MasterSpec
.builder()
.iso(IsoSpec.builder().sourcePath(operatingSystemIso)
.installationScript("").build()).vm(masterSpec)
.network(NetworkSpec.builder().build()).build();
NetworkAdapter networkAdapter = NetworkAdapter.builder() NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged)
.networkAttachmentType(NetworkAttachmentType.Bridged).build(); .build();
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
.builder().addNetworkAdapter(networkAdapter).build(); .build();
NetworkSpec networkSpec = NetworkSpec.builder() this.networkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build();
.addNIC(0L, networkInterfaceCard).build();
VmSpec clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName) }
.memoryMB(512).cleanUpMode(CleanupMode.Full)
.forceOverwrite(true).build();
cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(networkSpec) @Test
.build(); public void testLinkedClone() {
}
@Test Injector injector = context.utils().injector();
public void testLinkedClone() { IMachine master = injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
masterMachineSpec);
Injector injector = context.utils().injector(); VmSpec clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
IMachine master = injector.getInstance( .forceOverwrite(true).build();
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
masterMachineSpec);
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
manager, workingDir, cloneSpec, true, machineUtils)
.apply(master);
assertTrue(isLinkedClone().apply(clone)); this.cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(networkSpec).master(master).linked(true).build();
}
@BeforeMethod IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
@AfterMethod .apply(cloneSpec);
void cleanUpVms() {
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), assertTrue(isLinkedClone().apply(clone));
masterMachineSpec.getVmSpec())) }
this.undoVm(spec);
} @BeforeMethod
@AfterMethod
void cleanUpVms() {
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), masterMachineSpec.getVmSpec()))
this.undoVm(spec);
}
} }