jclouds-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ignasi Barrera <notificati...@github.com>
Subject [jclouds-labs] JCLOUDS-1014: Make the login port lookup function configurable (#209)
Date Fri, 09 Oct 2015 22:28:15 GMT
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

Mime
View raw message