@Override
  @Nullable
  public LoginCredentials get() {
    if (credentialStore.containsKey("image")) {
      return LoginCredentials.builder(credentialStore.get("image")).build();
    }
    Builder builder = LoginCredentials.builder();

    String loginUser = config.apply(provider + ".image.login-user");
    if (loginUser == null) loginUser = config.apply("jclouds.image.login-user");
    if (loginUser != null) {
      int pos = loginUser.indexOf(':');
      if (pos != -1) {
        builder.user(loginUser.substring(0, pos)).password(loginUser.substring(pos + 1));
      } else builder.user(loginUser);
    }

    String authenticateSudo = config.apply(provider + ".image.authenticate-sudo");
    if (authenticateSudo == null)
      authenticateSudo = config.apply("jclouds.image.authenticate-sudo");
    if (authenticateSudo != null) {
      builder.authenticateSudo(Boolean.valueOf(authenticateSudo));
    }

    LoginCredentials creds = builder.build();
    if (creds != null) credentialStore.put("image", creds);
    return creds;
  }
コード例 #2
0
 @Provides
 @Singleton
 @ImageQuery
 protected Map<String, String> imageQuery(ValueOfConfigurationKeyOrNull config) {
   String amiQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_AMI_QUERY));
   String owners = config.apply(PROPERTY_EC2_AMI_OWNERS);
   if ("".equals(owners)) {
     amiQuery = null;
   } else if (owners != null) {
     StringBuilder query = new StringBuilder();
     if ("*".equals(owners)) query.append("state=available;image-type=machine");
     else query.append("owner-id=").append(owners).append(";state=available;image-type=machine");
     Logger.getAnonymousLogger()
         .warning(
             String.format(
                 "Property %s is deprecated, please use new syntax: %s=%s",
                 PROPERTY_EC2_AMI_OWNERS, PROPERTY_EC2_AMI_QUERY, query.toString()));
     amiQuery = query.toString();
   }
   Builder<String, String> builder = ImmutableMap.<String, String>builder();
   if (amiQuery != null) builder.put(PROPERTY_EC2_AMI_QUERY, amiQuery);
   String ccQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_CC_AMI_QUERY));
   if (ccQuery != null) builder.put(PROPERTY_EC2_CC_AMI_QUERY, ccQuery);
   return builder.build();
 }
コード例 #3
0
 /** The default template if none is provided. */
 @Provides
 @Named("DEFAULT")
 protected TemplateBuilder provideTemplateOptionallyFromProperties(
     Injector injector,
     TemplateBuilder template,
     @Provider String provider,
     ValueOfConfigurationKeyOrNull config) {
   template = provideTemplate(injector, template);
   String imageId = config.apply(provider + ".image-id");
   if (imageId == null) imageId = config.apply(ComputeServiceConstants.PROPERTY_IMAGE_ID);
   if (imageId != null) template.imageId(imageId);
   return template;
 }
コード例 #4
0
 /** The default template if none is provided. */
 @Provides
 @Named("DEFAULT")
 protected TemplateBuilder provideTemplateOptionallyFromProperties(
     Injector injector,
     TemplateBuilder template,
     @Provider String provider,
     ValueOfConfigurationKeyOrNull config) {
   String templateString = config.apply(provider + ".template");
   if (templateString == null) templateString = config.apply(TEMPLATE);
   if (templateString != null) {
     template.from(templateString);
   } else {
     template.osFamily(UBUNTU).osVersionMatches("1[012].[01][04]").os64Bit(true);
   }
   String imageId = config.apply(provider + ".image-id");
   if (imageId == null) imageId = config.apply(IMAGE_ID);
   if (imageId != null) template.imageId(imageId);
   return template;
 }