コード例 #1
0
  @Override
  public boolean removePort(String uuid) {
    if (!portExists(uuid)) {
      return false;
    }
    NeutronPort port = getPort(uuid);
    portDB.remove(uuid);
    INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
    INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);

    NeutronNetwork network = networkCRUD.getNetwork(port.getNetworkUUID());
    network.removePort(port);
    Iterator<Neutron_IPs> fixedIPIterator = port.getFixedIPs().iterator();
    while (fixedIPIterator.hasNext()) {
      Neutron_IPs ip = fixedIPIterator.next();
      NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
      if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {
        subnet.releaseIP(ip.getIpAddress());
      } else {
        subnet.resetGatewayIPAllocated();
      }
      subnet.removePort(port);
    }
    return true;
  }
コード例 #2
0
  @Override
  public boolean updatePort(String uuid, NeutronPort delta) {
    if (!portExists(uuid)) {
      return false;
    }
    NeutronPort target = portDB.get(uuid);
    // remove old Fixed_IPs
    if (delta.getFixedIPs() != null) {
      NeutronPort port = getPort(uuid);
      INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
      for (Neutron_IPs ip : port.getFixedIPs()) {
        NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
        subnet.releaseIP(ip.getIpAddress());
      }

      // allocate new Fixed_IPs
      for (Neutron_IPs ip : delta.getFixedIPs()) {
        NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
        if (ip.getIpAddress() == null) {
          ip.setIpAddress(subnet.getLowAddr());
        }
        subnet.allocateIP(ip.getIpAddress());
      }
    }
    return overwrite(target, delta);
  }
コード例 #3
0
  @Override
  public boolean addPort(NeutronPort input) {
    if (portExists(input.getID())) {
      return false;
    }
    portDB.putIfAbsent(input.getID(), input);
    // if there are no fixed IPs, allocate one for each subnet in the network
    INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
    if (input.getFixedIPs().size() == 0) {
      List<Neutron_IPs> list = input.getFixedIPs();
      Iterator<NeutronSubnet> subnetIterator = systemCRUD.getAllSubnets().iterator();
      while (subnetIterator.hasNext()) {
        NeutronSubnet subnet = subnetIterator.next();
        if (subnet.getNetworkUUID().equals(input.getNetworkUUID())) {
          list.add(new Neutron_IPs(subnet.getID()));
        }
      }
    }
    Iterator<Neutron_IPs> fixedIPIterator = input.getFixedIPs().iterator();
    while (fixedIPIterator.hasNext()) {
      Neutron_IPs ip = fixedIPIterator.next();
      NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
      if (ip.getIpAddress() == null) {
        ip.setIpAddress(subnet.getLowAddr());
      }
      if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {
        subnet.allocateIP(ip.getIpAddress());
      } else {
        subnet.setGatewayIPAllocated();
      }
      subnet.addPort(input);
    }
    INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);

    NeutronNetwork network = networkIf.getNetwork(input.getNetworkUUID());
    network.addPort(input);
    return true;
  }