org.jclouds.sshj.config.SshjSshClientModule Java Examples

The following examples show how to use org.jclouds.sshj.config.SshjSshClientModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComputeServiceBuilderUtil.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public static ComputeService buildDefaultComputeService(IaasProvider iaasProvider) {

        Properties properties = new Properties();

        // load properties
        for (Map.Entry<String, String> entry : iaasProvider.getProperties().entrySet()) {
            properties.put(entry.getKey(), entry.getValue());
        }

        // set modules
        Iterable<Module> modules =
                ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                        new EnterpriseConfigurationModule());

        // build context
        ContextBuilder builder =
                ContextBuilder.newBuilder(iaasProvider.getProvider())
                        .credentials(iaasProvider.getIdentity(), iaasProvider.getCredential()).modules(modules)
                        .overrides(properties);

        return builder.buildView(ComputeServiceContext.class).getComputeService();
    }
 
Example #2
Source File: JCloudsConnector.java    From cloudml with GNU Lesser General Public License v3.0 6 votes vote down vote up
public JCloudsConnector(String provider,String login,String secretKey){
    journal.log(Level.INFO, ">> Connecting to "+provider+" ...");
    Properties overrides = new Properties();
    if(provider.equals("aws-ec2")){
        // choose only amazon images that are ebs-backed
        //overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_OWNERS,"107378836295");
        overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY,
                "owner-id=137112412989,107378836295,099720109477;state=available;image-type=machine;root-device-type=ebs");
    }
    overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, 0 + "");
    overrides.setProperty(PROPERTY_SO_TIMEOUT, 0 + "");
    overrides.setProperty(PROPERTY_REQUEST_TIMEOUT, 0 + "");
    overrides.setProperty(PROPERTY_RETRY_DELAY_START, 0 + "");
    Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new NullLoggingModule());
    ContextBuilder builder = ContextBuilder.newBuilder(provider).credentials(login, secretKey).modules(modules).overrides(overrides);
    journal.log(Level.INFO, ">> Authenticating ...");
    computeContext=builder.buildView(ComputeServiceContext.class);
    ec2api=builder.buildApi(EC2Api.class);
    //loadBalancerCtx=builder.buildView(LoadBalancerServiceContext.class);

    compute=computeContext.getComputeService();
    this.provider = provider;
}
 
Example #3
Source File: MainApp.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private static ComputeService initComputeService(final String provider, final String identity,
                                                 final String credential) {
    // example of specific properties, in this case optimizing image list to
    // only amazon supplied
    Properties properties = new Properties();
    long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
    properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");

    // example of injecting a ssh implementation
    Iterable<Module> modules =
            ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                    new EnterpriseConfigurationModule());

    ContextBuilder builder =
            ContextBuilder.newBuilder(provider).credentials(identity, credential).modules(modules)
                    .overrides(properties);

    System.out.printf(">> initializing %s%n", builder.getApiMetadata());

    return builder.buildView(ComputeServiceContext.class).getComputeService();
}
 
Example #4
Source File: CreateVolumeAndAttach.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public CreateVolumeAndAttach(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   // These properties control how often jclouds polls for a status udpate
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   ComputeServiceContext context = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules)
         .overrides(overrides)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
   novaApi = context.unwrapApi(NovaApi.class);
   volumeAttachmentApi = novaApi.getVolumeAttachmentApi(REGION).get();

   cinderApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(CinderApi.class);
   volumeApi = cinderApi.getVolumeApi(REGION);
}
 
Example #5
Source File: DetachVolume.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public DetachVolume(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   ComputeServiceContext context = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
   NovaApi novaApi = context.unwrapApi(NovaApi.class);
   serverApi = novaApi.getServerApi(REGION);
   volumeAttachmentApi = novaApi.getVolumeAttachmentApi(REGION).get();

   cinderApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(CinderApi.class);
   volumeApi = cinderApi.getVolumeApi(REGION);
}
 
Example #6
Source File: CreateServerWithKeyPair.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public CreateServerWithKeyPair(String username, String apiKey) {
   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   // These properties control how often jclouds polls for a status update
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .overrides(overrides)
         .modules(modules)
         .buildView(ComputeServiceContext.class);

   computeService = context.getComputeService();
   novaApi = context.unwrapApi(NovaApi.class);
}
 
Example #7
Source File: CloudServersPublish.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public CloudServersPublish(List<String> args) {
   String username = args.get(0);
   String apiKey = args.get(1);
   numServers = args.size() == 3 ? Integer.valueOf(args.get(2)) : 1;

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   // These properties control how often jclouds polls for a status update
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .overrides(overrides)
         .modules(modules)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
}
 
