Examples of SSHClient


Examples of org.jclouds.ssh.SshClient

      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();
      }
   }
View Full Code Here

Examples of org.jclouds.ssh.SshClient

   private void doCheckKey(RunningInstance newDetails) throws UnknownHostException {
      doCheckKey(newDetails.getIpAddress());
   }

   private void doCheckKey(String address) {
      SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22),
            LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build());
      try {
         ssh.connect();
         ExecResponse hello = ssh.exec("echo hello");
         assertEquals(hello.getOutput().trim(), "hello");
      } finally {
         if (ssh != null)
            ssh.disconnect();
      }
   }
View Full Code Here

Examples of org.jclouds.ssh.SshClient

            .render(OsFamily.UNIX);
   }

   @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 {
         ssh.connect();
      } catch (SshException e) {// try twice in case there is a network timeout
         try {
            Thread.sleep(10 * 1000);
         } catch (InterruptedException e1) {
         }
         ssh.connect();
      }
      try {
         System.out.printf("%d: %s writing ebs script%n", System.currentTimeMillis(), instance.getId());
         String script = "/tmp/mkebsboot-init.sh";
         ssh.put(script, Payloads.newStringPayload(mkEbsBoot));

         System.out.printf("%d: %s launching ebs script%n", System.currentTimeMillis(), instance.getId());
         ssh.exec("chmod 755 " + script);
         ssh.exec(script + " init");
         ExecResponse output = ssh.exec("sudo " + script + " start");
         System.out.println(output);
         output = ssh.exec(script + " status");

         assert !output.getOutput().trim().equals("") : output;
         Predicate<String> scriptTester = retry(new ScriptTester(ssh, SCRIPT_END), 600, 10, SECONDS);
         scriptTester.apply(script);
      } finally {
         if (ssh != null)
            ssh.disconnect();
      }
   }
View Full Code Here

Examples of org.jclouds.ssh.SshClient

   private void doCheckKey(RunningInstance newDetails) throws UnknownHostException {
      doCheckKey(newDetails.getIpAddress());
   }

   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();
      }
   }
View Full Code Here

Examples of org.jclouds.ssh.SshClient

   @Test(dependsOnMethods = "testCreateMachine")
   protected void testSsh() {
      String publicAddress = Iterables.find(machine.getIps(), not(InetAddresses2.IsPrivateIPAddress.INSTANCE));
      HostAndPort socket = HostAndPort.fromParts(publicAddress, 22);
      assertTrue(socketTester.apply(socket), socket.toString());
      SshClient api = context.utils().injector().getInstance(SshClient.Factory.class)
            .create(socket, LoginCredentials.builder().user("root").privateKey(key.get("private")).build());
      try {
         api.connect();
         ExecResponse exec = api.exec("echo hello");
         System.out.println(exec);
         assertEquals(exec.getOutput().trim(), "hello");
      } finally {
         if (api != null)
            api.disconnect();
      }
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.