Configure jclouds group in virtualmachine tags

This commit is contained in:
Ignasi Barrera 2016-10-18 11:17:38 +02:00
parent 43eb65938c
commit bf40d2ed2b
2 changed files with 14 additions and 4 deletions

View File

@ -99,6 +99,8 @@ import com.google.common.collect.Lists;
@Singleton
public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VirtualMachine, VMHardware, VMImage, Location> {
public static final String GROUP_KEY = "jclouds_group";
private final CleanupResources cleanupResources;
private final AzureComputeApi api;
private final AzureComputeConstants azureComputeConstants;
@ -125,8 +127,6 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
AzureTemplateOptions templateOptions = template.getOptions().as(AzureTemplateOptions.class);
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 network ids => create one nic in each network
// TODO inbound ports
@ -145,6 +145,9 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
.hardwareProfile(hardwareProfile).storageProfile(storageProfile).osProfile(osProfile)
.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());
Plan plan = getMarketplacePlanFromImageMetadata(template.getImage());
@ -187,7 +190,8 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
for (Version version : versionList) {
Version versionDetails = osImageApi.getVersion(publisherName, offer.name(), sku.name(), version.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);
}
}

View File

@ -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.transform;
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.CUSTOM_IMAGE_OFFER;
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.name(virtualMachine.name());
builder.hostname(virtualMachine.name());
builder.group(nodeNamingConvention.extractGroup(virtualMachine.name()));
ProvisioningState provisioningState = virtualMachine.properties().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.privateAddresses(getPrivateIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
String groupFromMetadata = null;
if (virtualMachine.tags() != null) {
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();
builder.location(getLocation(locationName));