Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command$Argument


            TimeSpan.FIVE_MINUTES));
        break;
      }

      case DiskRaw: {
        Command expand = Command.build("gunzip -c {0} | cp --sparse=always /proc/self/fd/0 {1}", rawImage,
            imageFile);
        target.executeCommand(expand.setTimeout(TimeSpan.FIVE_MINUTES));
        break;
      }

      case DiskQcow2: {
        Command expand = Command.build("cp {0} {1}", rawImage, imageFile);
        target.executeCommand(expand.setTimeout(TimeSpan.FIVE_MINUTES));
        break;
      }

      default:
        throw new OpsException("Unknown image format: " + imageFormat);
View Full Code Here


  public URI getUrl() {
    return url;
  }

  public CurlResult executeRequest(OpsTarget target) throws OpsException {
    Command command = toCommand();

    ProcessExecution execution = target.executeCommand(command);

    return parseResponse(execution);
  }
View Full Code Here

      escaped.add("%{" + tag + "}");
    }

    String format = metadataDelimiter.replace("\n", "\\n") + Joiner.on("\\n").join(escaped);

    Command command = Command.build("curl");
    if (!bareRequest) {
      command.addLiteral("--include");
      command.addLiteral("--write-out");
      command.addQuoted(format);
    }

    if (proxy != null) {
      command.addLiteral("--proxy");
      command.addQuoted(proxy);
    }

    if (timeout != null) {
      command.addLiteral("--max-time");
      command.addQuoted(Long.toString(timeout.getTotalSeconds() + 1));
    }

    for (Entry<String, String> entry : headers.entries()) {
      command.addLiteral("-H");
      command.addQuoted(entry.getKey() + ": " + entry.getValue());
    }

    if (body != null) {
      command.addLiteral("--data");
      command.addQuoted(body);
    }

    if (bodyFromStdin) {
      command.addLiteral("--data-binary");
      command.addLiteral("@-");
    }

    if (method != null) {
      command.addLiteral("--request");
      command.addQuoted(method);
    }

    command.addQuoted(getUrl().toString());
    return command;
  }
View Full Code Here

  }

  public void changePassword(Secret newPassword) throws OpsException {
    OpsTarget target = getOpsTarget();

    Command command = Command.build("mysqladmin");
    command.addQuoted("--user=", username);
    command.addQuoted("--host=", hostname);
    command.addQuoted("--password=", password);
    command.addLiteral("password");
    command.addQuoted(newPassword);

    target.executeCommand(command);

    password = newPassword;
  }
View Full Code Here

  }

  public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
    OpsTarget target = getOpsTarget();

    Command command = Command.build("mysql");
    command.addQuoted("--user=", username);
    command.addQuoted("--host=", hostname);
    command.addQuoted("--password=", password);

    command.addArgument(Argument.buildQuoted("--execute=", sql).setMasked("--execute=" + Command.MASKED));

    return target.executeCommand(command);
  }
View Full Code Here

    }
    glanceUploadUrl += "images";

    String imageName = "image-" + System.currentTimeMillis();

    Command command = Command.build("curl");
    command.addLiteral("--fail");
    command.addLiteral("--upload-file").addFile(imageFile);
    command.addLiteral("-X").addLiteral("POST");

    command.addLiteral("-H").addQuoted("X-Auth-Token: " + tokenId);

    command.addLiteral("-H").addQuoted("Content-Type: application/octet-stream");
    command.addLiteral("-H").addQuoted("X-Image-Meta-Name: " + imageName);
    command.addLiteral("-H").addQuoted("X-Image-Meta-Is-Public: True");

    // if (isQcow2) {
    // command.addLiteral("-H").addQuoted("X-Image-Meta-Disk-Format: qcow2");
    // } else {
    if (diskFormat != null) {
      command.addLiteral("-H").addQuoted("X-Image-Meta-Disk-Format: " + diskFormat);
    }

    command.addLiteral("-H").addQuoted("X-Image-Meta-Container-Format: bare");
    // }
    // command.addLiteral("-H").addQuoted("X-Image-Meta-Min-Disk: 0");
    // command.addLiteral("-H").addQuoted("X-Image-Meta-Min-Ram: 0");
    // command.addLiteral("-H").addQuoted("X-Image-Meta-Image-Size: " + rawImageFileSize);
    command.addLiteral("-H").addQuoted("X-Image-Meta-Size: " + rawImageFileSize);

    // image_meta = {'name': fields.pop('name'),
    // 'is_public': utils.bool_from_string(
    // fields.pop('is_public', False)),
    // 'disk_format': fields.pop('disk_format', 'raw'),
    // 'min_disk': fields.pop('min_disk', 0),
    // 'min_ram': fields.pop('min_ram', 0),
    // 'container_format': fields.pop('container_format', 'ovf')}

    // glance add name=DebianSqueeze is_public=True disk_format=raw container_format=bare
    // system_id="http://org.platformlayer/service/imagefactory/v1.0:bootstrap"
    // image_size="${RAW_SIZE}" < disk.raw.gz

    command.addQuoted(glanceUploadUrl);
    command.setTimeout(TimeSpan.FIFTEEN_MINUTES);

    ProcessExecution execution = target.executeCommand(command);

    String imageId;
    // String imageLocation;
View Full Code Here

  public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
    OpsTarget target = getOpsTarget();

    // We probably want psql -A -t -c "command"

    Command command = Command.build("psql");
    command.addQuoted("--username=", username);
    command.addQuoted("--host=", hostname);

    command.addArgument(Argument.buildQuoted("--command=", sql).setMasked("--command=" + Command.MASKED));

    CommandEnvironment env = new CommandEnvironment();
    env.put("PGPASSWORD", password.plaintext());

    command.setEnvironment(env);
    return target.executeCommand(command);
  }
View Full Code Here

    return transport;
  }

  @Override
  public Command buildIptablesAddCommand() {
    Command command = SimpleIptablesRules.buildCommand(transport, chain);
    command.addLiteral(ruleSpec);
    return command;
  }
View Full Code Here

  public String localPrivateAddress;

  @Handler
  public void handler(OpsTarget target) throws OpsException {
    // ip tunnel add netb mode gre remote 184.173.172.26 local 209.105.243.38 ttl 255
    Command addTunnel = Command.build("ip tunnel add {0} mode gre remote {1} local {2} ttl 255", tunnelName,
        remoteTunnelAddress, localTunnelAddress);
    target.executeCommand(addTunnel);

    // ip addr add fdfd:fdfd:fdfd:1::/64 dev netb
    Command tunnelAddAddress = Command.build("ip addr add {0} dev {1}", localPrivateAddress, tunnelName);
    target.executeCommand(tunnelAddAddress);

    // ip route add fdfd:fdfd:fdfd:1::/64 dev netb
    Command tunnelAddRoute = Command.build("ip route add {0} dev {1}", remotePrivateNetwork, tunnelName);
    target.executeCommand(tunnelAddRoute);

    Command tunnelUp = Command.build("ip link set {0} up", tunnelName);
    target.executeCommand(tunnelUp);
  }
View Full Code Here

    return command;
  }

  @Override
  public Command buildIptablesDeleteCommand() {
    Command command = SimpleIptablesRules.buildCommand(transport, chain);
    command.addLiteral(convertToDeleteSpec());
    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.