Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command$Argument


    return FirewallNetmask.buildCidr(cidr);
  }

  public static Command buildCommandAddFirewallRule(OpsTarget server, FirewallRecord add) throws OpsException {
    if (isPolicyDefault(add)) {
      Command command = getIptablesCommand(add.getTransport());
      command.addLiteral("-P");
      command.addLiteral(toChain(add));
      command.addLiteral(toIpTableDecision(add.decision));
      return command;
    }

    // iptables --append INPUT -s 74.125.67.103/32 -p tcp -m tcp --dport 22 -j ACCEPT
    String action;
    // Passes take precedence
    switch (add.decision) {
    case Pass:
      action = " --insert " + toChain(add) + " 1 ";
      break;
    case Block:
      action = " --append " + toChain(add);
      break;
    default:
      throw new IllegalStateException();
    }
    String ipTableRule = buildIpTableRule(add);
    String commandString = getIptablesCommand(add.getTransport()).buildCommandString() + action + ipTableRule;
    Command command = Command.build(commandString);
    return command;
  }
View Full Code Here


    // iptables --delete INPUT -s 74.125.67.103/32 -p tcp -m tcp --dport 22 -j ACCEP
    String ipTableRule = buildIpTableRule(remove);
    String commandString = getIptablesCommand(remove.getTransport()).buildCommandString() + " --delete "
        + toChain(remove) + " " + ipTableRule;
    Command command = Command.build(commandString);
    server.executeCommand(command);
  }
View Full Code Here

          List<SimpleIptablesRule> correct = checkMatchingRules(matches, protocol);

          if (correct.isEmpty()) {
            String ruleSpec = buildRuleSpec(protocol);

            Command command = SimpleIptablesRules.buildCommand(transport, chain);
            command.addLiteral("-A").addLiteral(ruleSpec);
            command.addLiteral("-m").addLiteral("comment");
            command.addLiteral("--comment").addQuoted(comment);

            target.executeCommand(command);
          } else {
            log.info("Found existing rule: " + Joiner.on("\n").join(matches));
          }
        }

        if (OpsContext.isDelete()) {
          if (!matches.isEmpty()) {
            for (SimpleIptablesRule rule : matches) {
              log.info("Deleting rule: " + rule);
              String deleteRuleSpec = rule.convertToDeleteSpec();
              Command command = SimpleIptablesRules.buildCommand(transport, chain);
              command.addLiteral(deleteRuleSpec);
              target.executeCommand(command);
            }
          }
        }
      }
View Full Code Here

    } else {
      fileOnTarget = src.getPath();
    }

    if (!fileOnTarget.equals(targetFilePath)) {
      Command copy = Command.build("cp {0} {1}", fileOnTarget, targetFilePath);
      target.executeCommand(copy);
    } else {
      log.info("File is in destination path: " + fileOnTarget);
    }
  }
View Full Code Here

    }
    return locales;
  }

  private List<String> getGeneratedLocales(OpsTarget target) throws OpsException {
    Command listLocales = Command.build("localedef --list-archive");
    ProcessExecution execution = target.executeCommand(listLocales);

    List<String> locales = Lists.newArrayList();
    for (String line : Splitter.on("\n").split(execution.getStdOut())) {
      line = line.trim();
View Full Code Here

  protected abstract void extendPool() throws OpsException;

  private boolean createSymlink(File symlinkTarget, File link) throws OpsException {
    // symlinkTarget = symlinkTarget.getAbsoluteFile();

    Command command = Command.build("ln -s -T {0} {1}", symlinkTarget, link);
    try {
      target.executeCommand(command);
      return true;
    } catch (ProcessExecutionException e) {
      if (e.getExecution().getStdErr().endsWith("File exists")) {
View Full Code Here

  public void setMainClass(String mainClass) {
    this.mainClass = mainClass;
  }

  public Command get() {
    Command command = Command.build("java");
    command.addLiteral("-server");

    for (Map.Entry<String, String> define : defines.entrySet()) {
      command.addLiteral("-D" + define.getKey() + "=" + define.getValue());
    }

    StringBuilder cp = new StringBuilder();
    for (ClasspathEntry entry : classpath) {
      if (cp.length() != 0) {
        cp.append(":");
      }
      String s = entry.path.getAbsolutePath();
      if (entry.wildcard) {
        // TODO: Adding * is gross
        s += "/*";
      }
      cp.append(s);
    }

    // TODO: This is not nice either
    if (cp.length() == 0) {
      cp.append(".");
    } else {
      cp.append(":.");
    }

    command.addLiteral("-cp").addQuoted(cp.toString());

    if (jar != null) {
      command.addLiteral("-jar").addFile(jar);
    } else {
      command.addQuoted(mainClass);
    }

    for (Argument argument : arguments) {
      command.addArgument(argument);
    }

    return command;
  }
View Full Code Here

  }

  @Override
  public void configureAddRule(OpsTarget target, FirewallRecord add) throws OpsException {
    // OpsServer server = smartGetServer(true);
    Command command = IpTablesManager.buildCommandAddFirewallRule(target, add);

    String fileName = Sanitizer.forFileName().clean(add.buildKey());

    File scriptDirectory = new File("/etc/iptables/eth0");
    File transportDirectory;
    switch (add.getTransport()) {
    case Ipv4:
      transportDirectory = new File(scriptDirectory, "inet");
      break;
    case Ipv6:
      transportDirectory = new File(scriptDirectory, "inet6");
      break;
    default:
      throw new IllegalStateException();
    }
    File scriptFile = new File(transportDirectory, fileName);

    ScriptBuilder sb = new ScriptBuilder();
    sb.add(command);

    String script = sb.toString();

    String existing = target.readTextFile(scriptFile);

    boolean shouldUpload = true;
    if (existing != null) {
      if (Objects.equal(existing, script)) {
        shouldUpload = false;
      } else {
        // TODO: Put a UUID in there, check the UUID is the same??
        throw new OpsException("Script has changed: " + scriptFile);
      }
    }

    if (shouldUpload) {
      target.mkdir(transportDirectory);

      FileUpload upload = FileUpload.build(script);
      upload.path = scriptFile;
      upload.mode = "0755";
      target.doUpload(upload);
    }

    Command executeScript = Command.build("{0}", scriptFile);
    target.executeCommand(executeScript);

    // getCurrentFirewallState(operation).state.add(add);
  }
View Full Code Here

        sshKey = target.readTextFile(sshPublicKeyPath);
        if (sshKey == null) {
          // su -c "ssh-keygen -q -f /var/lib/jenkins/.ssh/id_rsa -N ''" jenkins

          Command keygenCommand = Command.build("su");
          keygenCommand.addLiteral("-c").addQuoted("ssh-keygen -q -f /var/lib/jenkins/.ssh/id_rsa -N ''");
          keygenCommand.addLiteral("jenkins");

          target.executeCommand(keygenCommand);

          sshKey = target.readTextFile(sshPublicKeyPath);
        }
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.Command$Argument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.