Examples of IMachine


Examples of org.virtualbox_4_2.IMachine

   @Test(expectedExceptions = VBoxException.class)
   public void testFailOnOtherVBoxErrors() throws Exception {

      String controllerName = "IDE Controller";

      IMachine machine = createNiceMock(IMachine.class);

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

      int controllerPort = 0;
      int device = 1;

      VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
      machine.detachDevice(controllerName, controllerPort, device);
      expectLastCall().andThrow(isoAttachedException);

      replay(machine);

      new DetachDistroMediumFromMachine(controllerName, controllerPort, device).apply(machine);
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();

      MasterSpec machineSpec = MasterSpec.builder()
               .iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(vmSpec)
               .network(networkSpec).build();
      IMachine debianNode = view.utils().injector()
               .getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(machineSpec);
      IMachine machine = manager.get().getVBox().findMachine(vmName);
      assertEquals(debianNode.getName(), machine.getName());
      undoVm(vmName);

   }
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

   private IMachine cloneMachine(CloneSpec cloneSpec) {
      VmSpec vmSpec = cloneSpec.getVmSpec();
      NetworkSpec networkSpec = cloneSpec.getNetworkSpec();
      boolean isLinkedClone = cloneSpec.isLinked();
      IMachine master = cloneSpec.getMaster();
      String flags = "";
      List<String> groups = ImmutableList.of();
      String group = "";
      String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), group , flags , workingDir);
      IMachine clonedMachine = manager
               .get()
               .getVBox()
               .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());

      // registering
      manager.get().getVBox().registerMachine(clonedMachine);

      // Networking
      for (NetworkInterfaceCard networkInterfaceCard : networkSpec.getNetworkInterfaceCards()) {
         new AttachNicToMachine(vmSpec.getVmName(), machineUtils).apply(networkInterfaceCard);
      }
     
      // set only once the creds for this machine, same coming from its master
      logger.debug("<< storing guest credentials on vm(%s) as extra data", clonedMachine.getName());
      String masterUsername = master.getExtraData(GUEST_OS_USER);
      String masterPassword = master.getExtraData(GUEST_OS_PASSWORD);
      clonedMachine.setExtraData(GUEST_OS_USER, masterUsername);
      clonedMachine.setExtraData(GUEST_OS_PASSWORD, masterPassword);

      return clonedMachine;
   }
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      StringBuilder errorBuilder = new StringBuilder();
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IMedium newHardDisk = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);

      IMedium newHardDisk = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      expect(manager.getVBox()).andReturn(vBox).anyTimes();
      expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);

      String oldMachineId = "a1e03931-29f3-4370-ada3-9547b1009212";
      String oldMachineName = "oldMachine";
      IMachine oldMachine = createMock(IMachine.class);
      IMediumAttachment oldAttachment = createMock(IMediumAttachment.class);
      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);
      expect(newHardDisk.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IMedium newHardDisk = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

      HardDisk hardDisk = createTestHardDisk();

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      MachineUtils machineUtils = createMock(MachineUtils.class);

      IMachine machine = createMock(IMachine.class);
      IVirtualBox vBox = createMock(IVirtualBox.class);
      IMedium medium = createMock(IMedium.class);
      IProgress progress = createNiceMock(IProgress.class);

      String errorMessage = "VirtualBox error: Some other VBox error";
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

               .osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
               .credentialUrl(privateKeyFile()).build();
         return hostNode;
      }

      final IMachine machine = manager.getVBox().findMachine(id);
      final String ipAddress = iMachineToIpAddress.apply(machine);
      final String osTypeId = machine.getOSTypeId();
      final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);

      final Node node = Node.builder().id(machine.getId()).name(machine.getName())
            .description(machine.getDescription()).loginPort(22).group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
            .username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
            .credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
            .sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
            .locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)).os64Bit(guestOSType.getIs64Bit())
            .osArch(guestOSType.getDescription()).osFamily(guestOSType.getFamilyDescription())
View Full Code Here

Examples of org.virtualbox_4_2.IMachine

   public ImageTemplate buildImageTemplateFromNode(String name, final String id) {
      Optional<NodeMetadata> sourceNode = getNodeById(id);
      checkState(sourceNode.isPresent(), " there is no node with id " + id);
      String vmName = VIRTUALBOX_IMAGE_PREFIX + name;

      IMachine vm = null;
      try {
         vm = manager.get().getVBox().findMachine(vmName);
      } catch (Exception e) {
      }
      checkState(vm == null, " a machine exists with name: " + vmName);
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.