コード例 #1
0
  // TODO use userData to do this, and make initbuilder an example for
  // something else.
  @BeforeTest
  void makeScript() {

    mkEbsBoot =
        new InitBuilder(
                "mkebsboot", // name of the script
                "/tmp", // working directory
                "/tmp/logs", // location of stdout.log and stderr.log
                ImmutableMap.of(
                    "imageDir", "/mnt/tmp", "ebsDevice", "/dev/sdh", "ebsMountPoint", "/mnt/ebs"),
                ImmutableList.<Statement>of(
                    Statements.interpret(
                        "echo creating a filesystem and mounting the ebs volume",
                        "{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}",
                        "rm -rf {varl}IMAGE_DIR{varr}/*",
                        "yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-",
                        "mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}",
                        "echo making a local working copy of the boot disk",
                        "rsync -ax --exclude /ubuntu/.bash_history --exclude /home/*/.bash_history --exclude /etc/ssh/ssh_host_* --exclude /etc/ssh/moduli --exclude /etc/udev/rules.d/*persistent-net.rules --exclude /var/lib/* --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* --exclude=/dev/log / {varl}IMAGE_DIR{varr}",
                        "echo preparing the local working copy",
                        "touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data",
                        "echo copying the local working copy to the ebs mount",
                        "{cd} {varl}IMAGE_DIR{varr}",
                        "tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}",
                        "echo size of ebs",
                        "du -sk {varl}EBS_MOUNT_POINT{varr}",
                        "echo size of source",
                        "du -sk {varl}IMAGE_DIR{varr}",
                        "rm -rf {varl}IMAGE_DIR{varr}/*",
                        "umount {varl}EBS_MOUNT_POINT{varr}",
                        "echo " + SCRIPT_END)))
            .render(OsFamily.UNIX);
  }
コード例 #2
0
 /** @deprecated since 0.7 */
 @Deprecated
 public static void mapSecurityGroupRuleToIpTables(
     ComputeService computeService,
     NodeMetadata node,
     LoginCredentials credentials,
     String networkInterface,
     Iterable<Integer> ports) {
   for (Integer port : ports) {
     String insertIptableRule =
         IptablesCommands.insertIptablesRule(
             Chain.INPUT, networkInterface, Protocol.TCP, port, Policy.ACCEPT);
     Statement statement = Statements.newStatementList(exec(insertIptableRule));
     ExecResponse response =
         computeService.runScriptOnNode(
             node.getId(), statement, overrideLoginCredentials(credentials).runAsRoot(false));
     if (response.getExitStatus() != 0) {
       String msg =
           String.format(
               "Cannot insert the iptables rule for port %d. Error: %s",
               port, response.getError());
       LOG.error(msg);
       throw new RuntimeException(msg);
     }
   }
 }
コード例 #3
0
 /** @deprecated since 0.7; see {@link IptablesCommands} */
 @Deprecated
 public static Statement authorizePortInIpTables(int port) {
   // TODO gogrid rules only allow ports 22, 3389, 80 and 443.
   // the first rule will be ignored, so we have to apply this
   // directly
   return Statements.newStatementList( // just in case iptables are being used, try to open 8080
       exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"), //
       exec("iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport " + port + " -j ACCEPT"), //
       exec("iptables-save"));
 }
