mirror of https://github.com/apache/jclouds.git
Configure jclouds group in virtualmachine tags
This commit is contained in:
parent
43eb65938c
commit
bf40d2ed2b
|
@ -99,6 +99,8 @@ import com.google.common.collect.Lists;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VirtualMachine, VMHardware, VMImage, Location> {
|
public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VirtualMachine, VMHardware, VMImage, Location> {
|
||||||
|
|
||||||
|
public static final String GROUP_KEY = "jclouds_group";
|
||||||
|
|
||||||
private final CleanupResources cleanupResources;
|
private final CleanupResources cleanupResources;
|
||||||
private final AzureComputeApi api;
|
private final AzureComputeApi api;
|
||||||
private final AzureComputeConstants azureComputeConstants;
|
private final AzureComputeConstants azureComputeConstants;
|
||||||
|
@ -125,8 +127,6 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
|
||||||
AzureTemplateOptions templateOptions = template.getOptions().as(AzureTemplateOptions.class);
|
AzureTemplateOptions templateOptions = template.getOptions().as(AzureTemplateOptions.class);
|
||||||
String azureGroup = locationToResourceGroupName.apply(template.getLocation().getId());
|
String azureGroup = locationToResourceGroupName.apply(template.getLocation().getId());
|
||||||
|
|
||||||
// TODO Store group apart from the name to be able to identify nodes with
|
|
||||||
// custom names in the configured group
|
|
||||||
// TODO ARM specific options
|
// TODO ARM specific options
|
||||||
// TODO network ids => create one nic in each network
|
// TODO network ids => create one nic in each network
|
||||||
// TODO inbound ports
|
// TODO inbound ports
|
||||||
|
@ -145,6 +145,9 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
|
||||||
.hardwareProfile(hardwareProfile).storageProfile(storageProfile).osProfile(osProfile)
|
.hardwareProfile(hardwareProfile).storageProfile(storageProfile).osProfile(osProfile)
|
||||||
.networkProfile(networkProfile).build();
|
.networkProfile(networkProfile).build();
|
||||||
|
|
||||||
|
// Store group apart from the name to be able to identify nodes with
|
||||||
|
// custom names in the configured group
|
||||||
|
template.getOptions().getUserMetadata().put(GROUP_KEY, group);
|
||||||
Map<String, String> metadataAndTags = metadataAndTagsAsCommaDelimitedValue(template.getOptions());
|
Map<String, String> metadataAndTags = metadataAndTagsAsCommaDelimitedValue(template.getOptions());
|
||||||
Plan plan = getMarketplacePlanFromImageMetadata(template.getImage());
|
Plan plan = getMarketplacePlanFromImageMetadata(template.getImage());
|
||||||
|
|
||||||
|
@ -187,7 +190,8 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
|
||||||
for (Version version : versionList) {
|
for (Version version : versionList) {
|
||||||
Version versionDetails = osImageApi.getVersion(publisherName, offer.name(), sku.name(), version.name());
|
Version versionDetails = osImageApi.getVersion(publisherName, offer.name(), sku.name(), version.name());
|
||||||
VMImage vmImage = VMImage.azureImage().publisher(publisherName).offer(offer.name()).sku(sku.name())
|
VMImage vmImage = VMImage.azureImage().publisher(publisherName).offer(offer.name()).sku(sku.name())
|
||||||
.version(versionDetails.name()).location(location).versionProperties(version.properties()).build();
|
.version(versionDetails.name()).location(location).versionProperties(versionDetails.properties())
|
||||||
|
.build();
|
||||||
osImagesRef.add(vmImage);
|
osImagesRef.add(vmImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.collect.Iterables.find;
|
import static com.google.common.collect.Iterables.find;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static com.google.common.collect.Iterables.tryFind;
|
import static com.google.common.collect.Iterables.tryFind;
|
||||||
|
import static org.jclouds.azurecompute.arm.compute.AzureComputeServiceAdapter.GROUP_KEY;
|
||||||
import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CONTAINER_NAME;
|
import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CONTAINER_NAME;
|
||||||
import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_OFFER;
|
import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_OFFER;
|
||||||
import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.encodeFieldsToUniqueId;
|
import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.encodeFieldsToUniqueId;
|
||||||
|
@ -148,7 +149,6 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
builder.providerId(virtualMachine.id());
|
builder.providerId(virtualMachine.id());
|
||||||
builder.name(virtualMachine.name());
|
builder.name(virtualMachine.name());
|
||||||
builder.hostname(virtualMachine.name());
|
builder.hostname(virtualMachine.name());
|
||||||
builder.group(nodeNamingConvention.extractGroup(virtualMachine.name()));
|
|
||||||
|
|
||||||
ProvisioningState provisioningState = virtualMachine.properties().provisioningState();
|
ProvisioningState provisioningState = virtualMachine.properties().provisioningState();
|
||||||
if (ProvisioningState.SUCCEEDED.equals(provisioningState)) {
|
if (ProvisioningState.SUCCEEDED.equals(provisioningState)) {
|
||||||
|
@ -175,10 +175,16 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
builder.publicAddresses(getPublicIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
|
builder.publicAddresses(getPublicIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
|
||||||
builder.privateAddresses(getPrivateIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
|
builder.privateAddresses(getPrivateIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
|
||||||
|
|
||||||
|
String groupFromMetadata = null;
|
||||||
if (virtualMachine.tags() != null) {
|
if (virtualMachine.tags() != null) {
|
||||||
addMetadataAndParseTagsFromCommaDelimitedValue(builder, virtualMachine.tags());
|
addMetadataAndParseTagsFromCommaDelimitedValue(builder, virtualMachine.tags());
|
||||||
|
groupFromMetadata = virtualMachine.tags().get(GROUP_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to read the group from the virtual machine tags, and parse the name if missing
|
||||||
|
builder.group(groupFromMetadata != null ? groupFromMetadata : nodeNamingConvention.extractGroup(virtualMachine
|
||||||
|
.name()));
|
||||||
|
|
||||||
String locationName = virtualMachine.location();
|
String locationName = virtualMachine.location();
|
||||||
builder.location(getLocation(locationName));
|
builder.location(getLocation(locationName));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue