Java源码示例:org.jclouds.enterprise.config.EnterpriseConfigurationModule

示例1
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;
}
 
示例2
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();
    }
 
示例3
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();
}
 
示例4
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;
}
 
示例5
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();
}
 
示例6
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();
   }