Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command$Argument


      File scriptPath = new File("/etc/network/if-up.d/nat-for-bridge");
      TemplatedFile nat = addChild(TemplatedFile.build(template, scriptPath));
      nat.setFileMode("0755");

      // Simulate an ifup run
      Command command = Command.build(scriptPath);
      CommandEnvironment env = new CommandEnvironment();
      env.put("IFACE", template.getPublicInterface());
      env.put("MODE", "start");
      env.put("ADDRFAM", "inet");
      command.setEnvironment(env);

      nat.setUpdateAction(command);
    }
  }
View Full Code Here


      script.addresses.add(address4);
      script.addresses.add(address6);

      // script.hostPrimaryInterface = hostModel.publicInterface;

      Command command = Command.build("lxc-start");
      command.addLiteral("--name").addQuoted(id);
      script.launchInstanceCommand = command;
    }

    {
      // ManagedSupervisordInstance service = instance.addChild(ManagedSupervisordInstance.class);
View Full Code Here

          String hostPrimaryInterface = getHostPrimaryInterface();
          if (Strings.isNullOrEmpty(hostPrimaryInterface)) {
            throw new OpsException("primaryInterface not specified");
          }

          Command command = Command.build("ip neigh add proxy {0} dev {1}", address, hostPrimaryInterface);
          sb.add(command);
        }
      }
    }
  }
