本文整理汇总了Java中org.jclouds.compute.domain.TemplateBuilder.hardwareId方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateBuilder.hardwareId方法的具体用法?Java TemplateBuilder.hardwareId怎么用?Java TemplateBuilder.hardwareId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.compute.domain.TemplateBuilder
的用法示例。
在下文中一共展示了TemplateBuilder.hardwareId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNode
import org.jclouds.compute.domain.TemplateBuilder; //导入方法依赖的package包/类
/**
* Create a node with the specified group.
*/
protected void createNode(Exchange exchange) throws CamelException {
String group = getGroup(exchange);
String imageId = getImageId(exchange);
String locationId = getLocationId(exchange);
String hardwareId = getHardwareId(exchange);
if (ObjectHelper.isEmpty(group)) {
throw new CamelExchangeException("Group must be specific in the URI or as exchange property for the destroy node operation.", exchange);
}
TemplateBuilder builder = computeService.templateBuilder();
builder.any();
if (ObjectHelper.isNotEmpty(locationId)) {
builder.locationId(locationId);
}
if (ObjectHelper.isNotEmpty(imageId)) {
builder.imageId(imageId);
}
if (ObjectHelper.isNotEmpty(hardwareId)) {
builder.hardwareId(hardwareId);
}
try {
Set<? extends NodeMetadata> nodeMetadatas = computeService.createNodesInGroup(group, 1, builder.build());
exchange.getOut().setBody(nodeMetadatas);
exchange.getOut().setHeaders(exchange.getIn().getHeaders());
} catch (RunNodesException e) {
throw new CamelExchangeException("Error creating jclouds node.", exchange, e);
}
}
示例2: OpenstackNode
import org.jclouds.compute.domain.TemplateBuilder; //导入方法依赖的package包/类
public OpenstackNode(OpenstackCloudProvider osCloudProvider, String name, Map<String, String> configOverrides) {
super(osCloudProvider, name, configOverrides);
NovaTemplateOptions templateOptions = buildTemplateOptions(objectProperties);
final TemplateBuilder templateBuilder = computeService.templateBuilder();
final String instanceType = objectProperties.getProperty(Config.Node.Openstack.INSTANCE_TYPE);
if (!Strings.isNullOrEmpty(instanceType)) {
String hwId = null;
Set<? extends Hardware> hws = computeService.listHardwareProfiles();
for (Hardware hw : hws) {
String hwName = hw.getName();
if (instanceType.equals(hw.getId()) || instanceType.equals(hwName)
|| (hwName != null && hwName.endsWith("/" + instanceType))) {
hwId = hw.getId();
break;
}
}
if (hwId == null) {
throw new IllegalArgumentException("Hardware configuration '" + instanceType + "' was not found.");
}
templateBuilder.hardwareId(hwId);
}
String region = objectProperties.getProperty(Config.Node.Openstack.REGION);
if (Strings.isNullOrEmpty(region)) {
LOGGER.debug("Region for node '{}' was not configured, trying to assign automatically", name);
Set<? extends Location> locations = computeService.listAssignableLocations();
if (locations.size() == 1) {
region = locations.iterator().next().getId();
LOGGER.debug("Automatically assigned region '{}' to node '{}'", region, name);
} else {
LOGGER.warn("Failed to automatically assign region to node '{}', use {} (too many regions found: {})",
name, Config.Node.Openstack.REGION, locations);
throw new IllegalArgumentException("Region was not configured for node " + name);
}
}
templateBuilder.locationId(region);
ResolvedImage resolvedImage = ResolvedImage.fromNameAndId(
objectProperties.getProperty(Config.Node.Openstack.IMAGE),
objectProperties.getProperty(Config.Node.Openstack.IMAGE_ID),
region, computeService
);
this.imageName = resolvedImage.humanReadableName;
if (!templateOptions.getFloatingIpPoolNames().isPresent()) {
LOGGER.debug("Floating IP pool for node '{}' was not configured, trying to assign automatically", name);
final Optional<FloatingIPPoolApi> floatingIPPoolApi = osCloudProvider.getNovaApi().getFloatingIPPoolApi(region);
if (floatingIPPoolApi.isPresent()) {
final ImmutableList<String> pools = floatingIPPoolApi.get().list().transform(FloatingIPPool::getName).toList();
LOGGER.debug("Automatically assigned floating IP pools to node '{}': {}", name, pools);
templateOptions.floatingIpPoolNames(pools);
} else {
LOGGER.error("FloatingIPPoolApi missing, floating IP pool stays unconfigured, use {}",
Config.Node.Openstack.FLOATING_IP_POOLS);
}
}
final Template template = templateBuilder.imageId(resolvedImage.fullId).options(templateOptions).build();
LOGGER.debug("Creating {} node from template: {}",
cloudProvider.getCloudProviderType().getHumanReadableName(), template);
try {
this.initialNodeMetadata = createNode(template);
String publicAddress = Iterables.getFirst(initialNodeMetadata.getPublicAddresses(), null);
LOGGER.info("Started {} node '{}' from image {}, its public IP address is {}",
cloudProvider.getCloudProviderType().getHumanReadableName(), name, imageName, publicAddress);
} catch (RunNodesException e) {
throw new RuntimeException("Unable to create " + cloudProvider.getCloudProviderType().getHumanReadableName()
+ " node from template " + template, e);
}
}
示例3: buildTemplate
import org.jclouds.compute.domain.TemplateBuilder; //导入方法依赖的package包/类
public void buildTemplate() {
IaasProvider iaasProvider = getIaasProvider();
if (iaasProvider.getComputeService() == null) {
throw new CloudControllerException("Compute service is null for IaaS provider: " + iaasProvider.getName());
}
TemplateBuilder templateBuilder = iaasProvider.getComputeService().templateBuilder();
templateBuilder.imageId(iaasProvider.getImage());
// To avoid creation of template objects in each and every time, we create all at once!
String instanceType;
// set instance type
if (((instanceType = iaasProvider.getProperty(CloudControllerConstants.INSTANCE_TYPE)) != null)) {
templateBuilder.hardwareId(instanceType);
}
Template template = templateBuilder.build();
// In Openstack the call to IaaS should be blocking, in order to retrieve IP addresses.
boolean blockUntilRunning = true;
if (iaasProvider.getProperty(CloudControllerConstants.BLOCK_UNTIL_RUNNING) != null) {
blockUntilRunning = Boolean
.parseBoolean(iaasProvider.getProperty(CloudControllerConstants.BLOCK_UNTIL_RUNNING));
}
template.getOptions().as(TemplateOptions.class).blockUntilRunning(blockUntilRunning);
// this is required in order to avoid creation of additional security groups by Jclouds.
template.getOptions().as(TemplateOptions.class).inboundPorts();
if (iaasProvider.getProperty(CloudControllerConstants.SECURITY_GROUPS) != null) {
template.getOptions().as(NovaTemplateOptions.class).securityGroupNames(
iaasProvider.getProperty(CloudControllerConstants.SECURITY_GROUPS)
.split(CloudControllerConstants.ENTRY_SEPARATOR));
}
if (iaasProvider.getProperty(CloudControllerConstants.KEY_PAIR) != null) {
template.getOptions().as(NovaTemplateOptions.class)
.keyPairName(iaasProvider.getProperty(CloudControllerConstants.KEY_PAIR));
}
if (iaasProvider.getNetworkInterfaces() != null) {
Set<Network> novaNetworksSet = new LinkedHashSet<Network>(iaasProvider.getNetworkInterfaces().length);
for (NetworkInterface ni : iaasProvider.getNetworkInterfaces()) {
novaNetworksSet.add(Network.builder().networkUuid(ni.getNetworkUuid()).fixedIp(ni.getFixedIp())
.portUuid(ni.getPortUuid()).build());
}
template.getOptions().as(NovaTemplateOptions.class).novaNetworks(novaNetworksSet);
}
if (iaasProvider.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) != null) {
template.getOptions().as(NovaTemplateOptions.class)
.availabilityZone(iaasProvider.getProperty(CloudControllerConstants.AVAILABILITY_ZONE));
}
//TODO
// if (iaas.getProperty(CloudControllerConstants.HOST) != null) {
// template.getOptions().as(NovaTemplateOptions.class)
// .(CloudControllerConstants.HOST);
// }
// set Template
iaasProvider.setTemplate(template);
}