Search in sources :

Example 6 with IDockerContainerConfig

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

the class ImageInspectContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    final Object propertyValue = ((Object[]) parentElement)[1];
    if (propertyValue instanceof IDockerContainerConfig) {
        final IDockerContainerConfig config = (IDockerContainerConfig) propertyValue;
        return new Object[] { // $NON-NLS-1$
        new Object[] { "Hostname", config.hostname() }, // $NON-NLS-1$
        new Object[] { "Domainname", config.domainname() }, // $NON-NLS-1$
        new Object[] { "User", config.user() }, new Object[] { "Memory", // $NON-NLS-1$
        LabelProviderUtils.toString(config.memory()) }, new Object[] { "MemorySwap", // $NON-NLS-1$
        LabelProviderUtils.toString(config.memorySwap()) }, new Object[] { "CpuShares", // $NON-NLS-1$
        LabelProviderUtils.toString(config.cpuShares()) }, // $NON-NLS-1$
        new Object[] { "Cpuset", config.cpuset() }, // $NON-NLS-1$
        new Object[] { "AttachStdin", config.attachStdin() }, // $NON-NLS-1$
        new Object[] { "AttachStdout", config.attachStdout() }, // $NON-NLS-1$
        new Object[] { "AttachStderr", config.attachStderr() }, new Object[] { "PortSpecs", // $NON-NLS-1$
        LabelProviderUtils.reduce(config.portSpecs()) }, // $NON-NLS-1$
        new Object[] { "ExposedPorts", config.exposedPorts() }, // $NON-NLS-1$
        new Object[] { "Tty", config.tty() }, // $NON-NLS-1$
        new Object[] { "OpenStdin", config.openStdin() }, // $NON-NLS-1$
        new Object[] { "StdinOnce", config.stdinOnce() }, // $NON-NLS-1$
        new Object[] { "Env", LabelProviderUtils.reduce(config.env()) }, // $NON-NLS-1$
        new Object[] { "Cmd", LabelProviderUtils.reduce(config.cmd()) }, // $NON-NLS-1$
        new Object[] { "Image", config.image() }, new Object[] { "Volumes", // $NON-NLS-1$
        LabelProviderUtils.reduce(config.volumes().keySet()) }, // $NON-NLS-1$
        new Object[] { "WorkingDir", config.workingDir() }, new Object[] { "EntryPoint", // $NON-NLS-1$
        LabelProviderUtils.reduce(config.entrypoint()) }, // $NON-NLS-1$
        new Object[] { "NetworkDisabled", config.networkDisabled() }, new Object[] { "OnBuild", // $NON-NLS-1$
        LabelProviderUtils.reduce(config.onBuild()) } };
    } else if (propertyValue instanceof List<?>) {
        @SuppressWarnings("unchecked") final List<Object> propertyValues = (List<Object>) propertyValue;
        final Object[] result = new Object[propertyValues.size()];
        for (int i = 0; i < propertyValues.size(); i++) {
            result[i] = new Object[] { "", // $NON-NLS-1$
            LabelProviderUtils.toString(propertyValues.get(i)) };
        }
        return result;
    } else if (propertyValue instanceof Set<?>) {
        @SuppressWarnings("unchecked") final Set<Object> propertyValues = (Set<Object>) propertyValue;
        final Object[] result = new Object[propertyValues.size()];
        Iterator<Object> iterator = propertyValues.iterator();
        for (int i = 0; i < propertyValues.size(); i++) {
            result[i] = new Object[] { // $NON-NLS-1$
            "", LabelProviderUtils.toString(iterator.next()) };
        }
        return result;
    } else if (propertyValue instanceof Map<?, ?>) {
        final Map<?, ?> propertyValues = (Map<?, ?>) propertyValue;
        final Object[] result = new Object[propertyValues.size()];
        int i = 0;
        for (Entry<?, ?> entry : propertyValues.entrySet()) {
            result[i] = new Object[] { entry.getKey(), entry.getValue() };
            i++;
        }
        return result;
    }
    return EMPTY;
}
Also used : IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) Set(java.util.Set) Entry(java.util.Map.Entry) List(java.util.List) Map(java.util.Map)

Example 7 with IDockerContainerConfig

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

the class RunImageCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final IDockerImage selectedImage = CommandUtils.getSelectedImage(activePart);
    if (selectedImage == null) {
        Activator.log(new DockerException(// $NON-NLS-1$
        DVMessages.getString("RunImageUnableToRetrieveError.msg")));
    } else {
        try {
            final ImageRun wizard = new ImageRun(selectedImage);
            final boolean runImage = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
            if (runImage) {
                final IDockerContainerConfig containerConfig = wizard.getDockerContainerConfig();
                final IDockerHostConfig hostConfig = wizard.getDockerHostConfig();
                runImage(selectedImage, containerConfig, hostConfig, wizard.getDockerContainerName(), wizard.removeWhenExits());
            }
        } catch (DockerException | CoreException e) {
            Activator.log(e);
        }
    }
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) ImageRun(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRun)

Aggregations

IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)7 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)4 List (java.util.List)3 CoreException (org.eclipse.core.runtime.CoreException)3 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 DockerException (org.eclipse.linuxtools.docker.core.DockerException)2 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)2 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)2 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)1 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)1 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)1 HostConfig (com.spotify.docker.client.messages.HostConfig)1 LxcConfParameter (com.spotify.docker.client.messages.HostConfig.LxcConfParameter)1 PortBinding (com.spotify.docker.client.messages.PortBinding)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1