Example #8
Source File: Utils.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public static ComputeServiceContext getComputeApiFromCarinaDirectory(String path) throws IOException {
   // docker.ps1 contains the endpoint
   String endpoint = "https://" +
         Files.readFirstLine(new File(joinPath(path, "docker.ps1")),
               Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6);

   // enable logging and sshj
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule());
   Properties overrides = new Properties();

   // disable certificate checking for Carina
   overrides.setProperty("jclouds.trust-all-certs", "true");

   return ContextBuilder.newBuilder("docker")
         .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem"))
         .modules(modules)
         .overrides(overrides)
         .endpoint(endpoint)
         .buildView(ComputeServiceContext.class);
}
 
Example #9
Source File: NovaContext.java    From karamel with Apache License 2.0 6 votes vote down vote up
public static ContextBuilder buildContext(NovaCredentials credentials) {
  Properties properties = new Properties();
  properties.setProperty(NovaProperties.AUTO_ALLOCATE_FLOATING_IPS, "true");
  Iterable<Module> modules = ImmutableSet.<Module>of(
          new SshjSshClientModule(),
          new SLF4JLoggingModule(),
          new EnterpriseConfigurationModule());

  ContextBuilder build = ContextBuilder.newBuilder("aws-ec2")
          .credentials(credentials.getAccountName(), credentials.getAccountPass())
          .endpoint(credentials.getEndpoint())
          .modules(modules)
          .overrides(properties);

  return build;
}
 
Example #10
Source File: JcloudsUtil.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static Map<Integer, Integer> dockerPortMappingsFor(JcloudsLocation docker, String containerId) {
    ComputeServiceContext context = null;
    try {
        Properties properties = new Properties();
        properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, Boolean.toString(true));
        properties.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, Boolean.toString(true));
        context = ContextBuilder.newBuilder("docker")
                .endpoint(docker.getEndpoint())
                .credentials(docker.getIdentity(), docker.getCredential())
                .overrides(properties)
                .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule(), new SshjSshClientModule()))
                .build(ComputeServiceContext.class);
        DockerApi api = context.unwrapApi(DockerApi.class);
        Container container = api.getContainerApi().inspectContainer(containerId);
        Map<Integer, Integer> portMappings = Maps.newLinkedHashMap();
        Map<String, List<Map<String, String>>> ports = container.networkSettings().ports();
        if (ports == null) ports = ImmutableMap.<String, List<Map<String,String>>>of();

        LOG.debug("Docker will forward these ports {}", ports);
        for (Map.Entry<String, List<Map<String, String>>> entrySet : ports.entrySet()) {
            String containerPort = Iterables.get(Splitter.on("/").split(entrySet.getKey()), 0);
            String hostPort = Iterables.getOnlyElement(Iterables.transform(entrySet.getValue(),
                    new Function<Map<String, String>, String>() {
                        @Override
                        public String apply(Map<String, String> hostIpAndPort) {
                            return hostIpAndPort.get("HostPort");
                        }
                    }));
            portMappings.put(Integer.parseInt(containerPort), Integer.parseInt(hostPort));
        }
        return portMappings;
    } finally {
        if (context != null) {
            context.close();
        }
    }
}
 
Example #11
Source File: AbstractComputeServiceRegistry.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * returns the jclouds modules we typically install
 */
protected Iterable<? extends Module> commonModules() {
    return ImmutableSet.<Module>of(
            new SshjSshClientModule(),
            new SLF4JLoggingModule(),
            new BouncyCastleCryptoModule());
}
 
Example #12
Source File: BlobStoreContextFactoryImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** returns the jclouds modules we typically install */ 
protected ImmutableSet<Module> getCommonModules() {
    return ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new SLF4JLoggingModule(),
            new BouncyCastleCryptoModule());
}
 
Example #13
Source File: LinkContextSupplier.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Context get() {
    JcloudsContext jcloudsContext = conf.get(JcloudsLocationConfig.LINK_CONTEXT);
    String identity = MoreObjects.firstNonNull(jcloudsContext.getIdentity(), conf.get(CloudLocationConfig.ACCESS_IDENTITY));
    String credential = MoreObjects.firstNonNull(jcloudsContext.getCredential(), conf.get(CloudLocationConfig.ACCESS_CREDENTIAL));
    return ContextBuilder
            .newBuilder(jcloudsContext.getProviderOrApi())
            .credentials(identity, credential)
            .modules(ImmutableList.of(new SshjSshClientModule(), new SLF4JLoggingModule()))
            .overrides(getProperties(jcloudsContext, conf))
            .build();
}
 
