Search in sources :

Example 1 with SSHShell

use of com.microsoft.azure.management.samples.SSHShell in project azure-sdk-for-java by Azure.

the class CreateVirtualMachineUsingCustomImageFromVHD method deprovisionAgentInLinuxVM.

/**
     * De-provision an Azure linux virtual machine.
     *
     * @param host the public host name
     * @param port the ssh port
     * @param userName the ssh user name
     * @param password the ssh user password
     */
protected static void deprovisionAgentInLinuxVM(String host, int port, String userName, String password) {
    SSHShell shell = null;
    try {
        System.out.println("Trying to de-provision: " + host);
        shell = SSHShell.open(host, port, userName, password);
        List<String> deprovisionCommand = new ArrayList<>();
        deprovisionCommand.add("sudo waagent -deprovision+user --force");
        String output = shell.runCommands(deprovisionCommand);
        System.out.println(output);
    } catch (JSchException jSchException) {
        System.out.println(jSchException.getMessage());
    } catch (IOException ioException) {
        System.out.println(ioException.getMessage());
    } catch (Exception exception) {
        System.out.println(exception.getMessage());
    } finally {
        if (shell != null) {
            shell.close();
        }
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SSHShell(com.microsoft.azure.management.samples.SSHShell) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 2 with SSHShell

use of com.microsoft.azure.management.samples.SSHShell in project azure-sdk-for-java by Azure.

the class CreateVirtualMachinesUsingCustomImageOrSpecializedVHD method deprovisionAgentInLinuxVM.

/**
     * De-provision an Azure linux virtual machine.
     *
     * @param host the public host name
     * @param port the ssh port
     * @param userName the ssh user name
     * @param password the ssh user password
     */
protected static void deprovisionAgentInLinuxVM(String host, int port, String userName, String password) {
    SSHShell shell = null;
    try {
        System.out.println("Trying to de-provision: " + host);
        shell = SSHShell.open(host, port, userName, password);
        List<String> deprovisionCommand = new ArrayList<>();
        deprovisionCommand.add("sudo waagent -deprovision+user --force");
        String output = shell.runCommands(deprovisionCommand);
        System.out.println(output);
    } catch (JSchException jSchException) {
        System.out.println(jSchException.getMessage());
    } catch (IOException ioException) {
        System.out.println(ioException.getMessage());
    } catch (Exception exception) {
        System.out.println(exception.getMessage());
    } finally {
        if (shell != null) {
            shell.close();
        }
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SSHShell(com.microsoft.azure.management.samples.SSHShell) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 3 with SSHShell

use of com.microsoft.azure.management.samples.SSHShell in project azure-sdk-for-java by Azure.

the class CreateVirtualMachineUsingCustomImageFromVM method deprovisionAgentInLinuxVM.

/**
     * De-provision an Azure linux virtual machine.
     *
     * @param host the public host name
     * @param port the ssh port
     * @param userName the ssh user name
     * @param password the ssh user password
     */
protected static void deprovisionAgentInLinuxVM(String host, int port, String userName, String password) {
    SSHShell shell = null;
    try {
        System.out.println("Trying to de-provision: " + host);
        shell = SSHShell.open(host, port, userName, password);
        List<String> deprovisionCommand = new ArrayList<>();
        deprovisionCommand.add("sudo waagent -deprovision+user --force");
        String output = shell.runCommands(deprovisionCommand);
        System.out.println(output);
    } catch (JSchException jSchException) {
        System.out.println(jSchException.getMessage());
    } catch (IOException ioException) {
        System.out.println(ioException.getMessage());
    } catch (Exception exception) {
        System.out.println(exception.getMessage());
    } finally {
        if (shell != null) {
            shell.close();
        }
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SSHShell(com.microsoft.azure.management.samples.SSHShell) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 4 with SSHShell

use of com.microsoft.azure.management.samples.SSHShell in project azure-sdk-for-java by Azure.

the class ManageManagedDisks method deprovisionAgentInLinuxVM.

private static void deprovisionAgentInLinuxVM(String host, int port, String userName, String password) {
    SSHShell shell = null;
    try {
        System.out.println("Trying to de-provision: " + host);
        shell = SSHShell.open(host, port, userName, password);
        List<String> deprovisionCommand = new ArrayList<>();
        deprovisionCommand.add("sudo waagent -deprovision+user --force");
        String output = shell.runCommands(deprovisionCommand);
        System.out.println(output);
    } catch (JSchException jSchException) {
        System.out.println(jSchException.getMessage());
    } catch (IOException ioException) {
        System.out.println(ioException.getMessage());
    } catch (Exception exception) {
        System.out.println(exception.getMessage());
    } finally {
        if (shell != null) {
            shell.close();
        }
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SSHShell(com.microsoft.azure.management.samples.SSHShell) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Aggregations

JSchException (com.jcraft.jsch.JSchException)4 SSHShell (com.microsoft.azure.management.samples.SSHShell)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4