Exemplo n.º 1
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);
     }
   }
 }
Exemplo n.º 2
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"));
 }
  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));
    }
  }
 protected static Template addRunScriptToTemplate(Template template) {
   template
       .getOptions()
       .runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK()));
   return template;
 }