CLOUDSTACK-7588: [Vmware] Creating templates (with same names) from volumes get deleted from CS. Fix it by changing the unique name generation to the standard one used by registertemplate. Also cleaned up vmtemplatevo which had too many constructors.

This commit is contained in:
Nitin Mehta 2014-09-19 13:40:17 -07:00
parent 7877f3f960
commit 082aed3d33
2 changed files with 7 additions and 40 deletions

View File

@ -159,10 +159,8 @@ public class VMTemplateVO implements VirtualMachineTemplate {
uuid = UUID.randomUUID().toString();
}
/**
* Proper constructor for a new vm template.
*/
public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url,
//FIXME - Remove unwanted constructors.
private VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url,
boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable,
HypervisorType hyperType, Map<String, String> details) {
this(id,
@ -250,8 +248,8 @@ public class VMTemplateVO implements VirtualMachineTemplate {
state = State.Active;
}
// Has an extra attribute - isExtractable
public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
//FIXME - Remove unwanted constructors. Made them private for now
private VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId,
boolean bootable, HypervisorType hyperType, Map<String, String> details) {
this(id,
@ -278,34 +276,6 @@ public class VMTemplateVO implements VirtualMachineTemplate {
state = State.Active;
}
public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId,
boolean bootable, HypervisorType hyperType, String templateTag, Map<String, String> details) {
this(id,
uniqueName,
name,
format,
isPublic,
featured,
isExtractable,
type,
url,
created,
requiresHvm,
bits,
accountId,
cksum,
displayText,
enablePassword,
guestOSId,
bootable,
hyperType,
details);
this.templateTag = templateTag;
uuid = UUID.randomUUID().toString();
state = State.Active;
}
@Override
public boolean getEnablePassword() {
return enablePassword;

View File

@ -22,7 +22,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -1605,7 +1604,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
throw new InvalidParameterValueException("GuestOS with ID: " + guestOSId + " does not exist.");
}
String uniqueName = Long.valueOf((userId == null) ? 1 : userId).toString() + UUID.nameUUIDFromBytes(name.getBytes()).toString();
Long nextTemplateId = _tmpltDao.getNextInSequence(Long.class, "id");
String description = cmd.getDisplayText();
boolean isExtractable = false;
@ -1630,10 +1628,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
s_logger.debug("Adding template tag: " + templateTag);
}
}
privateTemplate =
new VMTemplateVO(nextTemplateId, uniqueName, name, ImageFormat.RAW, isPublic, featured, isExtractable, TemplateType.USER, null, null, requiresHvmValue,
bitsValue, templateOwner.getId(), null, description, passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails());
privateTemplate.setDynamicallyScalable(isDynamicScalingEnabled);
privateTemplate = new VMTemplateVO(nextTemplateId, name, ImageFormat.RAW, isPublic, featured, isExtractable,
TemplateType.USER, null, requiresHvmValue, bitsValue, templateOwner.getId(), null, description,
passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), false, isDynamicScalingEnabled);
if (sourceTemplateId != null) {
if (s_logger.isDebugEnabled()) {