JCLOUDS-664 Azurecompute-arm Update image name logic

This commit is contained in:
Rita Zhang 2016-07-01 16:08:55 -07:00 committed by Ignasi Barrera
parent 10d9b38976
commit cf438b6c1a
4 changed files with 14 additions and 12 deletions

View File

@ -265,9 +265,10 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VMDeplo
public VMImage getImage(final String id) {
String[] fields = VMImageToImage.decodeFieldsFromUniqueId(id);
if (fields[2].startsWith(CUSTOM_IMAGE_PREFIX)) {
String storage = fields[2].substring(CUSTOM_IMAGE_PREFIX.length());
String vhd = fields[3];
VMImage ref = VMImage.create(CUSTOM_IMAGE_PREFIX + azureGroup, CUSTOM_IMAGE_PREFIX + storage, vhd, null, fields[0], false);
String name = fields[2].substring(CUSTOM_IMAGE_PREFIX.length());
String sku = fields[3];
String version = "1";
VMImage ref = VMImage.create(CUSTOM_IMAGE_PREFIX + azureGroup, CUSTOM_IMAGE_PREFIX + name, sku, version, fields[0], false);
return ref;
}

View File

@ -85,6 +85,7 @@ public class AzureComputeImageExtension implements ImageExtension {
public ListenableFuture<Image> createImage(ImageTemplate template) {
final CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;
final String id = cloneTemplate.getSourceNodeId();
final String name = cloneTemplate.getName();
final String storageAccountName = id.replaceAll("[^A-Za-z0-9 ]", "") + "stor";
// VM needs to be stopped before it can be generalized
@ -118,7 +119,7 @@ public class AzureComputeImageExtension implements ImageExtension {
VirtualMachine vm = api.getVirtualMachineApi(group).get(id);
String location = vm.location();
final VMImage ref = VMImage.create(CUSTOM_IMAGE_PREFIX + group, CUSTOM_IMAGE_PREFIX + storageAccountName, disks[0], disks[1], location, false);
final VMImage ref = VMImage.create(CUSTOM_IMAGE_PREFIX + group, CUSTOM_IMAGE_PREFIX + name, disks[0], disks[1], location, false);
return imageReferenceToImage.apply(ref);
}
}

View File

@ -17,6 +17,7 @@
package org.jclouds.azurecompute.arm.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_PREFIX;
import static org.jclouds.azurecompute.arm.compute.functions.DeploymentToNodeMetadata.AZURE_LOGIN_PASSWORD;
import static org.jclouds.azurecompute.arm.compute.functions.DeploymentToNodeMetadata.AZURE_LOGIN_USERNAME;
@ -79,8 +80,14 @@ public class VMImageToImage implements Function<VMImage, Image> {
public Image apply(final VMImage image) {
Credentials credentials = new Credentials(AZURE_LOGIN_USERNAME, AZURE_LOGIN_PASSWORD);
String name = "";
if (image.offer().startsWith(CUSTOM_IMAGE_PREFIX)) {
name = image.offer().substring(CUSTOM_IMAGE_PREFIX.length());
} else {
name = image.offer();
}
final ImageBuilder builder = new ImageBuilder()
.name(image.offer())
.name(name)
.description(image.sku())
.status(Image.Status.AVAILABLE)
.version(image.sku())

View File

@ -34,7 +34,6 @@ import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
import org.jclouds.azurecompute.arm.domain.VirtualMachine;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.azurecompute.arm.domain.StorageService;
import com.google.common.base.Function;
@ -79,12 +78,6 @@ public class CleanupResources implements Function<String, Boolean> {
boolean deploymentDeleteStatus = false;
if (jobDone) {
StorageService ss = api.getStorageAccountApi(group).get(storageAccountName);
if (ss != null) {
storageAcctDeleteStatus = api.getStorageAccountApi(group).delete(storageAccountName);
} else {
storageAcctDeleteStatus = true;
}
Deployment deployment = api.getDeploymentApi(group).get(id);
if (deployment != null) {
uri = api.getDeploymentApi(group).delete(id);