Search in sources :

Example 1 with ContainerLinkModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.

the class RunImageLinksTab method onRemoveLinks.

private SelectionListener onRemoveLinks(final TableViewer linksTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final IStructuredSelection selection = linksTableViewer.getStructuredSelection();
        for (@SuppressWarnings("unchecked") Iterator<ContainerLinkModel> iterator = selection.iterator(); iterator.hasNext(); ) {
            model.removeLink(iterator.next());
        }
        updateLaunchConfigurationDialog();
    });
}
Also used : ContainerLinkModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with ContainerLinkModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.

the class RunImageLinksTab method onEditLink.

private SelectionListener onEditLink(final TableViewer linksTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final IStructuredSelection selection = linksTableViewer.getStructuredSelection();
        final ContainerLinkModel selectedContainerLink = (ContainerLinkModel) selection.getFirstElement();
        final ContainerLinkDialog dialog = new ContainerLinkDialog(getShell(), model.getSelectedConnection(), selectedContainerLink);
        dialog.create();
        if (dialog.open() == IDialogConstants.OK_ID) {
            selectedContainerLink.setContainerName(dialog.getContainerName());
            selectedContainerLink.setContainerAlias(dialog.getContainerAlias());
            linksTableViewer.refresh();
            updateLaunchConfigurationDialog();
        }
    });
}
Also used : ContainerLinkModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ContainerLinkDialog(org.eclipse.linuxtools.internal.docker.ui.wizards.ContainerLinkDialog)

Example 3 with ContainerLinkModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.

the class ImageRun method getDockerHostConfig.

public IDockerHostConfig getDockerHostConfig() {
    final ImageRunSelectionModel selectionModel = this.imageRunSelectionPage.getModel();
    final ImageRunResourceVolumesVariablesModel resourcesModel = this.imageRunResourceVolumesPage.getModel();
    final ImageRunNetworkModel networkModel = this.imageRunNetworkPage.getModel();
    final DockerHostConfig.Builder hostConfigBuilder = new DockerHostConfig.Builder();
    if (selectionModel.isPublishAllPorts()) {
        hostConfigBuilder.publishAllPorts(true);
    } else {
        final Map<String, List<IDockerPortBinding>> portBindings = new HashMap<>();
        for (Iterator<ExposedPortModel> iterator = selectionModel.getExposedPorts().iterator(); iterator.hasNext(); ) {
            final ExposedPortModel exposedPort = iterator.next();
            // only selected Ports in the CheckboxTableViewer are exposed.
            if (!selectionModel.getSelectedPorts().contains(exposedPort)) {
                continue;
            }
            final DockerPortBinding portBinding = new DockerPortBinding(exposedPort.getHostAddress(), exposedPort.getHostPort());
            portBindings.put(exposedPort.getContainerPort() + exposedPort.getPortType(), Arrays.<IDockerPortBinding>asList(portBinding));
        }
        hostConfigBuilder.portBindings(portBindings);
    }
    // container links
    final List<String> links = new ArrayList<>();
    for (Iterator<ContainerLinkModel> iterator = selectionModel.getLinks().iterator(); iterator.hasNext(); ) {
        final ContainerLinkModel link = iterator.next();
        links.add(link.getContainerName() + ':' + link.getContainerAlias());
    }
    hostConfigBuilder.links(links);
    // data volumes
    final List<String> volumesFrom = new ArrayList<>();
    final List<String> binds = new ArrayList<>();
    for (Iterator<DataVolumeModel> iterator = resourcesModel.getDataVolumes().iterator(); iterator.hasNext(); ) {
        final DataVolumeModel dataVolume = iterator.next();
        // included.
        if (!resourcesModel.getSelectedDataVolumes().contains(dataVolume)) {
            continue;
        }
        switch(dataVolume.getMountType()) {
            case HOST_FILE_SYSTEM:
                String bind = LaunchConfigurationUtils.convertToUnixPath(dataVolume.getHostPathMount()) + ':' + dataVolume.getContainerPath() + // $NON-NLS-1$ //$NON-NLS-2$
                ":Z";
                if (dataVolume.isReadOnly()) {
                    // $NON-NLS-1$
                    bind += ",ro";
                }
                binds.add(bind);
                break;
            case CONTAINER:
                volumesFrom.add(dataVolume.getContainerMount());
                break;
            default:
                break;
        }
    }
    hostConfigBuilder.binds(binds);
    hostConfigBuilder.volumesFrom(volumesFrom);
    hostConfigBuilder.privileged(selectionModel.isPrivileged());
    // make /tmp and /run use tmpfs, and drop all capabilities
    if (selectionModel.isBasicSecurity()) {
        hostConfigBuilder.readonlyRootfs(true);
        Map<String, String> tmpfsValues = new HashMap<>();
        // $NON-NLS-1$ //$NON-NLS-2$
        tmpfsValues.put("/run", "rw,exec");
        // $NON-NLS-1$ //$NON-NLS-2$
        tmpfsValues.put("/tmp", "rw,exec");
        hostConfigBuilder.tmpfs(tmpfsValues);
        List<String> capDropList = new ArrayList<>();
        // $NON-NLS-1$
        capDropList.add("all");
        hostConfigBuilder.capDrop(capDropList);
    }
    if (selectionModel.isUnconfined()) {
        List<String> seccomp = new ArrayList<>();
        // $NON-NLS-1$
        seccomp.add("seccomp:unconfined");
        hostConfigBuilder.securityOpt(seccomp);
    }
    String networkMode = networkModel.getNetworkModeString();
    // if network mode is not default, set it in host config
    if (networkMode != null && !networkMode.equals(ImageRunNetworkModel.DEFAULT_MODE))
        hostConfigBuilder.networkMode(networkMode);
    // memory constraints (in bytes)
    if (resourcesModel.isEnableResourceLimitations()) {
        hostConfigBuilder.memory(resourcesModel.getMemoryLimit() * MB);
        hostConfigBuilder.cpuShares(resourcesModel.getCpuShareWeight());
    }
    return hostConfigBuilder.build();
}
Also used : IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) DockerHostConfig(org.eclipse.linuxtools.internal.docker.core.DockerHostConfig) ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) HashMap(java.util.HashMap) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder) ArrayList(java.util.ArrayList) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) DockerPortBinding(org.eclipse.linuxtools.internal.docker.core.DockerPortBinding) ContainerLinkModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ContainerLinkModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.

the class ImageRunSelectionPage method onEditLink.

private SelectionListener onEditLink(final TableViewer linksTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final IStructuredSelection selection = linksTableViewer.getStructuredSelection();
        final ContainerLinkModel selectedContainerLink = (ContainerLinkModel) selection.getFirstElement();
        final ContainerLinkDialog dialog = new ContainerLinkDialog(getShell(), model.getSelectedConnection(), selectedContainerLink);
        dialog.create();
        if (dialog.open() == IDialogConstants.OK_ID) {
            selectedContainerLink.setContainerName(dialog.getContainerName());
            selectedContainerLink.setContainerAlias(dialog.getContainerAlias());
            linksTableViewer.refresh();
        }
    });
}
Also used : ContainerLinkModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

ContainerLinkModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)1 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)1 Builder (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder)1 DockerHostConfig (org.eclipse.linuxtools.internal.docker.core.DockerHostConfig)1 DockerPortBinding (org.eclipse.linuxtools.internal.docker.core.DockerPortBinding)1 ContainerLinkDialog (org.eclipse.linuxtools.internal.docker.ui.wizards.ContainerLinkDialog)1 ExposedPortModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)1