本文整理汇总了Java中org.jclouds.compute.domain.Template类的典型用法代码示例。如果您正苦于以下问题:Java Template类的具体用法?Java Template怎么用?Java Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Template类属于org.jclouds.compute.domain包,在下文中一共展示了Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
@Override
public Map<?, ListenableFuture<Void>> execute(
final String group, final int count, final Template template,
final Set<NodeMetadata> goodNodes, final Map<NodeMetadata, Exception> badNodes,
final Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
final DimensionDataCloudControllerTemplateOptions templateOptions = template.getOptions().as(DimensionDataCloudControllerTemplateOptions.class);
String networkDomainName = firstNonNull(templateOptions.getNetworkDomainName(), DEFAULT_NETWORK_DOMAIN_NAME);
String vlanName = firstNonNull(templateOptions.getVlanName(), DEFAULT_VLAN_NAME);
String defaultPrivateIPv4BaseAddress = firstNonNull(templateOptions.getDefaultPrivateIPv4BaseAddress(), DEFAULT_PRIVATE_IPV4_BASE_ADDRESS);
Integer defaultPrivateIPv4PrefixSize = firstNonNull(templateOptions.getDefaultPrivateIPv4PrefixSize(), DEFAULT_PRIVATE_IPV4_PREFIX_SIZE);
String location = template.getLocation().getId();
// If networkDomain and vlanId overrides are supplied in TemplateOptions, always prefer those.
if (templateOptions.getNetworkDomainId() == null && templateOptions.getVlanId() == null) {
String networkDomainId = tryCreateOrGetExistingNetworkDomain(api, location, networkDomainName);
templateOptions.networkDomainId(networkDomainId);
String vlanId = tryCreateOrGetExistingVlan(api, templateOptions.getNetworkDomainId(), vlanName, defaultPrivateIPv4BaseAddress, defaultPrivateIPv4PrefixSize);
templateOptions.vlanId(vlanId);
}
return super.execute(group, count, template, goodNodes, badNodes, customizationResponses);
}
示例2: apply
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
public LoginCredentials apply(final Template template, final LoginCredentials fromNode) {
RunScriptOptions options = checkNotNull(template.getOptions(), "template options are required");
LoginCredentials.Builder builder = LoginCredentials.builder(fromNode);
if (options.getLoginUser() != null) {
builder.user(template.getOptions().getLoginUser());
}
if (options.getLoginPassword() != null) {
builder.password(options.getLoginPassword());
}
if (options.getLoginPrivateKey() != null) {
builder.privateKey(options.getLoginPrivateKey());
}
if (options.shouldAuthenticateSudo() != null && options.shouldAuthenticateSudo()) {
builder.authenticateSudo(true);
}
return builder.build();
}
示例3: provisionNodes
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
public void provisionNodes() {
Map<String, String> singleTagConfig = new HashMap<String, String>();
singleTagConfig.put(TAG_1.getKey(), TAG_1.getValue());
Map<String, String> multiTagConfig = new HashMap<String, String>();
multiTagConfig.put(TAG_2.getKey(), TAG_2.getValue());
multiTagConfig.put(TAG_3.getKey(), TAG_3.getValue());
Template region1Template = getTemplateInRegion1(singleTagConfig);
Template region2Template = getTemplateInRegion2(multiTagConfig);
try {
createNode(GROUP_NAME_1, region1Template);
createNode(GROUP_NAME_1, region1Template);
createNode(GROUP_NAME_1, region2Template);
createNode(GROUP_NAME_2, region2Template);
createNode(GROUP_NAME_2, region1Template);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: createNodesInRegionAndZone
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
@Override
protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group,
int count, Template template, RunInstancesOptions instanceOptions) {
Float spotPrice = getSpotPriceOrNull(template.getOptions());
if (spotPrice != null) {
AWSEC2TemplateOptions awsOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
LaunchSpecification spec = AWSRunInstancesOptions.class.cast(instanceOptions).getLaunchSpecificationBuilder()
.imageId(template.getImage().getProviderId()).availabilityZone(zone).subnetId(awsOptions.getSubnetId())
.publicIpAddressAssociated(awsOptions.isPublicIpAddressAssociated())
.iamInstanceProfileArn(awsOptions.getIAMInstanceProfileArn())
.iamInstanceProfileName(awsOptions.getIAMInstanceProfileName()).build();
RequestSpotInstancesOptions options = awsOptions.getSpotOptions();
if (logger.isDebugEnabled())
logger.debug(">> requesting %d spot instances region(%s) price(%f) spec(%s) options(%s)", count, region,
spotPrice, spec, options);
return ImmutableSet.<RunningInstance> copyOf(transform(client.getSpotInstanceApi().get()
.requestSpotInstancesInRegion(region, spotPrice, count, spec, options), spotConverter));
}
return super.createNodesInRegionAndZone(region, zone, group, count, template, instanceOptions);
}
示例5: execute
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
public AWSRunInstancesOptions execute(String region, String group, Template template) {
AWSRunInstancesOptions instanceOptions = AWSRunInstancesOptions.class
.cast(super.execute(region, group, template));
String placementGroupName = template.getHardware().getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise(
region, group, template.getOptions()) : null;
if (placementGroupName != null)
instanceOptions.inPlacementGroup(placementGroupName);
AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
if (awsTemplateOptions.isMonitoringEnabled())
instanceOptions.enableMonitoring();
if (awsTemplateOptions.getIAMInstanceProfileArn() != null)
instanceOptions.withIAMInstanceProfileArn(awsTemplateOptions.getIAMInstanceProfileArn());
if (awsTemplateOptions.getIAMInstanceProfileName() != null)
instanceOptions.withIAMInstanceProfileName(awsTemplateOptions.getIAMInstanceProfileName());
if (awsTemplateOptions.getPrivateIpAddress() != null)
instanceOptions.withPrivateIpAddress(awsTemplateOptions.getPrivateIpAddress());
return instanceOptions;
}
开发者ID:apache,项目名称:stratos,代码行数:23,代码来源:CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java
示例6: addSecurityGroups
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
@Override
protected void addSecurityGroups(String region, String group, Template template, RunInstancesOptions instanceOptions) {
AWSEC2TemplateOptions awsTemplateOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
AWSRunInstancesOptions awsInstanceOptions = AWSRunInstancesOptions.class.cast(instanceOptions);
if (!awsTemplateOptions.getGroupIds().isEmpty())
awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
String subnetId = awsTemplateOptions.getSubnetId();
boolean associatePublicIpAddress = awsTemplateOptions.isPublicIpAddressAssociated();
if (subnetId != null) {
if (associatePublicIpAddress){
AWSRunInstancesOptions.class.cast(instanceOptions).associatePublicIpAddressAndSubnetId(subnetId);
if (awsTemplateOptions.getGroupIds().size() > 0)
awsInstanceOptions.withSecurityGroupIdsForNetworkInterface(awsTemplateOptions.getGroupIds());
} else {
AWSRunInstancesOptions.class.cast(instanceOptions).withSubnetId(subnetId);
if (awsTemplateOptions.getGroupIds().size() > 0)
awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
}
} else {
if (!awsTemplateOptions.getGroupIds().isEmpty())
awsInstanceOptions.withSecurityGroupIds(awsTemplateOptions.getGroupIds());
super.addSecurityGroups(region, group, template, instanceOptions);
}
}
开发者ID:apache,项目名称:stratos,代码行数:25,代码来源:CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java
示例7: createServer
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
/**
* Create a server based on a Template. This method uses Template.fromHardware() and Template.fromImage() to
* also demonstrate iterating through Hardware and Images. Alternatively you do the same without iterating
* using the following Template.
*
* Template template = computeService.templateBuilder()
* .locationId(getLocationId())
* .osFamily(OsFamily.UBUNTU)
* .osVersionMatches("14.04")
* .minRam(1024)
* .build();
*/
private void createServer() throws RunNodesException, TimeoutException {
System.out.format("Create Server%n");
Template template = computeService.templateBuilder()
.locationId(REGION)
.fromHardware(getHardware())
.fromImage(getImage())
.build();
// This method will continue to poll for the server status and won't return until this server is ACTIVE
// If you want to know what's happening during the polling, enable logging. See
// /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(NAME, 1, template);
NodeMetadata nodeMetadata = nodes.iterator().next();
String publicAddress = nodeMetadata.getPublicAddresses().iterator().next();
System.out.format(" %s%n", nodeMetadata);
System.out.format(" Login: ssh %[email protected]%s%n", nodeMetadata.getCredentials().getUser(), publicAddress);
System.out.format(" Password: %s%n", nodeMetadata.getCredentials().getOptionalPassword().get());
}
示例8: createServer
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
private Set<? extends NodeMetadata> createServer() throws RunNodesException, TimeoutException {
System.out.format("Create Server%n");
RegionAndId regionAndId = RegionAndId.fromRegionAndId(REGION, "performance1-1");
Template template = computeService.templateBuilder()
.locationId(REGION)
.osDescriptionMatches(".*Ubuntu 14.04.*")
.hardwareId(regionAndId.slashEncode())
.build();
// This method will continue to poll for the server status and won't return until this server is ACTIVE
// If you want to know what's happening during the polling, enable logging.
// See /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(NAME, numServers, template);
for (NodeMetadata nodeMetadata: nodes) {
System.out.format(" %s%n", nodeMetadata);
}
return nodes;
}
示例9: createServer
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
/**
* Create a server with the key pair.
*/
private NodeMetadata createServer(KeyPair keyPair) throws RunNodesException, TimeoutException {
System.out.format(" Create Server%n");
NovaTemplateOptions options = NovaTemplateOptions.Builder.keyPairName(keyPair.getName());
RegionAndId regionAndId = RegionAndId.fromRegionAndId(REGION, "performance1-1");
Template template = computeService.templateBuilder()
.locationId(REGION)
.osDescriptionMatches(".*Ubuntu 14.04.*")
.hardwareId(regionAndId.slashEncode())
.options(options)
.build();
// This method will continue to poll for the server status and won't return until this server is ACTIVE
// If you want to know what's happening during the polling, enable logging.
// See /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(NAME, 1, template);
NodeMetadata node = Iterables.getOnlyElement(nodes);
System.out.format(" %s%n", node);
return node;
}
示例10: createServer
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
private NodeMetadata createServer() throws RunNodesException, TimeoutException {
System.out.format("Create Server%n");
RegionAndId regionAndId = RegionAndId.fromRegionAndId(REGION, "performance1-1");
Template template = computeService.templateBuilder()
.locationId(REGION)
.osDescriptionMatches(".*Ubuntu 12.04.*")
.hardwareId(regionAndId.slashEncode())
.build();
Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(NAME, 1, template);
NodeMetadata nodeMetadata = nodes.iterator().next();
String publicAddress = nodeMetadata.getPublicAddresses().iterator().next();
// We set the password to something we know so we can login in the DetachVolume example
novaApi.getServerApi(REGION).changeAdminPass(nodeMetadata.getProviderId(), PASSWORD);
System.out.format(" %s%n", nodeMetadata);
System.out.format(" Login: ssh %[email protected]%s%n", nodeMetadata.getCredentials().getUser(), publicAddress);
System.out.format(" Password: %s%n", PASSWORD);
return nodeMetadata;
}
示例11: testLaunchClusterWithDomainName
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
@Test
public void testLaunchClusterWithDomainName() throws RunNodesException {
final String name = "test";
Template template = view.getComputeService().templateBuilder()
.osFamily(OsFamily.UBUNTU)
.locationId("NA9")
//.minRam(8192)
//.locationId("NA12")
.build();
DimensionDataCloudControllerTemplateOptions options = template.getOptions().as(DimensionDataCloudControllerTemplateOptions.class);
options
.inboundPorts(22, 8080, 8081)
.runScript(AdminAccess.standard())
.networkDomainId("91f577d2-5812-4e39-a79f-a35e42eb78a6")
.vlanId("025c59d7-b7e5-4261-95b8-4af067233ee7");
try {
Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(name, NUM_NODES, template);
assertThat(nodes).hasSize(NUM_NODES);
Map<? extends NodeMetadata, ExecResponse> responses = view.getComputeService().runScriptOnNodesMatching(runningInGroup(name), "echo hello");
assertThat(responses).hasSize(NUM_NODES);
for (ExecResponse execResponse : responses.values()) {
assertThat(execResponse.getOutput().trim()).isEqualTo("hello");
}
} catch (RunScriptOnNodesException e) {
Assert.fail();
} finally {
view.getComputeService().destroyNodesMatching(inGroup(name));
}
}
开发者ID:cloudsoft,项目名称:amp-dimensiondata,代码行数:35,代码来源:DimensionDataCloudControllerComputeServiceContextLiveTest.java
示例12: getTemplateInRegion1
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
public Template getTemplateInRegion1(Map<String, String> tags) {
TemplateBuilder templateBuilder = computeService.templateBuilder();
templateBuilder.locationId(AWS_REGION_1);
templateBuilder.smallest();
templateBuilder.options(userMetadata(tags));
return templateBuilder.build();
}
示例13: getTemplateInRegion2
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
public Template getTemplateInRegion2(Map<String, String> tags) {
TemplateBuilder templateBuilder = computeService.templateBuilder();
templateBuilder.locationId(AWS_REGION_2);
templateBuilder.smallest();
templateBuilder.options(userMetadata(tags));
return templateBuilder.build();
}
示例14: createNode
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
public NodeMetadata createNode(String groupName, Template template) throws Exception {
NodeMetadata node = getOnlyElement(computeService.createNodesInGroup(groupName, 1, template));
LOGGER.info(MessageFormat.format("<< node created {0}: {1}", node.getId(),
concat(node.getPrivateAddresses(), node.getPublicAddresses())));
nodes.add(node);
return node;
}
示例15: createNode
import org.jclouds.compute.domain.Template; //导入依赖的package包/类
@Override
public NodeMetadata createNode(Template template) {
try {
Set<? extends NodeMetadata> nodesInGroup =
this.computeServiceContext.getComputeService()
.createNodesInGroup(cloud.configuration().nodeGroup(), 1, template);
checkElementIndex(0, nodesInGroup.size());
checkState(nodesInGroup.size() == 1);
return nodesInGroup.iterator().next();
} catch (RunNodesException e) {
throw new RuntimeException(e);
}
}