@Override
public IMachine apply(MasterSpec masterSpec) {
VmSpec vmSpec = masterSpec.getVmSpec();
IsoSpec isoSpec = masterSpec.getIsoSpec();
String masterName = vmSpec.getVmName();
IMachine masterMachine =
checkNotNull(createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(masterSpec), "master machine");
// Launch machine and wait for it to come online
machineController.ensureMachineIsLaunched(masterName);
String installationKeySequence = isoSpec.getInstallationKeySequence().replace("PRECONFIGURATION_URL",
preconfigurationUrl);
configureOsInstallationWithKeyboardSequence(masterName, installationKeySequence);
masterMachine.setExtraData(GUEST_OS_USER, masterSpec.getLoginCredentials().getUser());
masterMachine.setExtraData(GUEST_OS_PASSWORD, masterSpec.getLoginCredentials().getPassword());
SshClient client = sshClientForIMachine.apply(masterMachine);
logger.debug(">> awaiting installation to finish node(%s)", masterName);
Stopwatch stopwatch = new Stopwatch();
stopwatch.start();
checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", masterName);
stopwatch.stop();
logger.debug(String.format("Elapsed time for the OS installation: %d minutes", TimeUnit.SECONDS.convert(stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)));
NodeMetadata nodeMetadata = imachineToNodeMetadata.apply(masterMachine);
logger.debug(">> awaiting post-installation actions on vm: %s", masterName);
ListenableFuture<ExecResponse> execCleanup = machineUtils.runScriptOnNode(nodeMetadata,
call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
ExecResponse cleanupResponse = Futures.getUnchecked(execCleanup);
checkState(cleanupResponse.getExitStatus() == 0, "post-installation actions on vm(%s) failed", masterName);
logger.debug(">> awaiting installation of guest additions on vm: %s", masterName);
ListenableFuture<ExecResponse> execInstallGA = machineUtils.runScriptOnNode(nodeMetadata,
new InstallGuestAdditions(vmSpec, version), RunScriptOptions.NONE);
logger.debug(">> check installation of guest additions on vm: %s", masterName);
ListenableFuture<ExecResponse> checkGAinstallation = machineUtils.runScriptOnNode(nodeMetadata,
call("checkVBoxService"), RunScriptOptions.NONE);
ExecResponse checkGAinstallationResponse = Futures.getUnchecked(checkGAinstallation);
checkState(checkGAinstallationResponse.getExitStatus() == 0, "check installation of guest additions on vm(%s) " +
"failed", masterName);
machineController.ensureMachineIsShutdown(masterName);
// detach DVD and ISOs, if needed
Iterable<IMediumAttachment> mediumAttachments = Iterables.filter(
masterMachine.getMediumAttachmentsOfController("IDE Controller"),
new Predicate<IMediumAttachment>() {
public boolean apply(IMediumAttachment in) {
return in.getMedium() != null
&& in.getMedium().getDeviceType()
.equals(DeviceType.DVD);
}
});
for (IMediumAttachment iMediumAttachment : mediumAttachments) {
logger.debug("<< iMedium(%s) detached from (%s)", iMediumAttachment.getMedium()
.getName(), masterMachine.getName());
machineUtils.sharedLockMachineAndApply(
masterMachine.getName(),
new DetachDistroMediumFromMachine(iMediumAttachment
.getController(), iMediumAttachment.getPort(),
iMediumAttachment.getDevice()));
}
return masterMachine;