@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;
  }
 /**
  * Invoked when a network creation is requested to check if the specified network can be created
  * and then creates the network
  *
  * @param network An instance of proposed new Neutron Network object.
  * @return A HTTP status code to the creation request.
  */
 @Override
 public int canCreateNetwork(NeutronNetwork network) {
   if (network == null) {
     LOGGER.error("Network object can't be null..");
     return HttpURLConnection.HTTP_BAD_REQUEST;
   }
   LOGGER.debug("Network object " + network);
   apiConnector = Activator.apiConnector;
   if (network.getNetworkUUID() == null
       || network.getNetworkName() == null
       || network.getNetworkUUID().equals("")
       || network.getNetworkName().equals("")) {
     LOGGER.error("Network UUID and Network Name can't be null/empty...");
     return HttpURLConnection.HTTP_BAD_REQUEST;
   }
   try {
     return createNetwork(network);
   } catch (IOException ie) {
     LOGGER.error("IOException :   " + ie);
     return HttpURLConnection.HTTP_INTERNAL_ERROR;
   } catch (Exception e) {
     LOGGER.error("Exception :   " + e);
     return HttpURLConnection.HTTP_INTERNAL_ERROR;
   }
 }
 /**
  * Invoked when a network update is requested to indicate if the specified network can be changed
  * using the specified delta.
  *
  * @param delta Updates to the network object using patch semantics.
  * @param original An instance of the Neutron Network object to be updated.
  * @return A HTTP status code to the update request.
  */
 @Override
 public int canUpdateNetwork(NeutronNetwork deltaNetwork, NeutronNetwork originalNetwork) {
   VirtualNetwork virtualnetwork = new VirtualNetwork();
   apiConnector = Activator.apiConnector;
   if (deltaNetwork == null || originalNetwork == null) {
     LOGGER.error("Neutron Networks can't be null..");
     return HttpURLConnection.HTTP_BAD_REQUEST;
   }
   if (("").equals(deltaNetwork.getNetworkName())) {
     LOGGER.error("Neutron Networks name can't be empty..");
     return HttpURLConnection.HTTP_BAD_REQUEST;
   }
   try {
     virtualnetwork =
         (VirtualNetwork)
             apiConnector.findById(VirtualNetwork.class, originalNetwork.getNetworkUUID());
   } catch (IOException e) {
     LOGGER.error("Exception :     " + e);
     return HttpURLConnection.HTTP_INTERNAL_ERROR;
   }
   if (virtualnetwork == null) {
     LOGGER.error("No network exists for the specified UUID...");
     return HttpURLConnection.HTTP_FORBIDDEN;
   } else {
     try {
       return updateNetwork(deltaNetwork, virtualnetwork);
     } catch (IOException ie) {
       LOGGER.error("IOException:     " + ie);
       return HttpURLConnection.HTTP_INTERNAL_ERROR;
     } catch (Exception e) {
       LOGGER.error("Exception:     " + e);
       return HttpURLConnection.HTTP_INTERNAL_ERROR;
     }
   }
 }
 /**
  * Invoked when a network deletion is requested to indicate if the specified network can be
  * deleted.
  *
  * @param network An instance of the Neutron Network object to be deleted.
  * @return A HTTP status code to the deletion request.
  */
 @Override
 public int canDeleteNetwork(NeutronNetwork network) {
   apiConnector = Activator.apiConnector;
   VirtualNetwork virtualNetwork = null;
   try {
     virtualNetwork =
         (VirtualNetwork) apiConnector.findById(VirtualNetwork.class, network.getNetworkUUID());
     if (virtualNetwork != null) {
       if (virtualNetwork.getVirtualMachineInterfaceBackRefs() != null) {
         LOGGER.info(
             "Network with UUID :  "
                 + network.getNetworkUUID()
                 + " cannot be deleted as it has port(s) associated with it....");
         return HttpURLConnection.HTTP_FORBIDDEN;
       } else {
         apiConnector.delete(virtualNetwork);
         LOGGER.info(
             "Network with UUID :  "
                 + network.getNetworkUUID()
                 + "  has been deleted successfully....");
         return HttpURLConnection.HTTP_OK;
       }
     } else {
       LOGGER.info("No Network exists with UUID :  " + network.getNetworkUUID());
       return HttpURLConnection.HTTP_BAD_REQUEST;
     }
   } catch (Exception e) {
     LOGGER.error("Exception : " + e);
     return HttpURLConnection.HTTP_INTERNAL_ERROR;
   }
 }
 /**
  * Invoked to map the NeutronNetwork object properties to the virtualNetwork object.
  *
  * @param neutronNetwork An instance of new Neutron Network object.
  * @param virtualNetwork An instance of new virtualNetwork object.
  * @return {@link VirtualNetwork}
  */
 private VirtualNetwork mapNetworkProperties(
     NeutronNetwork neutronNetwork, VirtualNetwork virtualNetwork) {
   String networkUUID = neutronNetwork.getNetworkUUID();
   String networkName = neutronNetwork.getNetworkName();
   virtualNetwork.setName(networkName);
   virtualNetwork.setUuid(networkUUID);
   virtualNetwork.setDisplayName(networkName);
   return virtualNetwork;
 }
 /**
  * Invoked to take action after a network has been updated.
  *
  * @param network An instance of modified Neutron Network object.
  */
 @Override
 public void neutronNetworkUpdated(NeutronNetwork network) {
   try {
     VirtualNetwork virtualnetwork = new VirtualNetwork();
     virtualnetwork =
         (VirtualNetwork) apiConnector.findById(VirtualNetwork.class, network.getNetworkUUID());
     if (network.getNetworkName().equalsIgnoreCase(virtualnetwork.getDisplayName())) {
       LOGGER.info("Network updatation verified....");
     } else {
       LOGGER.info("Network updatation failed....");
     }
   } catch (Exception e) {
     LOGGER.error("Exception :" + e);
   }
 }
 /**
  * Invoked to create the specified Neutron Network.
  *
  * @param network An instance of new Neutron Network object.
  * @return A HTTP status code to the creation request.
  */
 private int createNetwork(NeutronNetwork network) throws IOException {
   VirtualNetwork virtualNetwork = null;
   String networkUUID = null;
   try {
     networkUUID = UUID.fromString(network.getNetworkUUID()).toString();
   } catch (Exception ex) {
     LOGGER.error("networkUUID input incorrect", ex);
     return HttpURLConnection.HTTP_BAD_REQUEST;
   }
   virtualNetwork = (VirtualNetwork) apiConnector.findById(VirtualNetwork.class, networkUUID);
   if (virtualNetwork != null) {
     LOGGER.warn("Network already exists..");
     return HttpURLConnection.HTTP_FORBIDDEN;
   }
   virtualNetwork = new VirtualNetwork();
   // map neutronNetwork to virtualNetwork
   virtualNetwork = mapNetworkProperties(network, virtualNetwork);
   boolean networkCreated = apiConnector.create(virtualNetwork);
   LOGGER.debug("networkCreated:   " + networkCreated);
   if (!networkCreated) {
     LOGGER.warn("Network creation failed..");
     return HttpURLConnection.HTTP_INTERNAL_ERROR;
   }
   LOGGER.info(
       "Network : "
           + virtualNetwork.getName()
           + "  having UUID : "
           + virtualNetwork.getUuid()
           + "  sucessfully created...");
   return HttpURLConnection.HTTP_OK;
 }
