Examples of IMachine


Examples of org.virtualbox_4_2.IMachine

public class ApplyBootOrderToMachineTest {

   @Test
   public void testSetBootOrderSuccessful() throws Exception {
      Map<Long, DeviceType> positionAndDeviceType = ImmutableMap.of(1l, DeviceType.HardDisk);
      IMachine machine = createMock(IMachine.class);
      for(long position : positionAndDeviceType.keySet()) {
         machine.setBootOrder(position, positionAndDeviceType.get(position));
      }
      machine.saveSettings();
      replay(machine);
      new ApplyBootOrderToMachine(positionAndDeviceType).apply(machine);
      verify(machine);
   }
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

   }
  
   @Test
   public void testCloneMachineFromAnotherMachine() {
      IMachine source = getVmWithGuestAdditionsInstalled();
      CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec())
               .master(source).linked(true).build();
      IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
               .apply(cloneSpec);
      assertTrue(isLinkedClone().apply(clone));
   }
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      String diskFormat = "vdi";
      int controllerPort = 0;
      int deviceSlot = 1;

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium hardDisk = createNiceMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      expect(vBox.createHardDisk(diskFormat, diskPath)).andReturn(hardDisk);
      expect(hardDisk.createBaseStorage(anyLong(), anyLong())).andReturn(progress);

      machine.attachDevice(controllerName, controllerPort, deviceSlot, DeviceType.HardDisk, hardDisk);
      machine.saveSettings();
      replay(manager, machine, vBox, hardDisk);

      StorageController controller = StorageController.builder()
              .name(controllerName)
              .bus(StorageBus.IDE)
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      String controllerName = "IDE Controller";
      int controllerPort = 0;
      int deviceSlot = 1;

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium hardDisk = createNiceMock(IMedium.class);

      final StringBuilder errorBuilder = new StringBuilder();
      errorBuilder.append("VirtualBox error: ");
      errorBuilder.append("Medium '/Users/mattias/jclouds-virtualbox-test/testadmin.vdi' ");
      errorBuilder.append("is already attached to port 0, device 1 of controller 'IDE Controller' ");
      errorBuilder.append("of this virtual machine (0x80BB000C)");
      String isoAlreadyAttachedException = errorBuilder.toString();

      VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
              isoAlreadyAttachedException);
      machine.attachDevice(controllerName, controllerPort, deviceSlot, DeviceType.HardDisk, hardDisk);
      expectLastCall().andThrow(isoAttachedException);

      replay(manager, machine, vBox, hardDisk);

      StorageController controller = StorageController.builder()
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      String controllerName = "IDE Controller";
      int controllerPort = 0;
      int deviceSlot = 1;

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium hardDisk = createNiceMock(IMedium.class);

      final StringBuilder errorBuilder = new StringBuilder();
      errorBuilder.append("VirtualBox error: ");
      errorBuilder.append("Some other VBox error");
      String isoAlreadyAttachedException = errorBuilder.toString();

      VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
              isoAlreadyAttachedException);
      machine.attachDevice(controllerName, controllerPort, deviceSlot, DeviceType.HardDisk, hardDisk);
      expectLastCall().andThrow(isoAttachedException);

      replay(manager, machine, vBox, hardDisk);

View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      instanceNetworkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
   }

   @Test
   public void testGuestAdditionsAreInstalled() throws Exception {
      IMachine machine = null;
      try {
         machine = cloneFromMaster();
         machineController.ensureMachineIsLaunched(machine.getName());
         sshClientForIMachine = injector.getInstance(IMachineToSshClient.class);
         SshClient client = sshClientForIMachine.apply(machine);

         sshResponds = injector.getInstance(SshResponds.class);
         checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh",
                  machine.getName());
        
         assertTrue(NetworkUtils.isIpv4(networkUtils.getIpAddressFromNicSlot(machine.getName(), 0l)));

      } finally {
         if(machine!=null) {
            for (String vmNameOrId : ImmutableSet.of(machine.getName())) {
               machineController.ensureMachineHasPowerDown(vmNameOrId);
               undoVm(vmNameOrId);
            }
         }
      }
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

         }
      }
   }

   protected IMachine cloneFromMaster() {
      IMachine source = getVmWithGuestAdditionsInstalled();
      CloneSpec cloneSpec = CloneSpec.builder()
            .vm(instanceVmSpec)
            .network(instanceNetworkSpec)
            .master(source)
            .linked(true)
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

   @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;
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

   }

   @Test
   public void testGuestAdditionsAreInstalled() throws Exception {
      try {
         IMachine machine = cloneFromMaster();
         machineController.ensureMachineIsLaunched(machine.getName());

         sshClientForIMachine = injector.getInstance(IMachineToSshClient.class);
         SshClient client = sshClientForIMachine.apply(machine);

         sshResponds = injector.getInstance(SshResponds.class);
         checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh",
                  machine.getName());

         String version = machine.getGuestPropertyValue("/VirtualBox/GuestAdd/Version");
        
         assertTrue(version != null && !version.isEmpty());
      } finally {
         for (VmSpec spec : ImmutableSet.of(machineSpec.getVmSpec())) {
            machineController.ensureMachineIsShutdown(spec.getVmName());
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

         }
      }
   }

   private IMachine cloneFromMaster() {
      IMachine source = getVmWithGuestAdditionsInstalled();
      CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec())
               .master(source).linked(true).build();
      return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
               .apply(cloneSpec);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.