Package org.virtualbox_4_2

Examples of org.virtualbox_4_2.MachineState


      String oldAttachmentController = "oldAttachmentController";
      int oldAttachmentDevice = 1;
      int oldAttachmentPort = 2;
      IMedium oldMedium = createMock(IMedium.class);
      String oldMediumId = "oldMediumId";
      ISession detachSession = createNiceMock(ISession.class);

      StringBuilder errorBuilder = new StringBuilder();
      errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: ");
      errorBuilder.append("Cannot delete storage: medium '/Users/adriancole/jclouds-virtualbox-test/testadmin.vdi ");
      errorBuilder.append("is still attached to the following 1 virtual machine(s): ");
      errorBuilder.append(oldMachineId + " (0x80BB000C)");
      String errorMessage = errorBuilder.toString();

      VBoxException stillAttached = new VBoxException(createNiceMock(Throwable.class), errorMessage);
      expect(medium.deleteStorage()).andThrow(stillAttached);

      expect(vBox.findMachine(oldMachineId)).andReturn(oldMachine);
      expect(oldMachine.getMediumAttachments()).andReturn(ImmutableList.of(oldAttachment));
      expect(oldAttachment.getMedium()).andReturn(oldMedium);
      expect(oldMedium.getId()).andReturn(oldMediumId);
      // in this case, they are the same medium, so safe to detach
      expect(medium.getId()).andReturn(oldMediumId);
      expect(oldMachine.getName()).andReturn(oldMachineName);
      expect(oldAttachment.getController()).andReturn(oldAttachmentController);
      expect(oldAttachment.getDevice()).andReturn(oldAttachmentDevice);
      expect(oldAttachment.getPort()).andReturn(oldAttachmentPort);
      // TODO: is this ok that we searched by ID last time?
      expect(vBox.findMachine(oldMachineName)).andReturn(oldMachine);
      expect(manager.getSessionObject()).andReturn(detachSession);
      oldMachine.lockMachine(detachSession, LockType.Write);
      expect(detachSession.getMachine()).andReturn(oldMachine);
      oldMachine.detachDevice(oldAttachmentController, oldAttachmentPort, oldAttachmentDevice);
      oldMachine.saveSettings();

      expect(medium.deleteStorage()).andReturn(progress);
      expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(newHardDisk);
View Full Code Here


      this.machineUtils = machineUtils;
      this.executionType = executionType;
   }

   public ISession ensureMachineIsLaunched(String vmName) {
      ISession session = null;
      IMachine machine = manager.get().getVBox().findMachine(vmName);
      while (!machine.getState().equals(MachineState.Running)) {
         try {
            session = machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(),
                  executionType, ""));
         } catch (RuntimeException e) {
            if (e.getMessage().contains(
                  "org.virtualbox_4_2.VBoxException: VirtualBox error: The given session is busy (0x80BB0007)")) {
               throw e;
            } else if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
               continue;
            } else {
               throw e;
            }
         }
      }

      String guestAdditionsInstalled = machineUtils.sharedLockMachineAndApplyToSession(vmName,
            new Function<ISession, String>() {
               @Override
               public String apply(ISession session) {
                  retry(new FacilitiesPredicate(session), 15, 3, SECONDS).apply(4);
                  String guestAdditionsInstalled = session.getConsole().getGuest().getAdditionsVersion();
                  return guestAdditionsInstalled;
               }

            });
      if (!Strings.nullToEmpty(guestAdditionsInstalled).isEmpty()) {
View Full Code Here

      }
      return checkNotNull(session, "session");
   }

   public ISession ensureMachineHasPowerDown(String vmName) {
      ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, ISession>() {
         @Override
         public ISession apply(ISession session) {
            IProgress powerdownIProgress = session.getConsole().powerDown();
            powerdownIProgress.waitForCompletion(-1);
            return session;
         }
      });
      return checkNotNull(session, "session");