Example #8
0
  /**
   * Invoked when a network creation is requested to indicate if the specified network can be
   * created.
   *
   * @param network An instance of proposed new Neutron Network object.
   * @return A HTTP status code to the creation request.
   */
  @Override
  public int canCreateNetwork(NeutronNetwork network) {
    if (network.isShared()) {
      logger.error(" Network shared attribute not supported ");
      return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
    }

    return HttpURLConnection.HTTP_CREATED;
  }
Example #9
0
  /**
   * Invoked to take action after a network has been deleted.
   *
   * @param network An instance of deleted Neutron Network object.
   */
  @Override
  public void neutronNetworkDeleted(NeutronNetwork network) {

    int result = canDeleteNetwork(network);
    if (result != HttpURLConnection.HTTP_OK) {
      logger.error(" deleteNetwork validation failed for result - {} ", result);
      return;
    }
    TenantNetworkManager.getManager().networkDeleted(network.getID());
  }
 /**
  * Invoked to take action after a network has been created.
  *
  * @param network An instance of new Neutron Network object.
  */
 @Override
 public void neutronNetworkCreated(NeutronNetwork network) {
   VirtualNetwork virtualNetwork = null;
   try {
     virtualNetwork =
         (VirtualNetwork) apiConnector.findById(VirtualNetwork.class, network.getNetworkUUID());
     if (virtualNetwork != null) {
       LOGGER.info("Network creation verified....");
     }
   } catch (Exception e) {
     LOGGER.error("Exception :     " + e);
   }
 }
  @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;
  }
 /**
  * Invoked to update the network
  *
  * @param delta_network An instance of Network.
  * @param virtualNetwork An instance of new virtualNetwork object.
  * @return A HTTP status code to the creation request.
  */
 private int updateNetwork(NeutronNetwork deltaNetwork, VirtualNetwork virtualNetwork)
     throws IOException {
   String networkName = deltaNetwork.getNetworkName();
   virtualNetwork.setName(networkName);
   virtualNetwork.setDisplayName(networkName);
   {
     boolean networkUpdate = apiConnector.update(virtualNetwork);
     if (!networkUpdate) {
       LOGGER.warn("Network Updation failed..");
       return HttpURLConnection.HTTP_INTERNAL_ERROR;
     }
     LOGGER.info(
         "Network having UUID : "
             + virtualNetwork.getUuid()
             + "  has been sucessfully updated...");
     return HttpURLConnection.HTTP_OK;
   }
 }