Ejemplo n.º 1
0
  @RequestMapping(value = "/networks", method = RequestMethod.POST, consumes = "application/json")
  @ResponseStatus(HttpStatus.OK)
  public void addNetworks(@RequestBody final NetworkAdd na) {
    if (na.getName() == null || na.getName().isEmpty()) {
      throw BddException.INVALID_PARAMETER("name", na.getName());
    }

    if (na.getPortGroup() == null || na.getPortGroup().isEmpty()) {
      throw BddException.INVALID_PARAMETER("port group", na.getPortGroup());
    }

    if (na.isDhcp()) {
      networkManager.addDhcpNetwork(na.getName(), na.getPortGroup());
    } else {
      if (!IpAddressUtil.isValidNetmask(na.getNetmask())) {
        throw BddException.INVALID_PARAMETER("netmask", na.getNetmask());
      }
      long netmask = IpAddressUtil.getAddressAsLong(na.getNetmask());
      if (!IpAddressUtil.isValidIp(netmask, IpAddressUtil.getAddressAsLong(na.getGateway()))) {
        throw BddException.INVALID_PARAMETER("gateway", na.getGateway());
      }
      if (na.getDns1() != null && !IpAddressUtil.isValidIp(na.getDns1())) {
        throw BddException.INVALID_PARAMETER("primary dns", na.getDns1());
      }
      if (na.getDns2() != null && !IpAddressUtil.isValidIp(na.getDns2())) {
        throw BddException.INVALID_PARAMETER("secondary dns", na.getDns2());
      }

      AuAssert.check(na.getIp() != null, "Spring should guarantee this");
      for (IpBlock blk : na.getIp()) {
        Long begin = IpAddressUtil.getAddressAsLong(blk.getBeginIp());
        Long end = IpAddressUtil.getAddressAsLong(blk.getEndIp());

        if (begin == null
            || end == null
            || begin > end
            || !IpAddressUtil.isValidIp(netmask, begin)
            || !IpAddressUtil.isValidIp(netmask, end)) {
          throw BddException.INVALID_PARAMETER(
              "IP block", "[" + blk.getBeginIp() + ", " + blk.getEndIp() + "]");
        }
      }

      networkManager.addIpPoolNetwork(
          na.getName(),
          na.getPortGroup(),
          na.getNetmask(),
          na.getGateway(),
          na.getDns1(),
          na.getDns2(),
          na.getIp());
    }
  }
Ejemplo n.º 2
0
 @RequestMapping(value = "/networks", method = RequestMethod.GET, produces = "application/json")
 @ResponseBody
 public List<NetworkRead> getNetworks(
     @RequestParam(value = "details", required = false, defaultValue = "false")
         final Boolean details) {
   return networkManager.getAllNetworks(details != null ? details : false);
 }
Ejemplo n.º 3
0
  @RequestMapping(
      value = "/network/{networkName}",
      method = RequestMethod.GET,
      produces = "application/json")
  @ResponseBody
  public NetworkRead getNetworkByName(
      @PathVariable("networkName") final String networkName,
      @RequestParam(value = "details", required = false, defaultValue = "false")
          final Boolean details) {
    NetworkRead network =
        networkManager.getNetworkByName(networkName, details != null ? details : false);

    if (network == null) {
      throw NetworkException.NOT_FOUND("network", networkName);
    }

    return network;
  }
Ejemplo n.º 4
0
 @RequestMapping(value = "/network/{networkName}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.OK)
 public void deleteNetworkByName(@PathVariable("networkName") final String networkName) {
   networkManager.removeNetwork(networkName);
 }