@Override
 protected void addCredentialsForInstance(NodeMetadataBuilder builder, RunningInstance instance) {
   LoginCredentials creds =
       LoginCredentials.fromCredentials(
           credentialStore.get("node#" + instance.getRegion() + "/" + instance.getId()));
   String spotRequestId = AWSRunningInstance.class.cast(instance).getSpotInstanceRequestId();
   if (creds == null && spotRequestId != null) {
     creds =
         LoginCredentials.fromCredentials(
             credentialStore.get("node#" + instance.getRegion() + "/" + spotRequestId));
     if (creds != null)
       credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), creds);
   }
   if (creds != null) builder.credentials(creds);
 }
  @Test(enabled = true)
  public void testShellAccess() throws IOException {
    final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
    serversToDeleteAfterTheTests.add(nameOfServer);

    Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
    Ip availableIp = Iterables.getLast(availableIps);

    Server createdServer =
        client
            .getServerServices()
            .addServer(
                nameOfServer, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "1", availableIp.getIp());
    assertNotNull(createdServer);
    assert serverLatestJobCompleted.apply(createdServer);

    // get server by name
    Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
    assert (response.size() == 1);
    createdServer = Iterables.getOnlyElement(response);

    Map<String, Credentials> credsMap = client.getServerServices().getServerCredentialsList();
    LoginCredentials instanceCredentials =
        LoginCredentials.fromCredentials(credsMap.get(createdServer.getName()));
    assertNotNull(instanceCredentials);

    HostAndPort socket = HostAndPort.fromParts(createdServer.getIp().getIp(), 22);

    Predicate<HostAndPort> socketOpen = retry(new InetSocketAddressConnect(), 180, 5, SECONDS);

    socketOpen.apply(socket);

    SshClient sshClient =
        gocontext
            .utils()
            .injector()
            .getInstance(SshClient.Factory.class)
            .create(socket, instanceCredentials);
    sshClient.connect();
    String output = sshClient.exec("df").getOutput();
    assertTrue(
        output.contains("Filesystem"),
        "The output should've contained filesystem information, but it didn't. Output: " + output);
    sshClient.disconnect();

    // check that the get credentials call is the same as this
    assertEquals(
        client.getServerServices().getServerCredentials(createdServer.getId()),
        instanceCredentials);

    try {
      assertEquals(client.getServerServices().getServerCredentials(Long.MAX_VALUE), null);
    } catch (AssertionError e) {
      e.printStackTrace();
    }

    // delete the server
    client.getServerServices().deleteByName(nameOfServer);
  }
Example #3
0
 @Override
 public NodeMetadata apply(Server from) {
   // convert the result object to a jclouds NodeMetadata
   NodeMetadataBuilder builder = new NodeMetadataBuilder();
   builder.ids(from.id + "");
   builder.name(from.name);
   builder.location(findLocationForServer.apply(from));
   builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.name));
   builder.imageId(from.imageId + "");
   Image image = findImageForServer.apply(from);
   if (image != null) builder.operatingSystem(image.getOperatingSystem());
   builder.hardware(findHardwareForServer.apply(from));
   builder.state(serverStatusToNodeState.get(from.status));
   builder.publicAddresses(ImmutableSet.<String>of(from.publicAddress));
   builder.privateAddresses(ImmutableSet.<String>of(from.privateAddress));
   builder.credentials(LoginCredentials.fromCredentials(credentialStore.get(from.id + "")));
   return builder.build();
 }
 protected void addCredentialsForInstance(NodeMetadataBuilder builder, RunningInstance instance) {
   builder.credentials(
       LoginCredentials.fromCredentials(
           credentialStore.get("node#" + instance.getRegion() + "/" + instance.getId())));
 }
Example #5
0
 @Override
 public SshClient create(IPSocket socket, Credentials credentials) {
   return create(socket, LoginCredentials.fromCredentials(credentials));
 }