Example #14
Source File: MainApp.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
private static ComputeService initComputeService(String provider, String identity, String credential) {

      // example of specific properties, in this case optimizing image list to
      // only amazon supplied
      Properties properties = new Properties();
      properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine");
      properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
      long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");

      // set oauth endpoint property if set in system property
      String oAuthEndpoint = System.getProperty(PROPERTY_OAUTH_ENDPOINT);
      if (oAuthEndpoint != null) {
         properties.setProperty(PROPERTY_OAUTH_ENDPOINT, oAuthEndpoint);
      }

      // example of injecting a ssh implementation
      Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new SLF4JLoggingModule(),
            new EnterpriseConfigurationModule());

      ContextBuilder builder = ContextBuilder.newBuilder(provider)
                                             .credentials(identity, credential)
                                             .modules(modules)
                                             .overrides(properties);

      System.out.printf(">> initializing %s%n", builder.getApiMetadata());

      return builder.buildView(ComputeServiceContext.class).getComputeService();
   }
 
Example #15
Source File: Ec2Context.java    From karamel with Apache License 2.0 5 votes vote down vote up
public Ec2Context(Ec2Credentials credentials) {
  this.credentials = credentials;
  Properties properties = new Properties();
  long scriptTimeout = TimeUnit.MILLISECONDS.convert(50, TimeUnit.MINUTES);
  properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
  properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + "");
  properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, scriptTimeout + "");
  properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine");
  properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
  properties.setProperty(Constants.PROPERTY_MAX_RETRIES, Settings.JCLOUDS_PROPERTY_MAX_RETRIES + "");
  properties.setProperty(Constants.PROPERTY_RETRY_DELAY_START, Settings.JCLOUDS_PROPERTY_RETRY_DELAY_START + "");

  Iterable<Module> modules = ImmutableSet.<Module>of(
      new SshjSshClientModule(),
      new SLF4JLoggingModule(),
      new EnterpriseConfigurationModule());

  ContextBuilder build = ContextBuilder.newBuilder("aws-ec2")
      .credentials(credentials.getAccessKey(), credentials.getSecretKey())
      .modules(modules)
      .overrides(properties);
  ComputeServiceContext context = build.buildView(ComputeServiceContext.class);
  this.computeService = (AWSEC2ComputeService) context.getComputeService();
  this.ec2api = computeService.getContext().unwrapApi(EC2Api.class);
  this.securityGroupApi = ec2api.getSecurityGroupApi().get();
  this.keypairApi = (AWSKeyPairApi) ec2api.getKeyPairApi().get();

  vmBatchSize = Settings.AWS_VM_BATCH_SIZE();
}
 
Example #16
Source File: CloudSigmaConnector.java    From cloudml with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CloudSigmaConnector(String provider,String login,String secretKey){
    journal.log(Level.INFO, ">> Connecting to "+provider+" ...");
    Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new NullLoggingModule());
    ContextBuilder builder = ContextBuilder.newBuilder(provider)
            .credentials(login, secretKey)
            .modules(modules);
    journal.log(Level.INFO, ">> Authenticating ...");
    this.provider = provider;
    cloudSigmaApi=builder.buildApi(CloudSigma2Api.class);
}
 
Example #17
Source File: OpenStackConnector.java    From cloudml with GNU Lesser General Public License v3.0 5 votes vote down vote up
public OpenStackConnector(String endPoint,String provider,String login,String secretKey){
    this.endpoint=endPoint;
    journal.log(Level.INFO, ">> Connecting to "+provider+" ...");
    Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new NullLoggingModule());
    ContextBuilder builder = ContextBuilder.newBuilder(provider)
            .endpoint(endPoint)
            .credentials(login, secretKey)
            .modules(modules);
    journal.log(Level.INFO, ">> Authenticating ...");
    computeContext=builder.buildView(ComputeServiceContext.class);
    novaComputeService= computeContext.getComputeService();
    serverApi=builder.buildApi(NovaApi.class);
}
 
Example #18
Source File: GceContext.java    From karamel with Apache License 2.0 5 votes vote down vote up
public GceContext(Credentials credentials) {
  ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
      .modules(Arrays.asList(
              new SshjSshClientModule(),
              new EnterpriseConfigurationModule(),
              new SLF4JLoggingModule()))
      .credentials(credentials.identity, credentials.credential)
      .buildView(ComputeServiceContext.class);
  computeService = context.getComputeService();
  gceApi = context.unwrapApi(GoogleComputeEngineApi.class);
  fireWallApi = gceApi.firewalls();
  networkApi = gceApi.networks();
  routeApi = gceApi.routes();
  this.credentials = credentials;
}
 
Example #19
Source File: AWSKeyPairApiLiveTest.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
@Override
protected Module getSshModule() {
   return new SshjSshClientModule();
}
 
Example #20
Source File: PlacementGroupApiLiveTest.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
@Override
protected Module getSshModule() {
   return new SshjSshClientModule();
}
 
Example #21
Source File: AWSEC2ImageExtensionLiveTest.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
@Override
protected Module getSshModule() {
   return new SshjSshClientModule();
}