use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.
the class RunImagePortsTab method onAddPort.
private SelectionListener onAddPort(final CheckboxTableViewer exposedPortsTableViewer) {
return SelectionListener.widgetSelectedAdapter(e -> {
final ContainerPortDialog dialog = new ContainerPortDialog(getShell());
dialog.create();
if (dialog.open() == IDialogConstants.OK_ID) {
final ExposedPortModel port = dialog.getPort();
model.addAvailablePort(port);
model.getSelectedPorts().add(port);
port.setSelected(true);
exposedPortsTableViewer.setChecked(port, true);
updateLaunchConfigurationDialog();
}
});
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.
the class RunImagePortsTab method onEditPort.
private SelectionListener onEditPort(final CheckboxTableViewer exposedPortsTableViewer) {
return SelectionListener.widgetSelectedAdapter(e -> {
final IStructuredSelection selection = exposedPortsTableViewer.getStructuredSelection();
final ExposedPortModel selectedContainerPort = (ExposedPortModel) selection.getFirstElement();
final ContainerPortDialog dialog = new ContainerPortDialog(getShell(), selectedContainerPort);
dialog.create();
if (dialog.open() == IDialogConstants.OK_ID) {
final ExposedPortModel configuredPort = dialog.getPort();
selectedContainerPort.setContainerPort(configuredPort.getContainerPort());
selectedContainerPort.setHostAddress(configuredPort.getHostAddress());
selectedContainerPort.setHostPort(configuredPort.getHostPort());
}
updateLaunchConfigurationDialog();
});
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.
the class ImageRun method getDockerContainerConfig.
public DockerContainerConfig getDockerContainerConfig() {
final ImageRunSelectionModel selectionModel = this.imageRunSelectionPage.getModel();
final ImageRunResourceVolumesVariablesModel resourcesModel = this.imageRunResourceVolumesPage.getModel();
final Builder config = new DockerContainerConfig.Builder().cmd(selectionModel.getCommand()).entryPoint(selectionModel.getEntrypoint()).image(selectionModel.getSelectedImageName()).tty(selectionModel.isAllocatePseudoTTY()).openStdin(selectionModel.isInteractiveMode());
if (resourcesModel.isEnableResourceLimitations()) {
// memory limit must be converted from MB to bytes
config.memory(resourcesModel.getMemoryLimit() * MB);
config.cpuShares(resourcesModel.getCpuShareWeight());
}
// environment variables
final List<String> environmentVariables = new ArrayList<>();
for (Iterator<EnvironmentVariableModel> iterator = resourcesModel.getEnvironmentVariables().iterator(); iterator.hasNext(); ) {
final EnvironmentVariableModel var = iterator.next();
// $NON-NLS-1$
environmentVariables.add(var.getName() + "=" + var.getValue());
}
config.env(environmentVariables);
// container labels
final Map<String, String> labelVariables = new HashMap<>();
for (Iterator<LabelVariableModel> iterator = resourcesModel.getLabelVariables().iterator(); iterator.hasNext(); ) {
final LabelVariableModel var = iterator.next();
// $NON-NLS-1$
labelVariables.put(var.getName(), var.getValue());
}
config.labels(labelVariables);
if (!selectionModel.isPublishAllPorts()) {
final Set<String> exposedPorts = new HashSet<>();
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;
}
exposedPorts.add(exposedPort.getContainerPort() + exposedPort.getPortType());
}
config.exposedPorts(exposedPorts);
}
return config.build();
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.
the class ImageRunSelectionPage method setDefaultValues.
/**
* Sets the default values from the optional given {@link IDockerImage} and
* {@link ILaunchConfiguration} elements
*/
private void setDefaultValues() {
final IDockerImage selectedImage = model.getSelectedImage();
if (selectedImage == null) {
return;
}
final IDockerImageInfo selectedImageInfo = getImageInfo(selectedImage);
// skip if a previous launch configuration was provided
if (this.lastLaunchConfiguration != null) {
try {
this.model.setContainerName(lastLaunchConfiguration.getAttribute(CONTAINER_NAME, ""));
this.model.setEntrypoint(lastLaunchConfiguration.getAttribute(ENTRYPOINT, ""));
this.model.setCommand(lastLaunchConfiguration.getAttribute(COMMAND, ""));
this.model.setPublishAllPorts(lastLaunchConfiguration.getAttribute(PUBLISH_ALL_PORTS, false));
final List<String> exposedPortInfos = lastLaunchConfiguration.getAttribute(PUBLISHED_PORTS, Collections.<String>emptyList());
// by the user.
if (selectedImageInfo != null) {
final List<ExposedPortModel> exposedPorts = ExposedPortModel.fromStrings(selectedImageInfo.config().exposedPorts());
model.setExposedPorts(exposedPorts);
final List<ExposedPortModel> selectedExposedPorts = ExposedPortModel.fromStrings(exposedPortInfos);
this.model.setSelectedPorts(new HashSet<>(selectedExposedPorts));
}
// links
this.model.setLinks(lastLaunchConfiguration.getAttribute(LINKS, Collections.<String>emptyList()));
// other options
this.model.setRemoveWhenExits(lastLaunchConfiguration.getAttribute(AUTO_REMOVE, false));
this.model.setInteractiveMode(lastLaunchConfiguration.getAttribute(INTERACTIVE, false));
this.model.setAllocatePseudoTTY(lastLaunchConfiguration.getAttribute(ALLOCATE_PSEUDO_CONSOLE, false));
this.model.setPrivileged(lastLaunchConfiguration.getAttribute(PRIVILEGED, false));
this.model.setBasicSecurity(lastLaunchConfiguration.getAttribute(READONLY, false));
} catch (CoreException e) {
Activator.log(e);
}
} else {
applyImageInfo(selectedImageInfo);
}
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.
the class ImageRunSelectionPage method onRemovePorts.
private SelectionListener onRemovePorts(final TableViewer portsTableViewer) {
return SelectionListener.widgetSelectedAdapter(e -> {
final IStructuredSelection selection = portsTableViewer.getStructuredSelection();
for (@SuppressWarnings("unchecked") Iterator<ExposedPortModel> iterator = selection.iterator(); iterator.hasNext(); ) {
final ExposedPortModel port = iterator.next();
model.removeAvailablePort(port);
model.getSelectedPorts().remove(port);
}
});
}
Aggregations