Package org.virtualbox_4_2

Examples of org.virtualbox_4_2.IMediumAttachment


   private void onAlreadyAttachedExceptionDetachOrPropagate(IVirtualBox vBox, final IMedium medium, VBoxException e) {
      Matcher matcher = ATTACHED_PATTERN.matcher(e.getMessage());
      if (matcher.find()) {
         String machineId = matcher.group(1);
         IMachine immutableMachine = vBox.findMachine(machineId);
         IMediumAttachment mediumAttachment = Iterables.find(immutableMachine.getMediumAttachments(),
                  new Predicate<IMediumAttachment>() {
                     public boolean apply(IMediumAttachment in) {
                        return in.getMedium().getId().equals(medium.getId());
                     }
                  });
         machineUtils.writeLockMachineAndApply(immutableMachine.getName(), new DetachDistroMediumFromMachine(
               mediumAttachment.getController(), mediumAttachment.getPort(), mediumAttachment.getDevice()));
         deleteMediumAndBlockUntilComplete(medium);
      } else {
         throw e;
      }
   }
View Full Code Here


   @Test
   public void testConvert() throws Exception {

      VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
      IStorageController iStorageController = createNiceMock(IStorageController.class);
      IMediumAttachment iMediumAttachment = createNiceMock(IMediumAttachment.class);
      IMedium hd = createNiceMock(IMedium.class);
      IMedium dvd = createNiceMock(IMedium.class);
      IMachine vm = createNiceMock(IMachine.class);

      expect(vm.getStorageControllers()).andReturn(Lists.newArrayList(iStorageController)).anyTimes();
      expect(iStorageController.getName()).andReturn(CONTROLLER_NAME).anyTimes();
      expect(iStorageController.getBus()).andReturn(CONTROLLER_BUS).anyTimes();
      expect(vm.getMediumAttachmentsOfController(CONTROLLER_NAME)).andReturn(Lists.newArrayList(iMediumAttachment)).anyTimes();
      expect(iMediumAttachment.getPort()).andReturn(0).once();
      expect(iMediumAttachment.getDevice()).andReturn(0).once();

      expect(iMediumAttachment.getMedium()).andReturn(hd);
      expect(hd.getDeviceType()).andReturn(DeviceType.HardDisk).once();
      expect(hd.getLocation()).andReturn(PATH_TO_HD).once();

      expect(iMediumAttachment.getMedium()).andReturn(dvd);
      expect(dvd.getDeviceType()).andReturn(DeviceType.DVD).once();
      expect(dvd.getLocation()).andReturn(PATH_TO_DVD).once();

      expect(vm.getName()).andReturn(VM_NAME).anyTimes();
      expect(vm.getId()).andReturn(VM_ID).anyTimes();
View Full Code Here

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

   private void onAlreadyAttachedExceptionDetachOrPropagate(IVirtualBox vBox, final IMedium medium, VBoxException e) {
      Matcher matcher = ATTACHED_PATTERN.matcher(e.getMessage());
      if (matcher.find()) {
         String machineId = matcher.group(1);
         IMachine immutableMachine = vBox.findMachine(machineId);
         IMediumAttachment mediumAttachment = Iterables.find(immutableMachine.getMediumAttachments(),
                  new Predicate<IMediumAttachment>() {
                     public boolean apply(IMediumAttachment in) {
                        return in.getMedium().getId().equals(medium.getId());
                     }
                  });
         machineUtils.writeLockMachineAndApply(immutableMachine.getName(), new DetachDistroMediumFromMachine(
               mediumAttachment.getController(), mediumAttachment.getPort(), mediumAttachment.getDevice()));
         deleteMediumAndBlockUntilComplete(medium);
      } else {
         throw e;
      }
   }
View Full Code Here

  
   private NodeMetadataBuilder getIpAddresses(IMachine vm, NodeMetadataBuilder nodeMetadataBuilder) {
      List<String> publicIpAddresses = Lists.newArrayList();
      List<String> privateIpAddresses = Lists.newArrayList();
      for(long slot = 0; slot < 4; slot ++) {
         INetworkAdapter adapter = vm.getNetworkAdapter(slot);
         if(adapter != null) {
            if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) {
               String hostIP = adapter.getNATEngine().getHostIP();
               if(!hostIP.isEmpty())
                  publicIpAddresses.add(hostIP);
               for (String nameProtocolnumberAddressInboudportGuestTargetport : adapter.getNATEngine().getRedirects()) {
                  Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport);
                  String protocolNumber = Iterables.get(stuff, 1);
                  String hostAddress = Iterables.get(stuff, 2);
                  String inboundPort = Iterables.get(stuff, 3);
                  String targetPort = Iterables.get(stuff, 5);
                  if ("1".equals(protocolNumber) && "22".equals(targetPort)) {
                     int inPort = Integer.parseInt(inboundPort);
                     publicIpAddresses.add(hostAddress);
                     nodeMetadataBuilder.loginPort(inPort);
                  }
               }
            } else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) {
               String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
               privateIpAddresses.add(clientIpAddress);

            } else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) {
               String clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName());            
               publicIpAddresses.add(clientIpAddress);
            }
         }
      }
