コード例 #1
0
 protected Hardware parseHardware(RunningInstance instance) {
   Hardware in = super.parseHardware(instance);
   if (in == null) return null;
   AWSRunningInstance awsInstance = AWSRunningInstance.class.cast(instance);
   return HardwareBuilder.fromHardware(in)
       .hypervisor(awsInstance.getHypervisor().toString())
       .build();
 }
コード例 #2
0
  public void testNoSsh() throws Exception {

    Map<String, String> keyPair = ComputeTestUtils.setupKeyPair();

    AWSInstanceClient instanceClient =
        AWSEC2Client.class.cast(context.getApi()).getInstanceServices();

    String group = PREFIX + "unssh";
    computeContext.getComputeService().destroyNodesMatching(inGroup(group));

    TemplateOptions options = computeContext.getComputeService().templateOptions();

    options.authorizePublicKey(keyPair.get("public")).as(AWSEC2TemplateOptions.class);

    ComputeServiceContext noSshContext = null;
    try {
      noSshContext =
          new ComputeServiceContextFactory()
              .createContext(
                  provider, ImmutableSet.of(new Log4JLoggingModule()), setupProperties());

      Set<? extends NodeMetadata> nodes =
          noSshContext.getComputeService().createNodesInGroup(group, 1, options);

      NodeMetadata first = get(nodes, 0);
      assert first.getCredentials() != null : first;
      assert first.getCredentials().identity != null : first;
      assert first.getCredentials().credential == null : first;

      AWSRunningInstance instance = getInstance(instanceClient, first.getProviderId());

      assert instance.getSpotInstanceRequestId() != null : instance;
      assertEquals(instance.getKeyName(), "jclouds#" + group);

      Map<? extends NodeMetadata, ExecResponse> responses =
          computeContext
              .getComputeService()
              .runScriptOnNodesMatching(
                  runningInGroup(group),
                  exec("echo hello"),
                  overrideCredentialsWith(
                          new Credentials(first.getCredentials().identity, keyPair.get("private")))
                      .wrapInInitScript(false)
                      .runAsRoot(false));

      ExecResponse hello = getOnlyElement(responses.values());
      assertEquals(hello.getOutput().trim(), "hello");

    } finally {
      noSshContext.close();
      computeContext.getComputeService().destroyNodesMatching(inGroup(group));
    }
  }