Package org.virtualbox_4_2

Examples of org.virtualbox_4_2.INetworkAdapter


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

    expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
    iNetworkAdapter.setAttachmentType(NAT);
    expect(iNetworkAdapter.getNATEngine()).andReturn(natEngine).anyTimes();

    List<String> redirects = Lists.newArrayList();
    expect(natEngine.getRedirects()).andReturn(redirects);
    natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1",
        2222, "", 22);
    iNetworkAdapter.setEnabled(true);
    machine.saveSettings();

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


  @Test
  public void testApplySkipsWhenAlreadyExists() throws Exception {
    Long slotId = 0l;
    IMachine machine = createMock(IMachine.class);
    INetworkAdapter iNetworkAdapter = createMock(INetworkAdapter.class);
    INATEngine natEngine = createMock(INATEngine.class);

    expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
    iNetworkAdapter.setAttachmentType(NAT);
    expect(iNetworkAdapter.getNATEngine()).andReturn(natEngine).anyTimes();

    List<String> redirects = Lists.newArrayList();
    expect(natEngine.getRedirects()).andReturn(redirects);

    natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1",
        2222, "", 22);
    expectLastCall()
        .andThrow(
            new VBoxException(null,
                "VirtualBox error: A NAT rule of this name already exists (0x80070057)"));

    iNetworkAdapter.setEnabled(true);
    machine.saveSettings();

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

  @Test(enabled = false, expectedExceptions = VBoxException.class)
  public void testRethrowInvalidAdapterSlotException() throws Exception {
    Long slotId = 30l;
    IMachine machine = createMock(IMachine.class);
    INetworkAdapter iNetworkAdapter = createMock(INetworkAdapter.class);
    INATEngine natEngine = createMock(INATEngine.class);

    String error = "VirtualBox error: Argument slot is invalid "
        + "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
View Full Code Here

      IMachine vm = createNiceMock(IMachine.class);
      VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
      IVirtualBox vBox = createNiceMock(IVirtualBox.class);
      IGuestOSType iGuestOSType = createNiceMock(IGuestOSType.class);
      INetworkAdapter nat = createNiceMock(INetworkAdapter.class);
      INATEngine natEng = createNiceMock(INATEngine.class);

      expect(vm.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + MASTER_NAME).anyTimes();
      expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes();
      expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
      expect(vm.getNetworkAdapter(eq(1l))).andReturn(null).once();
      expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once();
      expect(nat.getNATEngine()).andReturn(natEng).anyTimes();
      expect(natEng.getHostIP()).andReturn("127.0.0.1").once();
      expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,2222,,22"));
     
      expect(vbm.getVBox()).andReturn(vBox).anyTimes();
      expect(vm.getOSTypeId()).andReturn("RedHat_64").anyTimes();
      expect(vBox.getGuestOSType(vm.getOSTypeId())).andReturn(iGuestOSType);
     
      INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
      NetworkUtils networkUtils = createNiceMock(NetworkUtils.class);

      replay(vm, vBox, iGuestOSType, nat, natEng, hostOnly, networkUtils);

      NodeMetadata node = new IMachineToNodeMetadata(Suppliers
View Full Code Here

      expect(vm.getName()).andReturn(
               VIRTUALBOX_NODE_PREFIX + MASTER_NAME + VIRTUALBOX_NODE_NAME_SEPARATOR + group
                        + VIRTUALBOX_NODE_NAME_SEPARATOR + name).anyTimes();
      expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes();

      INetworkAdapter nat = createNiceMock(INetworkAdapter.class);
      INATEngine natEng = createNiceMock(INATEngine.class);
     
      INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);



      expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
      expect(vm.getNetworkAdapter(eq(1l))).andReturn(hostOnly).once();
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

      this.networkInterfaceCard = networkInterfaceCard;
   }

   @Override
   public Void apply(IMachine machine) {
      INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
      // clean up previously set rules
      for (String redirectRule : iNetworkAdapter.getNATEngine().getRedirects()) {
         String redirectRuleName = Iterables.getFirst(Splitter.on(",").split(redirectRule), null);
         if (redirectRuleName != null) {
            iNetworkAdapter.getNATEngine().removeRedirect(redirectRuleName);
         }
      }
      iNetworkAdapter.setAttachmentType(NAT);
      for (RedirectRule rule : networkInterfaceCard.getNetworkAdapter().getRedirectRules()) {
         try {
            String ruleName = String.format("%s@%s:%s->%s:%s", rule.getProtocol(), rule.getHost(), rule.getHostPort(),
                     rule.getGuest(), rule.getGuestPort());
            iNetworkAdapter.getNATEngine().addRedirect(ruleName, rule.getProtocol(), rule.getHost(), rule.getHostPort(),
                     rule.getGuest(), rule.getGuestPort());
         } catch (VBoxException e) {
            if (!e.getMessage().contains("already exists"))
               throw e;
         }
      }
      iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
      machine.saveSettings();
      return null;
   }
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

      String clientIpAddress = null;

      long nicSlot = 0;
      while (nicSlot < 4 && Strings.isNullOrEmpty(clientIpAddress)) {
         INetworkAdapter networkAdapter = vm.getNetworkAdapter(nicSlot);

         if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.NAT)) {
            for (String nameProtocolnumberAddressInboudportGuestTargetport : networkAdapter.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)) {
                  clientIpAddress = hostAddress;
                  sshPort = inboundPort;
               }
            }
         } else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.Bridged)) {
            clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot());
         } else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.HostOnly)) {
            clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName());
         }
         nicSlot++;
      }
      return sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
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

TOP

Related Classes of org.virtualbox_4_2.INetworkAdapter

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.