/** * Creates a {@link SSHSession} to the given host. * * @param host hostname to ssh to * @return a new {@link SSHSession} * @throws IOException if failed to create a new session to the host */ default SSHSession createSSHSession(SSHKeyPair keyPair, String host) throws IOException { return createSSHSession(keyPair.getPublicKey().getUser(), keyPair.getPrivateKeySupplier(), host, 22, Collections.emptyMap()); }
@Override public Cluster execute(Cluster cluster) throws Exception { Cluster nextCluster = provisioner.createCluster(provisionerContext); // Add the ssh user property to the resulting Cluster if SSHKeyPair is present in the context return provisionerContext.getSSHContext().getSSHKeyPair() .map(sshKeyPair -> { Map<String, String> properties = new HashMap<>(nextCluster.getProperties()); properties.put(Constants.RuntimeMonitor.SSH_USER, sshKeyPair.getPublicKey().getUser()); return new Cluster(nextCluster.getName(), nextCluster.getStatus(), nextCluster.getNodes(), properties); }) .orElse(nextCluster); } }
@Override public Cluster execute(Cluster cluster) throws Exception { Cluster nextCluster = provisioner.createCluster(provisionerContext); // Add the ssh user property to the resulting Cluster if SSHKeyPair is present in the context return provisionerContext.getSSHContext().getSSHKeyPair() .map(sshKeyPair -> { Map<String, String> properties = new HashMap<>(nextCluster.getProperties()); properties.put(Constants.RuntimeMonitor.SSH_USER, sshKeyPair.getPublicKey().getUser()); return new Cluster(nextCluster.getName(), nextCluster.getStatus(), nextCluster.getNodes(), properties); }) .orElse(nextCluster); } }
/** * Creates a {@link SSHConfig} for ssh to the master node of the given {@link Cluster}. * * @param cluster the cluster information * @param keysDir the {@link Location} that contains the ssh keys * @return a {@link SSHConfig} */ private SSHConfig createSSHConfig(Cluster cluster, Location keysDir) { // Loads the SSH keys SSHKeyPair sshKeyPair = createSSHKeyPair(keysDir, cluster); Node masterNode = cluster.getNodes().stream() .filter(node -> node.getType() == Node.Type.MASTER) .findFirst().orElseThrow( () -> new IllegalArgumentException("Missing master node information for the cluster " + cluster.getName())); // Creates and return the twill preparer return SSHConfig.builder(masterNode.getIpAddress()) .setUser(sshKeyPair.getPublicKey().getUser()) .setPrivateKeySupplier(sshKeyPair.getPrivateKeySupplier()) .build(); } }
/** * Creates a {@link SSHConfig} for ssh to the master node of the given {@link Cluster}. * * @param cluster the cluster information * @param keysDir the {@link Location} that contains the ssh keys * @return a {@link SSHConfig} */ private SSHConfig createSSHConfig(Cluster cluster, Location keysDir) { // Loads the SSH keys SSHKeyPair sshKeyPair = createSSHKeyPair(keysDir, cluster); Node masterNode = cluster.getNodes().stream() .filter(node -> node.getType() == Node.Type.MASTER) .findFirst().orElseThrow( () -> new IllegalArgumentException("Missing master node information for the cluster " + cluster.getName())); // Creates and return the twill preparer return SSHConfig.builder(masterNode.getIpAddress()) .setUser(sshKeyPair.getPublicKey().getUser()) .setPrivateKeySupplier(sshKeyPair.getPrivateKeySupplier()) .build(); } }
if (publicKey != null) { metadata.put("ssh-keys", publicKey.getUser() + ":" + publicKey.getKey());