コード例 #4
0
ファイル: InitBuilderTest.java プロジェクト: rintcius/jclouds
 @Test
 public void testBuildEBS() throws MalformedURLException, IOException {
   assertEquals(
       new InitBuilder(
               "mkebsboot", // name of the script
               "/tmp", // working directory
               "/tmp/logs", // location of stdout.log and stderr.log
               ImmutableMap.of(
                   "IMAGE_DIR",
                   "/mnt/tmp",
                   "EBS_DEVICE",
                   "/dev/sdh",
                   "EBS_MOUNT_POINT",
                   "/mnt/ebs"), // variables
               // used
               // inside
               // of
               // the
               // script
               ImmutableList.<Statement>of(
                   Statements.interpret(
                       "echo creating a filesystem and mounting the ebs volume", // what
                       // to
                       // execute
                       "{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}",
                       "rm -rf {varl}IMAGE_DIR{varr}/*",
                       "yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-",
                       "mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}",
                       "echo making a local working copy of the boot disk",
                       "rsync -ax --exclude /ubuntu/.bash_history --exclude /home/*/.bash_history --exclude /etc/ssh/ssh_host_* --exclude /etc/ssh/moduli --exclude /etc/udev/rules.d/*persistent-net.rules --exclude /var/lib/ec2/* --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* --exclude=/dev/log / {varl}IMAGE_DIR{varr}",
                       "echo preparing the local working copy",
                       "touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data",
                       "echo copying the local working copy to the ebs mount",
                       "{cd} {varl}IMAGE_DIR{varr}",
                       "tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}",
                       "echo size of ebs",
                       "du -sk {varl}EBS_MOUNT_POINT{varr}",
                       "echo size of source",
                       "du -sk {varl}IMAGE_DIR{varr}",
                       "rm -rf {varl}IMAGE_DIR{varr}/*",
                       "umount {varl}EBS_MOUNT_POINT{varr}",
                       "echo ----COMPLETE----")))
           .render(OsFamily.UNIX),
       Resources.toString(
           Resources.getResource("test_ebs." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8));
 }
コード例 #5
0
  public void testStartCCInstance() throws Exception {

    Template template =
        view.getComputeService()
            .templateBuilder()
            .fromHardware(EC2HardwareBuilder.cc2_8xlarge().build())
            .osFamily(OsFamily.AMZN_LINUX)
            .build();
    assert template != null : "The returned template was null, but it should have a value.";
    assertEquals(template.getHardware().getProviderId(), InstanceType.CC2_8XLARGE);
    assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
    assertEquals(template.getImage().getUserMetadata().get("virtualizationType"), "hvm");
    assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen");

    template
        .getOptions()
        .runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK()));

    String group = PREFIX + "cccluster";
    view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
    // TODO make this not lookup an explicit region
    client
        .getPlacementGroupApi()
        .get()
        .deletePlacementGroupInRegion(null, "jclouds#" + group + "#us-east-1");

    try {
      Set<? extends NodeMetadata> nodes =
          view.getComputeService().createNodesInGroup(group, 1, template);
      NodeMetadata node = getOnlyElement(nodes);

      getOnlyElement(
          getOnlyElement(
              client.getInstanceApi().get().describeInstancesInRegion(null, node.getProviderId())));

    } catch (RunNodesException e) {
      System.err.println(e.getNodeErrors().keySet());
      Throwables.propagate(e);
    } finally {
      view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
    }
  }
コード例 #6
0
  /** ssh client is initialized through this call. */
  protected ExecResponse doCall() {
    try {
      ssh.put(initFile, init.render(OsFamily.UNIX));
    } catch (SshException e) {
      // If there's a problem with the sftp configuration, we can try via ssh exec
      if (logger.isTraceEnabled())
        logger.warn(
            e,
            "<< (%s) problem using sftp [%s], attempting via sshexec",
            ssh.toString(),
            e.getMessage());
      else
        logger.warn(
            "<< (%s) problem using sftp [%s], attempting via sshexec",
            ssh.toString(), e.getMessage());
      ssh.disconnect();
      ssh.connect();
      ssh.exec("rm " + initFile);
      ssh.exec(
          Statements.appendFile(
                  initFile,
                  Splitter.on('\n').split(init.render(OsFamily.UNIX)),
                  AppendFile.MARKER + "_" + init.getInstanceName())
              .render(OsFamily.UNIX));
    }

    ssh.exec("chmod 755 " + initFile);
    setupLinkToInitFile();

    runAction("init");
    init.getInitStatement()
        .accept(
            new AdminAccessVisitor() {

              @Override
              public void visit(AdminAccess input) {
                refreshSshIfNewAdminCredentialsConfigured(input);
              }
            });
    return runAction("start");
  }
コード例 #7
0
 protected String exec(final String nodeId, String command) {
   return exec(nodeId, Statements.exec(command));
 }
コード例 #8
0
 protected static Template addRunScriptToTemplate(Template template) {
   template
       .getOptions()
       .runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK()));
   return template;
 }
コード例 #9
0
 private static Statement asFileStatement(String path, Configuration configuration) {
   return Statements.appendFile(path, asYamlLines(configuration.subset(ES_PREFIX)));
 }