Ejemplo n.º 1
0
  @Test
  public void test() throws ApiSenderException {
    EipInventory eip = deployer.eips.get("eip");
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    VmNicInventory nic = vm.getVmNics().get(0);
    IpRangeInventory ipr = deployer.ipRanges.get("GuestIpRange");

    String newIp = null;
    long s = NetworkUtils.ipv4StringToLong(ipr.getStartIp());
    long e = NetworkUtils.ipv4StringToLong(ipr.getEndIp());

    for (long l = s; s < e; s++) {
      String ip = NetworkUtils.longToIpv4String(l);
      if (!ip.equals(nic.getIp())) {
        newIp = ip;
        break;
      }
    }
    Assert.assertNotNull(newIp);

    api.stopVmInstance(vm.getUuid());
    api.setStaticIp(vm.getUuid(), nic.getL3NetworkUuid(), newIp);
    EipVO eipvo = dbf.findByUuid(eip.getUuid(), EipVO.class);
    Assert.assertEquals(newIp, eipvo.getGuestIp());
  }
Ejemplo n.º 2
0
  @Override
  public UsedIpInventory allocateIp(IpAllocateMessage msg) {
    if (msg.getRequiredIp() != null) {
      return allocateRequiredIp(msg);
    }

    SimpleQuery<IpRangeVO> query = dbf.createQuery(IpRangeVO.class);
    query.add(IpRangeVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid());
    List<IpRangeVO> ranges = query.list();

    Collections.shuffle(ranges);

    do {
      String ip = null;
      IpRangeVO tr = null;

      for (IpRangeVO r : ranges) {
        ip = allocateIp(r);
        tr = r;
        if (ip != null) {
          break;
        }
      }

      if (ip == null) {
        /* No available ip in ranges */
        return null;
      }

      UsedIpInventory inv = l3NwMgr.reserveIp(IpRangeInventory.valueOf(tr), ip);
      if (inv != null) {
        return inv;
      }
    } while (true);
  }