You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by Ignasi Barrera <no...@github.com> on 2015/10/10 00:28:15 UTC

[jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

https://issues.apache.org/jira/browse/JCLOUDS-1014

Some Docker images can have the SSH server running in a port different than 22, and that configuration might not be populated in the container's networking configuration section. This pull request introduces a pluggable mechanism to let users provide their own port lookup functions for each image, allowing a more precise parsing of the container info.

The following example shows how to configure the user defined functions:

```java
// Define custom functions that given a container, return the login port
Function<Container, Integer> AlpinePortLookup = new Function<Container, Integer>() {
   @Override public Integer apply(Container input) {
      return 2222;  // Look for the port in the container object
   }
};

// Create a Guice module that configures the "image -> lookup-function" mappings
Module customLookupModule = new AbstractModule() {
   @Override protected void configure() {
      MapBinder<String, Function<Container, Integer>> lookup = loginPortLookupBinder(binder());
      lookup.addBinding("alpine-ext").toInstance(AlpinePortLookup);
      lookup.addBinding("ubuntu").toInstance(GenericUbuntuPortLookup);
      lookup.addBinding("ubuntu:12.04").toInstance(Ubuntu1204PortLookup);
};

// Provide the lookup module in the module list when creating the context
ComputeServiceContext context = ContextBuilder.newBuilder("docker")
   .credentials("identity", "credential")
   .modules(ImmutableSet.<Module> of(customLookupModule, new SshjSshClientModule()))
   .buildView(ComputeServiceContext.class);
```

/cc @kwart 
You can view, comment on, or merge this pull request online at:

  https://github.com/jclouds/jclouds-labs/pull/209

-- Commit Summary --

  * JCLOUDS-1014: Make the login port lookup function configurable

-- File Changes --

    M docker/pom.xml (4)
    M docker/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java (9)
    A docker/src/main/java/org/jclouds/docker/compute/config/LoginPort.java (36)
    A docker/src/main/java/org/jclouds/docker/compute/config/LoginPortLookupModule.java (44)
    M docker/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java (72)
    A docker/src/test/java/org/jclouds/docker/compute/functions/ContainerLoginPortLookupTest.java (132)
    M docker/src/test/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadataTest.java (9)

-- Patch Links --

https://github.com/jclouds/jclouds-labs/pull/209.patch
https://github.com/jclouds/jclouds-labs/pull/209.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209

Re: [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

Posted by Ignasi Barrera <no...@github.com>.
The build got stuck and I had to abort it. Let's try again: rebuild please!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209#issuecomment-147047041

Re: [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

Posted by Josef Cacek <no...@github.com>.
I like the new version. 
I'm just playing with replacing the default lookup implementation.

I'll play with the imageName-to-Function mapping later.

Thanks, @nacx .

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209#issuecomment-148008162

Re: [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

Posted by Ignasi Barrera <no...@github.com>.
As said in the conversation copied in the jira issue, there are cases where there is no network info in the container details. If the network mode is host, that's the only info you get, but in that case the port 22 might be taken by the host itself, so it won't be available to the container.

Some images address this by reading the port froman env var, orhers might hardcode another port, etc. This PR allows users to configure a *fallback* method to be invoked if the container does not have the port info populated.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209#issuecomment-147126634

Re: [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

Posted by Ignasi Barrera <no...@github.com>.
I've added a small change based on @kwart's feedback. Images are better mapped using patterns, as this allows a more precise mapping between concrete images and their lookup functions.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209#issuecomment-147729137

Re: [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

Posted by Andrea Turli <no...@github.com>.
@nacx not sure I get the purpose of this feature: the login port like any other ports depends on the docker engine, specifically the network type, and it is not a feature of an image. Am I missing something?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209#issuecomment-147110537

Re: [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)

Posted by Ignasi Barrera <no...@github.com>.
@andreaturli @kwart Thinking about this a bit more, I refactored the port lookup code to its own function. This allows users to configure per-image lookup functions, but also to easily override the default implementation. Have a look at the updated PR description for the details.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/209#issuecomment-147722274