SshClient ssh = sshFactory.create(HostAndPort.fromParts(vmIp, 22), LoginCredentials.builder().user(vmSshUsername).password(vmSshPassword).build());
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkArgument(node.getCredentials().credential != null || sshFactory.isAgentAvailable(), "no credential or ssh agent found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
factory.create(HostAndPort.fromParts("144.175.1.1", 22), LoginCredentials.builder().user("root").password("password1").build())).andReturn(client1); expect( factory.create(HostAndPort.fromParts("144.175.1.1", 22), LoginCredentials.builder().user("web").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client1New) .times(10); factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2) .times(4); expect( factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2New); expect( factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("foo").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client2Foo); expect( factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("romeo").build())).andThrow( new AuthorizationException("Auth fail", null)); factory.create(HostAndPort.fromParts("144.175.1.3", 22), LoginCredentials.builder().user("root").password("password3").build())).andReturn(client3) .times(2); expect( factory.create(HostAndPort.fromParts("144.175.1.4", 22), LoginCredentials.builder().user("root").password("password4").build())).andReturn(client4) .times(2); expect(
factory.create(HostAndPort.fromParts("144.175.1.1", 22), LoginCredentials.builder().user("root").password("password1").build())).andReturn(client1); expect( factory.create(HostAndPort.fromParts("144.175.1.1", 22), LoginCredentials.builder().user("web").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client1New) .times(10); factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2) .times(4); expect( factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2New); expect( factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("foo").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client2Foo); expect( factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("romeo").build())).andThrow( new AuthorizationException("Auth fail", null)); factory.create(HostAndPort.fromParts("144.175.1.3", 22), LoginCredentials.builder().user("root").password("password3").build())).andReturn(client3) .times(2); expect( factory.create(HostAndPort.fromParts("144.175.1.4", 22), LoginCredentials.builder().user("root").password("password4").build())).andReturn(client4) .times(2); expect(
SshClient connection; if (Strings.emptyToNull(sshKeyFile) != null) { connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser) .privateKey(Files.toString(new File(sshKeyFile), Charsets.UTF_8)).build()); } else { connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser).password(sshPass).build());
SshClient connection; if (Strings.emptyToNull(sshKeyFile) != null) { connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser) .privateKey(Files.toString(new File(sshKeyFile), Charsets.UTF_8)).build()); } else { connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser).password(sshPass).build());
SshClient connection; if (Strings.emptyToNull(sshKeyFile) != null) { connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser) .privateKey(Files.toString(new File(sshKeyFile), Charsets.UTF_8)).build()); } else { connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser).password(sshPass).build());
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") void testBundleInstance() { SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try {
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") void testBundleInstance() { SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try {
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance") void testReboot() throws InterruptedException, ExecutionException, TimeoutException, IOException { RunningInstance instance = getInstance(instanceId); System.out.printf("%d: %s rebooting instance %n", System.currentTimeMillis(), instanceId); client.getInstanceApi().get().rebootInstancesInRegion(null, instanceId); Thread.sleep(1000); instance = getInstance(instanceId); blockUntilWeCanSshIntoInstance(instance); SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse uptime = ssh.exec("uptime"); assert uptime.getOutput().indexOf("0 min") != -1 : "reboot didn't work: " + uptime; } finally { if (ssh != null) ssh.disconnect(); } }
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance") void testReboot() throws InterruptedException, ExecutionException, TimeoutException, IOException { RunningInstance instance = getInstance(instanceId); System.out.printf("%d: %s rebooting instance %n", System.currentTimeMillis(), instanceId); client.getInstanceServices().rebootInstancesInRegion(null, instanceId); Thread.sleep(1000); instance = getInstance(instanceId); blockUntilWeCanSshIntoInstance(instance); SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse uptime = ssh.exec("uptime"); assert uptime.getOutput().indexOf("0 min") != -1 : "reboot didn't work: " + uptime; } finally { if (ssh != null) ssh.disconnect(); } }
protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create( HostAndPort.fromParts(server.getVnc().getIp(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); System.err.println(ssh.exec("df -k").getOutput()); System.err.println(ssh.exec("mount").getOutput()); System.err.println(ssh.exec("uname -a").getOutput()); } finally { if (ssh != null) ssh.disconnect(); } }
protected void doConnectViaSsh(VirtualGuest guest, LoginCredentials creds) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(guest.getPrimaryIpAddress(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); System.err.println(ssh.exec("df -k").getOutput()); System.err.println(ssh.exec("mount").getOutput()); System.err.println(ssh.exec("uname -a").getOutput()); } finally { if (ssh != null) ssh.disconnect(); } }
protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create( HostAndPort.fromParts(server.getVnc().getIp(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); System.err.println(ssh.exec("df -k").getOutput()); System.err.println(ssh.exec("mount").getOutput()); System.err.println(ssh.exec("uname -a").getOutput()); } finally { if (ssh != null) ssh.disconnect(); } }
protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class) .create(HostAndPort.fromParts(server.getVnc().getIp(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); System.err.println(ssh.exec("df -k").getOutput()); System.err.println(ssh.exec("mount").getOutput()); System.err.println(ssh.exec("uname -a").getOutput()); } finally { if (ssh != null) ssh.disconnect(); } }
protected void checkSSH(HostAndPort socket) { socketTester.apply(socket); SshClient client = sshFactory.create(socket, loginCredentials); try { client.connect(); ExecResponse exec = client.exec("echo hello"); System.out.println(exec); assertEquals(exec.getOutput().trim(), "hello"); } finally { if (client != null) client.disconnect(); } }
protected SshjSshClient createClient(final Properties props) { Injector i = Guice.createInjector(module(), new AbstractModule() { @Override protected void configure() { bindProperties(binder(), props); } }, new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshjSshClient ssh = SshjSshClient.class.cast(factory.create(HostAndPort.fromParts("localhost", 22), LoginCredentials .builder().user("username").password("password").build())); return ssh; }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
protected void doConnectViaSsh(VirtualGuest guest, LoginCredentials creds) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(guest.getPrimaryIpAddress(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); System.err.println(ssh.exec("df -k").getOutput()); System.err.println(ssh.exec("mount").getOutput()); System.err.println(ssh.exec("uname -a").getOutput()); } finally { if (ssh != null) ssh.disconnect(); } }
public void testConfigureBindsClient() { Injector i = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection = factory.create(HostAndPort.fromParts("localhost", 22), LoginCredentials.builder().user("username") .password("password").build()); assert connection instanceof SshjSshClient; } }