Search in sources :

Example 1 with DockerConnectionManager

use of org.eclipse.linuxtools.docker.core.DockerConnectionManager in project linuxtools by eclipse.

the class NewDockerConnectionPage method retrieveDefaultConnectionSettings.

/**
 * Sets the default settings by looking for the:
 * <ul>
 * <li>a Unix socket at /var/run/docker.sock</li>
 * <li>the following environment variables:
 * <ul>
 * <li>DOCKER_HOST</li>
 * <li>DOCKER_CERT_PATH</li>
 * <li>DOCKER_TLS_VERIFY</li>
 * </ul>
 * </li>
 * </ul>
 * and sets the default connection settings accordingly.
 */
private void retrieveDefaultConnectionSettings() {
    // progressbar
    try {
        getWizard().getContainer().run(true, true, monitor -> {
            monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.retrieveTask"), 1);
            final DockerConnectionManager dockerConnectionManager = DockerConnectionManager.getInstance();
            final IDockerConnectionSettings defaultConnectionSettings = dockerConnectionManager.findDefaultConnectionSettings();
            if (defaultConnectionSettings != null) {
                model.setCustomSettings(!defaultConnectionSettings.isSettingsResolved());
                model.setConnectionName(dockerConnectionManager.resolveConnectionName(defaultConnectionSettings));
                switch(defaultConnectionSettings.getType()) {
                    case TCP_CONNECTION:
                        final TCPConnectionSettings tcpConnectionSettings = (TCPConnectionSettings) defaultConnectionSettings;
                        model.setTcpConnectionBindingMode(true);
                        model.setTcpCertPath(tcpConnectionSettings.getPathToCertificates());
                        model.setTcpTLSVerify(tcpConnectionSettings.isTlsVerify());
                        model.setTcpHost(tcpConnectionSettings.getHost());
                        break;
                    case UNIX_SOCKET_CONNECTION:
                        model.setUnixSocketBindingMode(true);
                        final UnixSocketConnectionSettings unixSocketConnectionSettings = (UnixSocketConnectionSettings) defaultConnectionSettings;
                        model.setUnixSocketPath(unixSocketConnectionSettings.getPath());
                        break;
                }
            } else {
                // fall-back to custom settings, suggesting a
                // Unix Socket connection to the user.
                model.setCustomSettings(true);
                model.setUnixSocketBindingMode(true);
            }
            monitor.done();
        });
    } catch (InvocationTargetException | InterruptedException e) {
        Activator.log(e);
    }
}
Also used : IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) InvocationTargetException(java.lang.reflect.InvocationTargetException) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DockerConnectionManager (org.eclipse.linuxtools.docker.core.DockerConnectionManager)1 IDockerConnectionSettings (org.eclipse.linuxtools.docker.core.IDockerConnectionSettings)1 TCPConnectionSettings (org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings)1 UnixSocketConnectionSettings (org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings)1