bug 7365: return both physical and virutal size when creating private template

status 7365: resolved fixed
This commit is contained in:
anthony 2010-11-29 18:58:48 -08:00
parent d3325de5ae
commit fb0675bbf4
4 changed files with 33 additions and 55 deletions

View File

@ -1593,17 +1593,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
loc.addFormat(info);
loc.save();
return new CreatePrivateTemplateAnswer(cmd, true, "", tmplPath, info.virtualSize, tmplName, info.format);
return new CreatePrivateTemplateAnswer(cmd, true, "", tmplPath, info.virtualSize, info.size, tmplName, info.format);
} catch (LibvirtException e) {
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage(), null, 0, null, null);
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
} catch (URISyntaxException e) {
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage(), null, 0, null, null);
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
} catch (ConfigurationException e) {
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage(), null, 0, null, null);
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
} catch (InternalErrorException e) {
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage(), null, 0, null, null);
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
} catch (IOException e) {
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage(), null, 0, null, null);
return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
}
}
@ -1642,13 +1642,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
if (result != null) {
s_logger.debug("failed to create template: " + result);
return new CreatePrivateTemplateAnswer(cmd,
false,
result,
null,
0,
null,
null);
return new CreatePrivateTemplateAnswer(cmd, false, result);
}
Map<String, Object> params = new HashMap<String, Object>();
@ -1669,49 +1663,21 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
null,
templateInstallFolder + cmd.getUniqueName() + ".qcow2",
info.virtualSize,
info.size,
cmd.getUniqueName(),
ImageFormat.QCOW2);
} catch (URISyntaxException e) {
return new CreatePrivateTemplateAnswer(cmd,
false,
e.toString(),
null,
0,
null,
null);
return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
} catch (LibvirtException e) {
s_logger.debug("Failed to get secondary storage pool: " + e.toString());
return new CreatePrivateTemplateAnswer(cmd,
false,
e.toString(),
null,
0,
null,
null);
return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
} catch (InternalErrorException e) {
return new CreatePrivateTemplateAnswer(cmd,
false,
e.toString(),
null,
0,
null,
null);
return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
} catch (IOException e) {
return new CreatePrivateTemplateAnswer(cmd,
false,
e.toString(),
null,
0,
null,
null);
return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
} catch (ConfigurationException e) {
return new CreatePrivateTemplateAnswer(cmd,
false,
e.toString(),
null,
0,
null,
null);
return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
}
}

View File

@ -25,15 +25,18 @@ import com.cloud.storage.Storage.ImageFormat;
public class CreatePrivateTemplateAnswer extends Answer {
private String _path;
private long _virtualSize;
private long _physicalSize;
private String _uniqueName;
private ImageFormat _format;
public CreatePrivateTemplateAnswer() {}
public CreatePrivateTemplateAnswer(Command cmd, boolean success, String result, String path, long virtualSize, String uniqueName, ImageFormat format) {
public CreatePrivateTemplateAnswer(Command cmd, boolean success, String result, String path, long virtualSize,
long physicalSize, String uniqueName, ImageFormat format) {
super(cmd, success, result);
_path = path;
_virtualSize = virtualSize;
_physicalSize = physicalSize;
_uniqueName = uniqueName;
_format = format;
}
@ -58,6 +61,14 @@ public class CreatePrivateTemplateAnswer extends Answer {
_virtualSize = virtualSize;
}
public void setphysicalSize(long _physicalSize) {
this._physicalSize = _physicalSize;
}
public long getphysicalSize() {
return _physicalSize;
}
public String getUniqueName() {
return _uniqueName;
}

View File

@ -5458,14 +5458,14 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
String tmpltUUID = tmpltVDI.getUuid(conn);
String tmpltFilename = tmpltUUID + ".vhd";
long virtualSize = tmpltVDI.getVirtualSize(conn);
long size = tmpltVDI.getPhysicalUtilisation(conn);
long physicalSize = tmpltVDI.getPhysicalUtilisation(conn);
// create the template.properties file
result = postCreatePrivateTemplate(tmpltSrUUID, tmpltFilename, tmpltUUID, userSpecifiedName, null, size, virtualSize, templateId);
result = postCreatePrivateTemplate(tmpltSrUUID, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize, templateId);
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
}
installPath = installPath + "/" + tmpltFilename;
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, tmpltUUID, ImageFormat.VHD);
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUUID, ImageFormat.VHD);
} catch (XenAPIException e) {
details = "Creating template from volume " + volumeUUID + " failed due to " + e.getMessage();
s_logger.error(details, e);
@ -5520,15 +5520,15 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
String tmpltUUID = tmpltVDI.getUuid(conn);
String tmpltFilename = tmpltUUID + ".vhd";
long virtualSize = tmpltVDI.getVirtualSize(conn);
long size = tmpltVDI.getPhysicalUtilisation(conn);
long physicalSize = tmpltVDI.getPhysicalUtilisation(conn);
// create the template.properties file
result = postCreatePrivateTemplate(tmpltSrUUID, tmpltFilename, tmpltUUID, userSpecifiedName, null, size, virtualSize, newTemplateId);
result = postCreatePrivateTemplate(tmpltSrUUID, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize, newTemplateId);
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
}
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, tmpltUUID, ImageFormat.VHD);
return new CreatePrivateTemplateAnswer(cmd, true, null, installPath, virtualSize, physicalSize, tmpltUUID, ImageFormat.VHD);
} catch (XenAPIException e) {
details = "Creating template from snapshot " + backedUpSnapshotUuid + " failed due to " + e.getMessage();
s_logger.error(details, e);

View File

@ -2652,6 +2652,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
templateHostVO.setInstallPath(answer.getPath());
templateHostVO.setLastUpdated(new Date());
templateHostVO.setSize(answer.getVirtualSize());
templateHostVO.setPhysicalSize(answer.getphysicalSize());
_templateHostDao.persist(templateHostVO);
// Increment the number of templates