View Full Code Here

   /**
    * if machine supports ACPI it can be shutdown gently - not powerdown()
    * http://askubuntu.com/questions/82015/shutting-down-ubuntu-server-running-in-headless-virtualbox
    */
   public ISession ensureMachineIsShutdown(String vmName) {
      ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, ISession>() {
               @Override
               public ISession apply(ISession session) {
                  session.getConsole().powerButton();
                  return session;
               }
            });       
      checkState(
            retry(new MachineStatePredicate(manager.get().getVBox(), vmName), 15, 3, SECONDS).apply(
View Full Code Here

            .cleanUpMode(CleanupMode.Full).build();
      MasterSpec machineSpec = MasterSpec.builder()
            .iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build()).vm(vmSpec)
            .network(NetworkSpec.builder().build()).build();
      IMachine createdMachine = createMock(IMachine.class);
      ISession session = createMock(ISession.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      String flags = "";
      List<String> groups = Lists.newArrayList();
      String group = "";
      expect(vBox.composeMachineFilename(vmName, group, flags, "/tmp/workingDir")).andReturn("settingsFile");

      StringBuilder errorMessageBuilder = new StringBuilder();
      errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
      errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)");
      String errorMessage = errorMessageBuilder.toString();
      VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);

      expect(vBox.findMachine(vmName)).andThrow(vBoxException);

      expect(vBox.createMachine(anyString(), eq(vmName), groups, anyString(), anyString())).andReturn(createdMachine)
            .anyTimes();
      vBox.registerMachine(createdMachine);

      expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
      expect(manager.getSessionObject()).andReturn(session);
      expect(session.getMachine()).andReturn(createdMachine);
      createdMachine.lockMachine(session, LockType.Write);
      createdMachine.setMemorySize(1024l);
      createdMachine.saveSettings();
      session.unlockMachine();

      // TODO: this mock test is not finished.
      replay(manager, createdMachine, vBox, session);

      new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils,
View Full Code Here

   }

   @Override
   public ISnapshot apply(IMachine machine) {
      // Snapshot a machine
      ISession session = null;
      ISnapshot snap = machine.getCurrentSnapshot();

      if (snap == null) {
         try {
            session = manager.get().openMachineSession(machine);
            int retries = 10;
            while (true) {
               try {

                  // running machines need to be pause before a snapshot can be taken
                  // due to a vbox bug see https://www.virtualbox.org/ticket/9255
                  boolean paused = false;
                  if (machine.getState() == MachineState.Running) {
                     session.getConsole().pause();
                     paused = true;
                  }

                  IProgress progress = session.getConsole().takeSnapshot(snapshotName, snapshotDesc);
                  progress.waitForCompletion(-1);

                  if (paused) {
                     session.getConsole().resume();
                  }

                  snap = machine.getCurrentSnapshot();
                  logger.debug("<< snapshot(%s) with description(%s) taken from master(%s)", snapshotName, snapshotDesc,
                           machine.getName());
View Full Code Here

               + nodeSpec.getTag() + VIRTUALBOX_NODE_NAME_SEPARATOR + nodeSpec.getName();
   }

   private void deleteExistingSnapshot(Master master) {
      if (master.getMachine().getCurrentSnapshot() != null) {
         ISession session;
         try {
            session = manager.get().getSessionObject();
            master.getMachine().lockMachine(session, LockType.Write);
            IProgress progress = session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
            progress.waitForCompletion(-1);
            session.unlockMachine();
         } catch (Exception e) {
            throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e);
         }
         logger.debug("<< deleted an existing snapshot of vm(%s)", master.getMachine().getName());
      }
View Full Code Here

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      ISession session = createMock(ISession.class);
      IConsole console = createNiceMock(IConsole.class);
      IProgress progress = createNiceMock(IProgress.class);
      ISnapshot snapshot = createNiceMock(ISnapshot.class);
      expect(machine.getCurrentSnapshot()).andReturn(snapshot).anyTimes();
      expect(machine.getState()).andReturn(MachineState.PoweredOff).anyTimes();

      expect(manager.openMachineSession(machine)).andReturn(session);
View Full Code Here

   @Override
   public ISnapshot apply(IMachine machine) {
      // Snapshot a machine
      ISession session = null;
      ISnapshot snap = machine.getCurrentSnapshot();

      if (snap == null) {
         try {
            session = manager.get().openMachineSession(machine);
            int retries = 10;
View Full Code Here

               .createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags);
      List<CloneOptions> options = Lists.newArrayList();
      if (isLinkedClone)
         options.add(CloneOptions.Link);

      ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager,
            "snapshotName", "snapshotDesc", logger).apply(master);
      IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine,
            CloneMode.MachineState, options);
      progress.waitForCompletion(-1);

      // memory may not be the same as the master vm
      clonedMachine.setMemorySize(cloneSpec.getVmSpec().getMemory());
View Full Code Here

TOP

Related Classes of org.virtualbox_4_2.MachineState

Copyright © 2018 www.massapicom. 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.