Skip to content

Commit 082aed3

Browse files
committed
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.
1 parent 7877f3f commit 082aed3

File tree

2 files changed

+7
-40
lines changed

2 files changed

+7
-40
lines changed

engine/schema/src/com/cloud/storage/VMTemplateVO.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ public VMTemplateVO() {
159159
uuid = UUID.randomUUID().toString();
160160
}
161161

162-
/**
163-
* Proper constructor for a new vm template.
164-
*/
165-
public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url,
162+
//FIXME - Remove unwanted constructors.
163+
private VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url,
166164
boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable,
167165
HypervisorType hyperType, Map<String, String> details) {
168166
this(id,
@@ -250,8 +248,8 @@ public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format,
250248
state = State.Active;
251249
}
252250

253-
// Has an extra attribute - isExtractable
254-
public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
251+
//FIXME - Remove unwanted constructors. Made them private for now
252+
private VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
255253
String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId,
256254
boolean bootable, HypervisorType hyperType, Map<String, String> details) {
257255
this(id,
@@ -278,34 +276,6 @@ public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format,
278276
state = State.Active;
279277
}
280278

281-
public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
282-
String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId,
283-
boolean bootable, HypervisorType hyperType, String templateTag, Map<String, String> details) {
284-
this(id,
285-
uniqueName,
286-
name,
287-
format,
288-
isPublic,
289-
featured,
290-
isExtractable,
291-
type,
292-
url,
293-
created,
294-
requiresHvm,
295-
bits,
296-
accountId,
297-
cksum,
298-
displayText,
299-
enablePassword,
300-
guestOSId,
301-
bootable,
302-
hyperType,
303-
details);
304-
this.templateTag = templateTag;
305-
uuid = UUID.randomUUID().toString();
306-
state = State.Active;
307-
}
308-
309279
@Override
310280
public boolean getEnablePassword() {
311281
return enablePassword;

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.HashMap;
2323
import java.util.List;
2424
import java.util.Map;
25-
import java.util.UUID;
2625
import java.util.concurrent.ExecutionException;
2726
import java.util.concurrent.ExecutorService;
2827
import java.util.concurrent.Executors;
@@ -1605,7 +1604,6 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
16051604
throw new InvalidParameterValueException("GuestOS with ID: " + guestOSId + " does not exist.");
16061605
}
16071606

1608-
String uniqueName = Long.valueOf((userId == null) ? 1 : userId).toString() + UUID.nameUUIDFromBytes(name.getBytes()).toString();
16091607
Long nextTemplateId = _tmpltDao.getNextInSequence(Long.class, "id");
16101608
String description = cmd.getDisplayText();
16111609
boolean isExtractable = false;
@@ -1630,10 +1628,9 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
16301628
s_logger.debug("Adding template tag: " + templateTag);
16311629
}
16321630
}
1633-
privateTemplate =
1634-
new VMTemplateVO(nextTemplateId, uniqueName, name, ImageFormat.RAW, isPublic, featured, isExtractable, TemplateType.USER, null, null, requiresHvmValue,
1635-
bitsValue, templateOwner.getId(), null, description, passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails());
1636-
privateTemplate.setDynamicallyScalable(isDynamicScalingEnabled);
1631+
privateTemplate = new VMTemplateVO(nextTemplateId, name, ImageFormat.RAW, isPublic, featured, isExtractable,
1632+
TemplateType.USER, null, requiresHvmValue, bitsValue, templateOwner.getId(), null, description,
1633+
passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), false, isDynamicScalingEnabled);
16371634

16381635
if (sourceTemplateId != null) {
16391636
if (s_logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)