本文整理汇总了Java中org.jclouds.ContextBuilder.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java ContextBuilder.newBuilder方法的具体用法?Java ContextBuilder.newBuilder怎么用?Java ContextBuilder.newBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.ContextBuilder
的用法示例。
在下文中一共展示了ContextBuilder.newBuilder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContextBuilder
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private static ContextBuilder createContextBuilder(ObjectProperties objectProperties) {
Set<Module> modules = new HashSet<>();
modules.add(new DynamicSshClientModule());
modules.add(new SocketFinderOnlyPublicInterfacesModule());
modules.add(new SLF4JLoggingModule());
Properties overrides = new Properties();
overrides.setProperty("jclouds.ssh.retry-auth", Boolean.FALSE.toString());
overrides.setProperty("jclouds.ssh.max-retries", Integer.toString(1));
ContextBuilder contextBuilder = ContextBuilder.newBuilder("openstack-nova");
String endpoint = objectProperties.getProperty(Config.CloudProvider.Openstack.ENDPOINT);
if (!Strings.isNullOrEmpty(endpoint)) {
contextBuilder.endpoint(endpoint);
}
contextBuilder
.credentials(
objectProperties.getProperty(Config.CloudProvider.Openstack.USERNAME),
objectProperties.getProperty(Config.CloudProvider.Openstack.PASSWORD)
)
.overrides(overrides)
.modules(modules);
return contextBuilder;
}
示例2: addProviderFromConfig
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private void addProviderFromConfig(String prefix, String provider) {
String id = prefix.substring(prefix.lastIndexOf('.')).substring(1);
logger.info("adding provider from {} id: {}", prefix, id);
Configuration c = config.subset(prefix);
BlobStoreContext context;
try {
ContextBuilder builder = ContextBuilder.newBuilder(provider);
String identity = c.getString(Constants.PROPERTY_IDENTITY);
if (identity != null) {
builder.credentials(identity, c.getString(Constants.PROPERTY_CREDENTIAL));
}
c.addProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true");
context = builder.overrides(new ConfigurationPropertiesView(c))
.modules(ImmutableList.of(new SLF4JLoggingModule()))
.build(BlobStoreContext.class);
logger.info("added provider {} id {}", context.unwrap().getId(), id);
} catch (CreationException e) {
e.printStackTrace();
throw propagate(e);
}
BlobStore blobStore = new LoggingBlobStore(context.getBlobStore(), id, this);
providers.put(Integer.valueOf(id), blobStore);
}
示例3: createContextBuilder
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private static ContextBuilder createContextBuilder(ObjectProperties objectProperties) {
Properties properties = new Properties();
final String amiQuery = objectProperties.getProperty(Config.CloudProvider.EC2.AMI_QUERY);
if (!Strings.isNullOrEmpty(amiQuery)) {
properties.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, amiQuery);
}
final String ec2Regions = objectProperties.getProperty(Config.CloudProvider.EC2.REGION);
if (!Strings.isNullOrEmpty(ec2Regions)) {
properties.setProperty(LocationConstants.PROPERTY_REGIONS, ec2Regions);
}
Set<Module> modules = new HashSet<>();
modules.add(new DynamicSshClientModule());
modules.add(new SocketFinderOnlyPublicInterfacesModule());
if (Boolean.parseBoolean(objectProperties.getProperty(Config.CloudProvider.EC2.LOG_EC2_OPERATIONS))) {
// TODO we should add that unconditionally, like we do in all other cloud providers!
// the reason why we don't [yet] is that the JClouds EC2 provider does some excessive logging,
// e.g. the names of all available images, and we don't want our users to have to deal with that
modules.add(new SLF4JLoggingModule());
}
final ContextBuilder contextBuilder = ContextBuilder.newBuilder("aws-ec2");
final String endpoint = objectProperties.getProperty(Config.CloudProvider.EC2.ENDPOINT);
if (!Strings.isNullOrEmpty(endpoint)) {
contextBuilder.endpoint(endpoint);
}
contextBuilder
.credentials(
objectProperties.getProperty(Config.CloudProvider.EC2.ACCESS_KEY_ID),
objectProperties.getProperty(Config.CloudProvider.EC2.SECRET_ACCESS_KEY)
)
.overrides(properties).modules(ImmutableSet.copyOf(modules));
return contextBuilder;
}
示例4: buildContext
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private ContextBuilder buildContext() {
//todo ugly hack
final Properties properties = new Properties();
if (regions != null) {
properties.setProperty("jclouds.regions", regions);
}
if (requestTimeout != null) {
properties.setProperty(org.jclouds.Constants.PROPERTY_REQUEST_TIMEOUT, requestTimeout);
}
//todo duplicates code from NovaApiProvider
// loading ssh module of jclouds as it seems to be required for google,
// we are using the jschsshclient as the sshj conflicts with the overthere bouncy castle impl.
Set<Module> moduleSet = new HashSet<>();
moduleSet.addAll(overrideModules());
moduleSet.add(new JCloudsLoggingModule(loggerFactory));
ContextBuilder contextBuilder = ContextBuilder.newBuilder(cloud.api().providerName());
contextBuilder.credentials(cloud.credential().user(), cloud.credential().password())
.modules(moduleSet).overrides(overrideProperties(properties));
// setting optional endpoint, check for present first
// as builder does not allow null values...
if (cloud.endpoint().isPresent()) {
contextBuilder.endpoint(cloud.endpoint().get());
}
return contextBuilder;
}