Пример #1
0
  public WakeOnLan(JSAPResult cmdConfig) throws JSAPException, IOException {
    super();

    if (!cmdConfig.success()) {
      printHelpAndExit();
    }

    if (cmdConfig.getBoolean(CMD_HELP)) {
      printHelpAndExit();
    }

    if (cmdConfig.getBoolean(CMD_VERSION)) {
      printVersionAndExit();
    }

    String[] machines = cmdConfig.getStringArray(CMD_ADDRESSES);
    String configPath = cmdConfig.getString(CMD_CONFIG_FILE);
    Configuration config = new Configuration(configPath);

    if (null == machines || 0 == machines.length) {
      showGUI(config);
    } else {
      InetAddress host = cmdConfig.getInetAddress(CMD_INET_ADDRESS);
      int port = cmdConfig.getInt(CMD_PORT);

      wakeup(machines, config, host, port);
    }
  }
Пример #2
0
  public Object execute(List<String> argList) {
    JSAPResult argv = parse(argList);
    if (argv == null) {
      return false;
    }

    String modelID = argv.getString(SmOption.MODEL_OPTION);

    ModelDB model = SmOption.getModel(modelID);

    DBJobParam dBJobParam = new DBJobParam();
    dBJobParam.setDstModel(model);

    for (String portName : argv.getStringArray(SmOption.PORT_OPTION)) {
      dBJobParam.setDstPortName(portName);

      new PortDeleteDBJob(dBJobParam).launch();
    }

    return true;
  }
  public Object execute(List<String> argList) throws TclShellException {
    JSAPResult argv = parse(argList);
    if (argv == null) {
      return false;
    }

    if (argv.getBoolean(SmOptionPM.LIST_ATTR_OPTION)) {
      for (PWR_SRC_ATTR e : PWR_SRC_ATTR.values())
        System.out.println(
            " =>  "
                + e.arg
                + " :\n         "
                + e.help
                + (e.allowed == null ? "" : " = " + StringUtilities.join(", ", e.allowed) + ")"));

      return true;
    }

    String modelID = argv.getString(SmOption.MODEL_OPTION);
    ModelDB model =
        (modelID != null) ? ToolsDesign.getModel(modelID) : UnwCore.getDBProject().model();

    if (model == null) {
      Logger.error(ErrorList.DB3.errorName(), ErrorList.DB3.getMessage(modelID));
      throw new TclShellException("");
    }

    PMConfig cfg = PMResourceManager.instance.getPmconfig(model, null);

    String pwrsrcName = argv.getString(SmOptionPM.PWRSRC_OPTION);

    PowerSourceInstance powerSource = PMFindVDomainTools.findPowerSource(cfg, pwrsrcName);

    if (powerSource == null) {
      Logger.error(
          ErrorListPM.PM22.errorName(),
          ErrorListPM.PM22.getMessage(pwrsrcName + "in model " + model.getModelName()));
      throw new TclShellException("");
    }

    if (!argv.contains(SmOption.NAME_VALUE_OPTION)) {
      Logger.error("TCL", "no attribute specified");
      throw new TclShellException("");
    }

    String[] tokens = argv.getStringArray(SmOption.NAME_VALUE_OPTION);
    if (tokens.length % 2 != 0) {
      Logger.error(ErrorListPM.PM_TCL1.errorName(), ErrorListPM.PM_TCL1.getMessage());
      throw new TclShellException("");
    }

    String attrName;
    String attrValue;
    boolean error = false;

    for (int i = 0; i < tokens.length; i += 2) {
      attrName = tokens[i];
      attrValue = tokens[i + 1];

      PWR_SRC_ATTR id = PWR_SRC_ATTR.findAttr(attrName);

      if (id == null) {
        Logger.error(ErrorListPM.PM_TCL3.errorName(), ErrorListPM.PM_TCL3.getMessage(attrName));
        throw new TclShellException("");

      } else {

        CONNECT_DIRECTIVE direct = null;

        switch (id) {
          case CONNECT_IVOLT:
            try {
              direct = CONNECT_DIRECTIVE.valueOf(attrValue);
              powerSource.setConnectInputVoltage(direct);
            } catch (Exception e) {
              error = true;
            }
            break;

          case CONNECT_CTRL:
            try {
              direct = CONNECT_DIRECTIVE.valueOf(attrValue);
              powerSource.setConnectControl(direct);
            } catch (Exception e) {
              error = true;
            }
            break;

          case NAME:
            if (FormatValidation.isAlphaNumeric(attrValue, false)) {
              powerSource.setName(attrValue);
            } else error = true;

          default:
            break;
        }

        if (error) {
          Logger.error(
              ErrorListPM.PM_TCL2.errorName(),
              ErrorListPM.PM_TCL2.getMessage(attrValue + " for attribute " + attrName));
          throw new TclShellException("");
        }
      }
    }

    return true;
  }
Пример #4
0
  public Object execute(List<String> argList) throws TclShellException {

    JSAPResult argv = parse(argList);
    if (argv == null) {
      return false;
    }
    InstanceDB inst;
    boolean hasError = false;
    String modelID = argv.getString(SmOption.MODEL_OPTION);

    ModelDB model = SmOption.getModel(modelID);
    if (model == null) throw new TclShellException("");

    boolean createPort = argv.getBoolean(SmOption.CREATE_PORT_OPTION);
    /*
     * Set Parameters
     */
    String[] instances = argv.getStringArray(SmOption.INSTANCE_OPTION);

    Collection<InstanceDB> instToConnect = new ArrayList<InstanceDB>();

    if (instances == null || instances.length == 0) instToConnect = model.instances();

    for (String instName : instances) {
      inst = model.instance(instName);

      if (inst == null) {
        Logger.error(
            ErrorList.DB15.errorName(),
            ErrorList.DB15.getMessage(instName + " in model " + model.getModelName()));
        hasError = true;
        continue;
      }
      instToConnect.add(inst);
    }

    DBJobParam param = new DBJobParam();
    param.setSrcData(
        ConnectByNameDBJob.CONNECT_INSTANCES,
        instToConnect.toArray(new InstanceDB[instToConnect.size()]));
    param.setSrcData(ConnectByNameDBJob.CREATE_PORT, createPort);
    param.setSrcData(ConnectByNameDBJob.LEAKAGE_PORT, argv.getBoolean(SmOption.LEAKAGE_OPTION));
    param.setSrcData(
        ConnectByNameDBJob.PROPAGATE_UP,
        SmOption.UP_OPTION.equals(argv.getString(SmOption.PROPAGATE_OPTION)));

    if (argv.contains(SmOption.DIRECTION_OPTION)) {
      String dir = argv.getString(SmOption.DIRECTION_OPTION);

      if ("in".equals(dir)) param.setSrcData(ConnectByNameDBJob.DIRECTION, PortInDB.class);
      else if ("out".equals(dir)) param.setSrcData(ConnectByNameDBJob.DIRECTION, PortOutDB.class);
    }

    if (argv.getBoolean(SmOption.HIER_OPTION))
      param.setSrcData(ConnectByNameDBJob.HIER_OPTION, true);

    param.setSrcData(ConnectByNameDBJob.KEEPCONNECTION, !argv.getBoolean(SmOption.FORCE_OPTION));

    DBJob job = new ConnectByNameDBJob(param);
    job.launch();

    if (hasError || !job.isSuccessful())
      throw new TclShellException("error with " + getCommandText());

    return null;
  }