- INeutronSubnetCRUD subnetInterface = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
- if (subnetInterface == null) {
- throw new ServiceUnavailableException(INTERFACE_NAME
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
- INeutronNetworkCRUD networkInterface = NeutronCRUDInterfaces.getINeutronNetworkCRUD( this);
- if (networkInterface == null) {
- throw new ServiceUnavailableException("Network CRUD Interface "
- + RestMessages.SERVICEUNAVAILABLE.toString());
- }
- if (input.isSingleton()) {
- NeutronSubnet singleton = input.getSingleton();
-
- /*
- * Verify that the subnet doesn't already exist (Issue: is a deeper check necessary?)
- * the specified network exists, the subnet has a valid network address,
- * and that the gateway IP doesn't overlap with the allocation pools
- * *then* add the subnet to the cache
- */
- if (subnetInterface.subnetExists(singleton.getID())) {
- throw new BadRequestException(UUID_EXISTS);
- }
- if (!networkInterface.networkExists(singleton.getNetworkUUID())) {
- throw new ResourceNotFoundException("network UUID does not exist.");
- }
- if (!singleton.isValidCIDR()) {
- throw new BadRequestException("invaild CIDR");
- }
- if (!singleton.initDefaults()) {
- throw new InternalServerErrorException("subnet object could not be initialized properly");
- }
- if (singleton.gatewayIP_Pool_overlap()) {
- throw new ResourceConflictException("IP pool overlaps with gateway");
- }
- Object[] instances = NeutronUtil.getInstances(INeutronSubnetAware.class, this);
- if (instances != null) {
- if (instances.length > 0) {
- for (Object instance : instances) {
- INeutronSubnetAware service = (INeutronSubnetAware) instance;
- int status = service.canCreateSubnet(singleton);
- if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
- return Response.status(status).build();
- }
- }
- } else {
- throw new ServiceUnavailableException(NO_PROVIDERS);
- }
- } else {
- throw new ServiceUnavailableException(NO_PROVIDER_LIST);
- }
- subnetInterface.addSubnet(singleton);
- if (instances != null) {
- for (Object instance : instances) {
- INeutronSubnetAware service = (INeutronSubnetAware) instance;
- service.neutronSubnetCreated(singleton);
- }
- }
- } else {
- List<NeutronSubnet> bulk = input.getBulk();
- Iterator<NeutronSubnet> i = bulk.iterator();
- HashMap<String, NeutronSubnet> testMap = new HashMap<String, NeutronSubnet>();
- Object[] instances = NeutronUtil.getInstances(INeutronSubnetAware.class, this);
- while (i.hasNext()) {
- NeutronSubnet test = i.next();
-
- /*
- * Verify that the subnet doesn't already exist (Issue: is a deeper check necessary?)
- * the specified network exists, the subnet has a valid network address,
- * and that the gateway IP doesn't overlap with the allocation pools,
- * and that the bulk request doesn't already contain a subnet with this id
- */