- /*
- * the port must be part of an existing network, must not already exist,
- * have a valid MAC and the MAC not be in use
- */
- if (singleton.getNetworkUUID() == null) {
- throw new BadRequestException("network UUID musy be specified");
- }
- if (portInterface.portExists(singleton.getID())) {
- throw new BadRequestException(UUID_EXISTS);
- }
- if (!networkInterface.networkExists(singleton.getNetworkUUID())) {
- throw new ResourceNotFoundException("network UUID does not exist.");
- }
- if (singleton.getMacAddress() == null ||
- !singleton.getMacAddress().matches(MAC_REGEX)) {
- throw new BadRequestException("MAC address not properly formatted");
- }
- if (portInterface.macInUse(singleton.getMacAddress())) {
- throw new ResourceConflictException("MAC Address is in use.");
- }
- /*
- * if fixed IPs are specified, each one has to have an existing subnet ID
- * that is in the same scoping network as the port. In addition, if an IP
- * address is specified it has to be a valid address for the subnet and not
- * already in use
- */
- List<Neutron_IPs> fixedIPs = singleton.getFixedIPs();
- if (fixedIPs != null && fixedIPs.size() > 0) {
- Iterator<Neutron_IPs> fixedIPIterator = fixedIPs.iterator();
- while (fixedIPIterator.hasNext()) {
- Neutron_IPs ip = fixedIPIterator.next();
- if (ip.getSubnetUUID() == null) {
- throw new BadRequestException("subnet UUID not specified");
- }
- NeutronSubnet subnet = subnetInterface.getSubnet(ip.getSubnetUUID());
- if (subnet == null) {
- throw new BadRequestException("subnet UUID must exist");
- }
- if (!singleton.getNetworkUUID().equalsIgnoreCase(subnet.getNetworkUUID())) {
- throw new BadRequestException(NET_UUID_MATCH);
- }
- if (ip.getIpAddress() != null) {
- if (!subnet.isValidIP(ip.getIpAddress())) {
- throw new BadRequestException("IP address is not valid");
- }
- if (subnet.isIPInUse(ip.getIpAddress())) {
- throw new ResourceConflictException("IP address is in use.");
- }
- }
- }
- }
-