View Full Code Here

  //
  // instance.config = Providers.of(sup);
  // }

  public void configure(ItemBase owner, StandardService service) {
    Command command = Command.build(filePath.getAbsolutePath());
    service.command = OpsProvider.of(command);

    service.key = key;
    service.owner = owner.getKey();
View Full Code Here

      throws OpsException {
    File ldifTempDir = target.createTempDir();
    File ldifTempFile = new File(ldifTempDir, "ldapmodify.ldif");
    FileUpload.upload(target, ldifTempFile, ldifCommands);
    try {
      Command command = Command.build(CMD_LDAP_MODIFY);

      if (add) {
        command.addLiteral("-a"); // Add
      }

      command.addLiteral("-x"); // Simple auth

      command.addLiteral("-D"); // Bind DN
      command.addQuoted(bindDN.toLdifEncoded());

      command.addLiteral("-w"); // Simple auth password
      command.addQuoted(password);

      command.addLiteral("-f"); // Command file
      command.addFile(ldifTempFile);

      target.executeCommand(command);
    } finally {
      target.rmdir(ldifTempDir);
    }
View Full Code Here

    Base, One, Sub, Children
  };

  public static List<LdifRecord> doLdapQuery(OpsTarget target, LdapDN bindDN, String ldapPassword,
      LdapDN searchBaseDN, String filter, SearchScope searchScope) throws OpsException {
    Command command = Command.build(CMD_LDAP_SEARCH);

    command.addLiteral("-LLL"); // Pure LDIF, no extra junk

    command.addLiteral("-x"); // Simple auth

    command.addLiteral("-D"); // Bind DN
    command.addQuoted(bindDN.toLdifEncoded());

    command.addLiteral("-w"); // Simple auth password
    command.addQuoted(ldapPassword);

    command.addLiteral("-b"); // Search base
    command.addQuoted(searchBaseDN.toLdifEncoded());

    command.addLiteral("-s"); // Scope
    command.addLiteral(searchScope.toString().toLowerCase());

    if (!Strings.isNullOrEmpty(filter)) {
      command.addQuoted(filter);
    }

    ProcessExecution processExecution = target.executeCommand(command);

    return LdifRecord.parse(processExecution.getStdOut());
View Full Code Here

  @Handler
  public void doOperation(OpsTarget target) throws OpsException {
    // TODO: Make this idempotent
    LdifRecord configLdif;
    {
      Command ldapSearch = Command
          .build("ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config olcRootDN=cn=admin,cn=config dn olcRootDN olcRootPW");

      List<LdifRecord> ldifs = LdifRecord.parse(target.executeCommand(ldapSearch).getStdOut());
      if (ldifs.size() != 1) {
        throw new OpsException("Expected exactly one LDIF record for config");
      }
      configLdif = ldifs.get(0);
    }

    {
      StringBuilder modify = new StringBuilder();

      modify.append("dn: " + configLdif.getLdapDn().toString() + "\n");
      modify.append("replace: olcRootPW\n");
      modify.append("olcRootPW: " + LdapPasswords.getLdapPasswordEncoded(ldapSecret.plaintext()) + "\n");
      modify.append("\n");

      File tempDir = target.createTempDir();
      File modifyFile = new File(tempDir, "modifypw.ldif");
      FileUpload.upload(target, modifyFile, modify.toString());

      Command ldapModify = Command.build("ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f {0}", modifyFile);

      target.executeCommand(ldapModify);
    }

    ldap.writeLdapServerPassword(target, ldapSecret);
View Full Code Here

      // TODO: Do timestamp based dependency checking?
      rebuild = false;
    }

    if (rebuild) {
      Command mkisoCommand = Command.build("genisoimage -input-charset utf-8 -R -o {0}", iso);
      if (volumeLabel != null) {
        mkisoCommand.addLiteral("-V").addQuoted(volumeLabel);
      }
      mkisoCommand.addFile(srcDir);

      target.executeCommand(mkisoCommand);
    }
  }
View Full Code Here

  public Provider<String> bridgeName;

  @Handler
  public void handler(OpsTarget target) throws OpsException {
    if (OpsContext.isConfigure()) {
      Command findCommand = Command.build("/sbin/ifconfig {0}", interfaceName);
      boolean found = false;
      try {
        target.executeCommand(findCommand);
        found = true;
      } catch (ProcessExecutionException e) {
        ProcessExecution execution = e.getExecution();
        if (execution.getExitCode() == 1 && execution.getStdErr().contains("Device not found")) {
          found = false;
        } else {
          throw new OpsException("Error checking for interface", e);
        }
      }

      if (!found) {
        // This is actually idempotent, but I think it's scary to rely on it being so
        Command command = Command.build("/usr/sbin/tunctl -t {0}", interfaceName);
        target.executeCommand(command);
      }

      {
        // TODO: Safe to re-run?
        Command command = Command.build("ifconfig {0} up", interfaceName);
        target.executeCommand(command);
      }

      if (bridgeName != null) {
        // TODO: Safe to re-run?

        Command command = Command.build("brctl addif {0} {1}", bridgeName.get(), interfaceName);
        try {
          target.executeCommand(command);
        } catch (ProcessExecutionException e) {
          ProcessExecution execution = e.getExecution();
          if (execution.getExitCode() == 1 && execution.getStdErr().contains("already a member of a bridge")) {
View Full Code Here

      }
    };
  }

  private Command buildKvmCommand() {
    Command command = Command.build("/usr/bin/kvm");

    if (this.vnc != null) {
      InetSocketAddress vnc = this.vnc.get();
      if (vnc != null) {
        int port = vnc.getPort();
        int vncPort = port - 5900;
        command.addLiteral("-vnc");
        InetAddress address = vnc.getAddress();
        if (!address.isAnyLocalAddress()) {
          command.addQuoted(address.getHostAddress() + ":" + vncPort);
        } else {
          command.addQuoted("0.0.0.0:" + vncPort);
        }
      }
    }

    command.addLiteral("-m").addQuoted(Integer.toString(memoryMb));
    command.addLiteral("-smp").addQuoted(Integer.toString(vcpus));
    command.addLiteral("-name").addQuoted(id);
    // command.addLiteral("-nodefconfig");
    command.addLiteral("-nodefaults");
    command.addLiteral("-vga").addQuoted("cirrus");
    command.addLiteral("-usb");
    command.addLiteral("-readconfig").addFile(getDeviceConfigPath());

    if (!disableKvm) {
      command.addLiteral("-enable-kvm");
    }

    return command;
  }
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.