Exemplo n.º 1
0
  /**
   * Executes the "remove network table" functionality.
   *
   * @return PntAdm.SUCCESS, PntAdm.ENOENT, PntAdm.WARNING, or PntAdm.CRITICAL
   */
  public int execute() throws IllegalArgumentException {

    int returnCode = PntAdm.SUCCESS;

    // Create a Network object.
    //
    try {
      Network network = getNetMgr().getNetwork(networkName);
      if (network == null) {
        printErrMessage(getString("network_name_error"));
        return (PntAdm.WARNING);
      }

      // Delete the network table.
      //
      getNetMgr().deleteNetwork(network.toString(), false, false, getDhcpDatastore());
    } catch (NoTableException e) {
      printErrMessage(getMessage(e));
      returnCode = PntAdm.ENOENT;
    } catch (Throwable e) {
      printErrMessage(getMessage(e));
      returnCode = PntAdm.WARNING;
    }

    return (returnCode);
  } // execute
  /**
   * Executes the "add client" functionality.
   *
   * @return PntAdm.SUCCESS, PntAdm.EXISTS, PntAdm.WARNING, or PntAdm.CRITICAL
   */
  public int execute() throws IllegalArgumentException {

    int returnCode = PntAdm.SUCCESS;

    // Build up a DhcpClientRecord from the user specified options.
    //
    try {
      DhcpClientRecord dhcpClientRecord = new DhcpClientRecord(clientIP);

      String clientId = options.valueOf(PntAdm.CLIENTID);
      boolean convertClientId = options.isSet(PntAdm.CONVERT_CLIENTID);
      if (convertClientId) {
        if (clientId == null) {
          String msg = getString("no_clientid_specified");
          throw new IllegalArgumentException(msg);
        }
        clientId = Util.asciiToHex(clientId);
      }
      if (clientId != null) {
        dhcpClientRecord.setClientId(clientId);
      }

      String flags = options.valueOf(PntAdm.FLAGS);
      if (flags != null) {
        dhcpClientRecord.setFlags(flags);
      }

      String serverIP = options.valueOf(PntAdm.SERVER);
      if (serverIP == null) {
        serverIP = getSvcMgr().getServerName();
      }
      dhcpClientRecord.setServerIP(serverIP);

      String expiration = options.valueOf(PntAdm.LEASE_EXPIRATION);
      if (expiration != null) {
        dhcpClientRecord.setExpiration(shortFormat, expiration);
      }

      boolean verifyMacro = options.isSet(PntAdm.VERIFY_MACRO);
      String macro = options.valueOf(PntAdm.MACRO_NAME);
      if (verifyMacro) {
        if (macro == null) {
          String msg = getString("no_macro_specified");
          throw new IllegalArgumentException(msg);
        }

        // Create a Macro entry so that we can check to see if it
        // exists in the dhcptab.
        //
        try {
          Macro existingMacro = getDhcptabMgr().getMacro(macro);
        } catch (BridgeException e) {
          printErrMessage(getString("macro_not_found"));
          return (PntAdm.WARNING);
        }
      }
      if (macro != null) {
        dhcpClientRecord.setMacro(macro);
      }

      String comment = options.valueOf(PntAdm.COMMENT);
      if (comment != null) {
        dhcpClientRecord.setComment(comment);
      }

      // Create a Network object.
      //
      Network network = getNetMgr().getNetwork(networkName);
      if (network == null) {
        printErrMessage(getString("network_name_error"));
        return (PntAdm.WARNING);
      }

      // Add the client. The host will be added to the hosts table
      // if necessary.
      //
      getNetMgr().addClient(dhcpClientRecord, network.toString(), getDhcpDatastore());
    } catch (IllegalArgumentException e) {
      throw e;
    } catch (ExistsException e) {
      printErrMessage(getMessage(e));
      returnCode = PntAdm.EXISTS;
    } catch (Throwable e) {
      printErrMessage(getMessage(e));
      returnCode = PntAdm.WARNING;
    }

    return (returnCode);
  } // execute