View Full Code Here

        this.networkInterfaceCard = networkInterfaceCard;
   }

   @Override
   public Void apply(IMachine machine) {
      INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
      iNetworkAdapter.setAttachmentType(Bridged);
      iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
      iNetworkAdapter.setBridgedInterface(networkInterfaceCard.getHostInterfaceName());
      iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
      machine.saveSettings();
      return null;
   }
View Full Code Here

      this.networkInterfaceCard = networkInterfaceCard;
   }

   @Override
   public Void apply(IMachine machine) {
      INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
      iNetworkAdapter.setAttachmentType(NetworkAttachmentType.HostOnly);
      iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
      iNetworkAdapter.setHostOnlyInterface(networkInterfaceCard.getHostInterfaceName());
      iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
      machine.saveSettings();
      return null;
   }
View Full Code Here

  @Test
  public void testApplyNetworkingToNonExistingAdapter() throws Exception {
    Long adapterId = 0l;
    IMachine machine = createMock(IMachine.class);
    INetworkAdapter iNetworkAdapter = createMock(INetworkAdapter.class);

    expect(machine.getNetworkAdapter(adapterId)).andReturn(iNetworkAdapter);
    iNetworkAdapter.setAttachmentType(Bridged);
    iNetworkAdapter.setMACAddress(macAddress);
    iNetworkAdapter.setBridgedInterface(hostInterface);
    iNetworkAdapter.setEnabled(true);
    machine.saveSettings();

    replay(machine, iNetworkAdapter);
    NetworkAdapter networkAdapter = NetworkAdapter.builder()
        .networkAttachmentType(NetworkAttachmentType.Bridged).build();
View Full Code Here

      VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
      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);

      expect(session.getConsole()).andReturn(console);
      expect(console.takeSnapshot(snapshotName, snapshotDesc)).andReturn(
            progress);
      expect(progress.getCompleted()).andReturn(true);

      session.unlockMachine();
      replay(manager, machine, vBox, session, console, progress);

      new TakeSnapshotIfNotAlreadyAttached(Suppliers.ofInstance(manager), snapshotName, snapshotDesc, Logger.CONSOLE)
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);
      expect(progress.getCompleted()).andReturn(true);
      expect(machine.getCurrentSnapshot()).andReturn(null).anyTimes();
      expect(manager.openMachineSession(machine)).andReturn(session);
      expect(machine.getState()).andReturn(MachineState.PoweredOff).anyTimes();

      expect(machine.getName()).andReturn("machine").anyTimes();
View Full Code Here

TOP

Related Classes of org.virtualbox_4_2.IMediumAttachment

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.