/** * 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; }
/** * 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 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 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); } }
/** * 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); } }