@Test public void testPrintAccess() { final Instance instance = mock(Instance.class); when(instance.getPublicIp()).thenReturn("test-public-ip"); when(instance.getRoles()).thenReturn(ImmutableSet.of("test-role")); Cluster cluster = mock(Cluster.class); when(cluster.getInstances()).thenReturn(ImmutableSet.<Cluster.Instance>of(instance)); ClusterSpec spec = mock(ClusterSpec.class); when(spec.getClusterUser()).thenReturn("test-identity"); when(spec.getPrivateKeyFile()).thenReturn(new File("/test/key/path")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); Utils.printSSHConnectionDetails(ps, spec, cluster, 20); assertEquals("The ssh command did not match", EXPECTED_SSH_COMMAND, new String(baos.toByteArray())); }
public static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec, Cluster cluster, int maxPrint) { out.println("\nYou can log into instances using the following ssh commands:"); String user = clusterSpec.getClusterUser() != null ? clusterSpec .getClusterUser() : clusterSpec.getTemplate().getLoginUser(); String pkFile = clusterSpec.getPrivateKeyFile().getAbsolutePath(); int counter = 0; for (Instance instance : cluster.getInstances()) { StringBuilder roles = new StringBuilder(); for (String role : instance.getRoles()) { if (roles.length() != 0) { roles.append('+'); } roles.append(role); } out.printf( "[%s]: ssh -i %s -o \"UserKnownHostsFile /dev/null\" -o StrictHostKeyChecking=no %s@%s\n", roles.toString(), pkFile, user, instance.getPublicIp()); if (counter > maxPrint) { out.println("... Too many instances, truncating."); break; } counter++; } }
Utils { public static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec, Cluster cluster, int maxPrint) { out.println("\nYou can log into instances using the following ssh commands:"); String user = clusterSpec.getClusterUser() != null ? clusterSpec .getClusterUser() : clusterSpec.getTemplate().getLoginUser(); String pkFile = clusterSpec.getPrivateKeyFile().getAbsolutePath(); int counter = 0; for (Instance instance : cluster.getInstances()) { StringBuilder roles = new StringBuilder(); for (String role : instance.getRoles()) { if (roles.length() != 0) { roles.append('+'); } roles.append(role); } out.printf( "[%s]: ssh -i %s -o \"UserKnownHostsFile /dev/null\" -o StrictHostKeyChecking=no %s@%s\n", roles.toString(), pkFile, user, instance.getPublicIp()); if (counter > maxPrint) { out.println("... Too many instances, truncating."); break; } counter++; } } }
Utils { public static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec, Cluster cluster, int maxPrint) { out.println("\nYou can log into instances using the following ssh commands:"); String user = clusterSpec.getClusterUser() != null ? clusterSpec .getClusterUser() : clusterSpec.getTemplate().getLoginUser(); String pkFile = clusterSpec.getPrivateKeyFile().getAbsolutePath(); int counter = 0; for (Instance instance : cluster.getInstances()) { StringBuilder roles = new StringBuilder(); for (String role : instance.getRoles()) { if (roles.length() != 0) { roles.append('+'); } roles.append(role); } out.printf( "[%s]: ssh -i %s -o \"UserKnownHostsFile /dev/null\" -o StrictHostKeyChecking=no %s@%s\n", roles.toString(), pkFile, user, instance.getPublicIp()); if (counter > maxPrint) { out.println("... Too many instances, truncating."); break; } counter++; } }  }
Utils { public static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec, Cluster cluster, int maxPrint) { out.println("\nYou can log into instances using the following ssh commands:"); String user = clusterSpec.getClusterUser() != null ? clusterSpec .getClusterUser() : clusterSpec.getTemplate().getLoginUser(); String pkFile = clusterSpec.getPrivateKeyFile().getAbsolutePath(); int counter = 0; for (Instance instance : cluster.getInstances()) { StringBuilder roles = new StringBuilder(); for (String role : instance.getRoles()) { if (roles.length() != 0) { roles.append('+'); } roles.append(role); } out.printf( "[%s]: ssh -i %s -o \"UserKnownHostsFile /dev/null\" -o StrictHostKeyChecking=no %s@%s\n", roles.toString(), pkFile, user, instance.getPublicIp()); if (counter > maxPrint) { out.println("... Too many instances, truncating."); break; } counter++; } }  static LoadingCache<K, V> convertMapToLoadingCache(Map<K, V> in); static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec,
      Cluster cluster, int maxPrint); }
Utils { public static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec, Cluster cluster, int maxPrint) { out.println("\nYou can log into instances using the following ssh commands:"); String user = clusterSpec.getClusterUser() != null ? clusterSpec .getClusterUser() : clusterSpec.getTemplate().getLoginUser(); String pkFile = clusterSpec.getPrivateKeyFile().getAbsolutePath(); int counter = 0; for (Instance instance : cluster.getInstances()) { StringBuilder roles = new StringBuilder(); for (String role : instance.getRoles()) { if (roles.length() != 0) { roles.append('+'); } roles.append(role); } out.printf( "[%s]: ssh -i %s -o \"UserKnownHostsFile /dev/null\" -o StrictHostKeyChecking=no %s@%s\n", roles.toString(), pkFile, user, instance.getPublicIp()); if (counter > maxPrint) { out.println("... Too many instances, truncating."); break; } counter++; } }  static LoadingCache<K, V> convertMapToLoadingCache(Map<K, V> in); static void printSSHConnectionDetails(PrintStream out, ClusterSpec clusterSpec,
      Cluster cluster, int maxPrint);  }