Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command


    return sb.getBytes();
  }

  private Command buildIptablesAddCommand() throws OpsException {
    Command command = getRule().buildIptablesAddCommand();
    addKey(command);
    return command;
  }
View Full Code Here


    addKey(command);
    return command;
  }

  private Command buildIptablesDeleteCommand() throws OpsException {
    Command command = getRule().buildIptablesDeleteCommand();
    addKey(command);
    return command;
  }
View Full Code Here

              CommandEnvironment env = new CommandEnvironment();
              env.put("MODE", "start");
              env.put("IFACE", "--all");
              env.put("ADDRFAM", "meta");

              Command runLockdown = Command.build("/etc/network/if-pre-up.d/iptables-lockdown");
              runLockdown.setEnvironment(env);
              target.executeCommand(runLockdown);
            }
          }
        }));
View Full Code Here

    }
  }

  public static List<FirewallRecord> getCurrentFirewallState(OpsTarget target, Transport transport)
      throws OpsException {
    Command command = getIptablesCommand(transport);
    command.addLiteral("--list-rules");

    List<FirewallRecord> records = Lists.newArrayList();

    ProcessExecution execution = target.executeCommand(command);
    String stdout = execution.getStdOut();
View Full Code Here

    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

TOP

Related Classes of org.platformlayer.ops.Command

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.