Search in sources :

Example 6 with UnixSocketConnectionSettings

use of org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings in project linuxtools by eclipse.

the class DockerConnectionManager method reloadConnections.

public void reloadConnections() {
    this.connections = connectionStorageManager.loadConnections();
    for (IDockerConnection connection : connections) {
        notifyListeners(connection, IDockerConnectionManagerListener.ADD_EVENT);
    }
    List<IDockerConnectionSettings> settings = connectionSettingsFinder.getKnownConnectionSettings();
    for (IDockerConnectionSettings setting : settings) {
        if (setting != null) {
            IDockerConnection conn;
            if (setting.getType().equals(BindingType.UNIX_SOCKET_CONNECTION)) {
                UnixSocketConnectionSettings usetting = (UnixSocketConnectionSettings) setting;
                conn = new DockerConnection.Builder().name(usetting.getName()).unixSocketConnection(usetting);
            } else {
                TCPConnectionSettings tsetting = (TCPConnectionSettings) setting;
                conn = new DockerConnection.Builder().name(tsetting.getName()).tcpConnection(tsetting);
            }
            // add the connection but do not notify the listeners to avoid
            // flickering on the Docker Explorer view for each entry
            addConnection(conn, false);
        }
    }
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings)

Example 7 with UnixSocketConnectionSettings

use of org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings 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

UnixSocketConnectionSettings (org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings)7 Test (org.junit.Test)4 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)3 TCPConnectionSettings (org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings)3 File (java.io.File)2 IDockerConnectionSettings (org.eclipse.linuxtools.docker.core.IDockerConnectionSettings)2 IDockerConnectionStorageManager (org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager)2 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DockerConnectionManager (org.eclipse.linuxtools.docker.core.DockerConnectionManager)1 IDockerConnectionSettingsFinder (org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsFinder)1 DefaultDockerConnectionSettingsFinder (org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder)1 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)1