@Override
  public void execute() throws InvalidParameterValueException {
    CallContext.current().setEventDetails("Ip Id: " + id);
    NicSecondaryIp nicSecIp = getIpEntry();

    if (nicSecIp == null) {
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid IP id is passed");
    }

    if (getNetworkType() == NetworkType.Basic) {
      // remove the security group rules for this secondary ip
      boolean success = false;
      success =
          _securityGroupService.securityGroupRulesForVmSecIp(
              nicSecIp.getNicId(), nicSecIp.getNetworkId(), nicSecIp.getIp4Address(), false);
      if (success == false) {
        throw new ServerApiException(
            ApiErrorCode.INTERNAL_ERROR, "Failed to set security group rules for the secondary ip");
      }
    }

    try {
      boolean result = _networkService.releaseSecondaryIpFromNic(id);
      if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
      } else {
        throw new ServerApiException(
            ApiErrorCode.INTERNAL_ERROR, "Failed to remove secondary  ip address for the nic");
      }
    } catch (InvalidParameterValueException e) {
      throw new InvalidParameterValueException("Removing guest ip from nic failed");
    }
  }
 public Long getNetworkId() {
   NicSecondaryIp nicSecIp = _entityMgr.findById(NicSecondaryIp.class, getIpAddressId());
   if (nicSecIp != null) {
     Long networkId = nicSecIp.getNetworkId();
     return networkId;
   } else {
     return null;
   }
 }