mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +01:00
Refactoring register commands for template and iso
This commit is contained in:
parent
d468a0bd7f
commit
d5b041a790
@ -18,44 +18,18 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.dc.DataCenterVO;
|
|
||||||
import com.cloud.storage.Storage.FileSystem;
|
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
|
||||||
import com.cloud.storage.VMTemplateHostVO;
|
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
|
|
||||||
|
@Implementation(method="registerIso", manager=Manager.TemplateManager)
|
||||||
public class RegisterIsoCmd extends BaseCmd {
|
public class RegisterIsoCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(RegisterIsoCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(RegisterIsoCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "registerisoresponse";
|
private static final String s_name = "registerisoresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.BOOTABLE, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DISPLAY_TEXT, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.IS_FEATURED, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.IS_PUBLIC, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.OS_TYPE_ID, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.URL, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.TRUE));
|
|
||||||
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -129,141 +103,143 @@ public class RegisterIsoCmd extends BaseCmd {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
|
||||||
return s_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
public String getResponse() {
|
||||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// TODO Auto-generated method stub
|
||||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
return null;
|
||||||
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
|
||||||
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
|
||||||
String url = (String)params.get(BaseCmd.Properties.URL.getName());
|
|
||||||
Boolean isPublic = (Boolean)params.get(BaseCmd.Properties.IS_PUBLIC.getName());
|
|
||||||
Boolean featured = (Boolean)params.get(BaseCmd.Properties.IS_FEATURED.getName());
|
|
||||||
Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
|
||||||
Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
|
|
||||||
Long zoneId = (Long) params.get(BaseCmd.Properties.ZONE_ID.getName());
|
|
||||||
|
|
||||||
if (isPublic == null) {
|
|
||||||
isPublic = Boolean.FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoneId.longValue() == -1) {
|
// @Override
|
||||||
zoneId = null;
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
}
|
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
|
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||||
long accountId = 1L; // default to system account
|
// String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
||||||
if (account != null) {
|
// String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
||||||
accountId = account.getId().longValue();
|
// String url = (String)params.get(BaseCmd.Properties.URL.getName());
|
||||||
}
|
// Boolean isPublic = (Boolean)params.get(BaseCmd.Properties.IS_PUBLIC.getName());
|
||||||
|
// Boolean featured = (Boolean)params.get(BaseCmd.Properties.IS_FEATURED.getName());
|
||||||
Account accountObj;
|
// Long guestOSId = (Long) params.get(BaseCmd.Properties.OS_TYPE_ID.getName());
|
||||||
if (account == null) {
|
// Boolean bootable = (Boolean) params.get(BaseCmd.Properties.BOOTABLE.getName());
|
||||||
accountObj = getManagementServer().findAccountById(accountId);
|
// Long zoneId = (Long) params.get(BaseCmd.Properties.ZONE_ID.getName());
|
||||||
} else {
|
//
|
||||||
accountObj = account;
|
// if (isPublic == null) {
|
||||||
}
|
// isPublic = Boolean.FALSE;
|
||||||
|
// }
|
||||||
boolean isAdmin = (accountObj.getType() == Account.ACCOUNT_TYPE_ADMIN);
|
//
|
||||||
|
// if (zoneId.longValue() == -1) {
|
||||||
if (!isAdmin && zoneId == null) {
|
// zoneId = null;
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid zone Id.");
|
// }
|
||||||
}
|
//
|
||||||
|
// long accountId = 1L; // default to system account
|
||||||
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
// if (account != null) {
|
||||||
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
// accountId = account.getId().longValue();
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid iso");
|
// }
|
||||||
}
|
//
|
||||||
|
// Account accountObj;
|
||||||
boolean allowPublicUserTemplates = Boolean.parseBoolean(getManagementServer().getConfigurationValue("allow.public.user.templates"));
|
// if (account == null) {
|
||||||
if (!isAdmin && !allowPublicUserTemplates && isPublic) {
|
// accountObj = getManagementServer().findAccountById(accountId);
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Only private ISOs can be created.");
|
// } else {
|
||||||
}
|
// accountObj = account;
|
||||||
|
// }
|
||||||
if (!isAdmin || featured == null) {
|
//
|
||||||
featured = Boolean.FALSE;
|
// boolean isAdmin = (accountObj.getType() == Account.ACCOUNT_TYPE_ADMIN);
|
||||||
}
|
//
|
||||||
|
// if (!isAdmin && zoneId == null) {
|
||||||
// If command is executed via 8096 port, set userId to the id of System account (1)
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid zone Id.");
|
||||||
if (userId == null) {
|
// }
|
||||||
userId = Long.valueOf(1);
|
//
|
||||||
}
|
// if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
||||||
|
// &&(!url.toLowerCase().endsWith("iso.gz"))){
|
||||||
if (bootable == null) {
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid iso");
|
||||||
bootable = Boolean.TRUE;
|
// }
|
||||||
}
|
//
|
||||||
|
// boolean allowPublicUserTemplates = Boolean.parseBoolean(getManagementServer().getConfigurationValue("allow.public.user.templates"));
|
||||||
//removing support for file:// type urls (bug: 4239)
|
// if (!isAdmin && !allowPublicUserTemplates && isPublic) {
|
||||||
if(url.toLowerCase().contains("file://")){
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Only private ISOs can be created.");
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "File:// type urls are currently unsupported");
|
// }
|
||||||
}
|
//
|
||||||
|
// if (!isAdmin || featured == null) {
|
||||||
Long templateId;
|
// featured = Boolean.FALSE;
|
||||||
try {
|
// }
|
||||||
templateId = getManagementServer().createTemplate(userId, zoneId, name, displayText, isPublic.booleanValue(), featured.booleanValue(), ImageFormat.ISO.toString(), FileSystem.cdfs.toString(), url, null, true, 64 /*bits*/, false, guestOSId, bootable);
|
//
|
||||||
} catch (Exception ex) {
|
// // If command is executed via 8096 port, set userId to the id of System account (1)
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
// if (userId == null) {
|
||||||
}
|
// userId = Long.valueOf(1);
|
||||||
|
// }
|
||||||
|
//
|
||||||
VMTemplateVO template = getManagementServer().findTemplateById(templateId);
|
// if (bootable == null) {
|
||||||
List<Pair<String, Object>> isoTags = new ArrayList<Pair<String, Object>>();
|
// bootable = Boolean.TRUE;
|
||||||
List<Object> iTagList = new ArrayList<Object>();
|
// }
|
||||||
if (template != null) {
|
//
|
||||||
List<DataCenterVO> zones = null;
|
// //removing support for file:// type urls (bug: 4239)
|
||||||
|
// if(url.toLowerCase().contains("file://")){
|
||||||
if (zoneId != null) {
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "File:// type urls are currently unsupported");
|
||||||
zones = new ArrayList<DataCenterVO>();
|
// }
|
||||||
zones.add(getManagementServer().findDataCenterById(zoneId));
|
//
|
||||||
} else {
|
// Long templateId;
|
||||||
zones = getManagementServer().listDataCenters();
|
// try {
|
||||||
}
|
// templateId = getManagementServer().createTemplate(userId, zoneId, name, displayText, isPublic.booleanValue(), featured.booleanValue(), ImageFormat.ISO.toString(), FileSystem.cdfs.toString(), url, null, true, 64 /*bits*/, false, guestOSId, bootable);
|
||||||
|
// } catch (Exception ex) {
|
||||||
for (DataCenterVO zone : zones) {
|
// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
|
||||||
VMTemplateHostVO isoHostRef = getManagementServer().findTemplateHostRef(templateId, zone.getId());
|
// }
|
||||||
|
//
|
||||||
// Use embeded object for response
|
//
|
||||||
List<Pair<String, Object>> listForEmbeddedObject = new ArrayList<Pair<String, Object>>();
|
// VMTemplateVO template = getManagementServer().findTemplateById(templateId);
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), template.getId().toString()));
|
// List<Pair<String, Object>> isoTags = new ArrayList<Pair<String, Object>>();
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), template.getName()));
|
// List<Object> iTagList = new ArrayList<Object>();
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), template.getDisplayText()));
|
// if (template != null) {
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(template.isPublicTemplate()).toString()));
|
// List<DataCenterVO> zones = null;
|
||||||
|
//
|
||||||
if (isoHostRef != null) {
|
// if (zoneId != null) {
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(isoHostRef.getCreated())));
|
// zones = new ArrayList<DataCenterVO>();
|
||||||
}
|
// zones.add(getManagementServer().findDataCenterById(zoneId));
|
||||||
|
// } else {
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.IS_READY.getName(), (isoHostRef != null && isoHostRef.getDownloadState() == Status.DOWNLOADED)));
|
// zones = getManagementServer().listDataCenters();
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.IS_FEATURED.getName(), Boolean.valueOf(template.isFeatured()).toString()));
|
// }
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), Boolean.valueOf(template.isBootable()).toString()));
|
//
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), template.getGuestOSId()));
|
// for (DataCenterVO zone : zones) {
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_NAME.getName(), getManagementServer().findGuestOSById(template.getGuestOSId()).getName()));
|
// VMTemplateHostVO isoHostRef = getManagementServer().findTemplateHostRef(templateId, zone.getId());
|
||||||
|
//
|
||||||
Account owner = getManagementServer().findAccountById(template.getAccountId());
|
// // Use embeded object for response
|
||||||
if (owner != null) {
|
// List<Pair<String, Object>> listForEmbeddedObject = new ArrayList<Pair<String, Object>>();
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT_ID.getName(), owner.getId()));
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), template.getId().toString()));
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), owner.getAccountName()));
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), template.getName()));
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), owner.getDomainId()));
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), template.getDisplayText()));
|
||||||
}
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.IS_PUBLIC.getName(), Boolean.valueOf(template.isPublicTemplate()).toString()));
|
||||||
|
//
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), zone.getId()));
|
// if (isoHostRef != null) {
|
||||||
listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), zone.getName()));
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(isoHostRef.getCreated())));
|
||||||
|
// }
|
||||||
iTagList.add(listForEmbeddedObject);
|
//
|
||||||
}
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.IS_READY.getName(), (isoHostRef != null && isoHostRef.getDownloadState() == Status.DOWNLOADED)));
|
||||||
}
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.IS_FEATURED.getName(), Boolean.valueOf(template.isFeatured()).toString()));
|
||||||
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.BOOTABLE.getName(), Boolean.valueOf(template.isBootable()).toString()));
|
||||||
Object[] iTag = new Object[iTagList.size()];
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(), template.getGuestOSId()));
|
||||||
for (int i = 0; i < iTagList.size(); i++) {
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_NAME.getName(), getManagementServer().findGuestOSById(template.getGuestOSId()).getName()));
|
||||||
iTag[i] = iTagList.get(i);
|
//
|
||||||
}
|
// Account owner = getManagementServer().findAccountById(template.getAccountId());
|
||||||
|
// if (owner != null) {
|
||||||
Pair<String, Object> templateTag = new Pair<String, Object>("iso", iTag);
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT_ID.getName(), owner.getId()));
|
||||||
isoTags.add(templateTag);
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), owner.getAccountName()));
|
||||||
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), owner.getDomainId()));
|
||||||
return isoTags;
|
// }
|
||||||
}
|
//
|
||||||
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), zone.getId()));
|
||||||
|
// listForEmbeddedObject.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), zone.getName()));
|
||||||
|
//
|
||||||
|
// iTagList.add(listForEmbeddedObject);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Object[] iTag = new Object[iTagList.size()];
|
||||||
|
// for (int i = 0; i < iTagList.size(); i++) {
|
||||||
|
// iTag[i] = iTagList.get(i);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Pair<String, Object> templateTag = new Pair<String, Object>("iso", iTag);
|
||||||
|
// isoTags.add(templateTag);
|
||||||
|
//
|
||||||
|
// return isoTags;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.api.commands.CreateTemplateCmd;
|
import com.cloud.api.commands.CreateTemplateCmd;
|
||||||
|
import com.cloud.api.commands.RegisterIsoCmd;
|
||||||
import com.cloud.api.commands.RegisterTemplateCmd;
|
import com.cloud.api.commands.RegisterTemplateCmd;
|
||||||
import com.cloud.exception.InternalErrorException;
|
import com.cloud.exception.InternalErrorException;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
@ -67,7 +68,7 @@ public interface TemplateManager extends Manager {
|
|||||||
*/
|
*/
|
||||||
Long create(long userId, Long zoneId, String name, String displayText, boolean isPublic, boolean featured, ImageFormat format, FileSystem fs, URI url, String chksum, boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable);
|
Long create(long userId, Long zoneId, String name, String displayText, boolean isPublic, boolean featured, ImageFormat format, FileSystem fs, URI url, String chksum, boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable);
|
||||||
Long registerTemplate(RegisterTemplateCmd cmd) throws InvalidParameterValueException, URISyntaxException, ResourceAllocationException;
|
Long registerTemplate(RegisterTemplateCmd cmd) throws InvalidParameterValueException, URISyntaxException, ResourceAllocationException;
|
||||||
|
Long registerIso(RegisterIsoCmd cmd) throws InvalidParameterValueException, IllegalArgumentException, ResourceAllocationException;
|
||||||
/**
|
/**
|
||||||
* Creates a Template
|
* Creates a Template
|
||||||
*
|
*
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import java.net.URI;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
|||||||
import com.cloud.agent.manager.AgentManager;
|
import com.cloud.agent.manager.AgentManager;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.RegisterIsoCmd;
|
||||||
import com.cloud.api.commands.RegisterTemplateCmd;
|
import com.cloud.api.commands.RegisterTemplateCmd;
|
||||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||||
import com.cloud.configuration.dao.ConfigurationDao;
|
import com.cloud.configuration.dao.ConfigurationDao;
|
||||||
@ -122,6 +124,75 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
@Inject ConfigurationDao _configDao;
|
@Inject ConfigurationDao _configDao;
|
||||||
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
|
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long registerIso(RegisterIsoCmd cmd) throws InvalidParameterValueException, IllegalArgumentException, ResourceAllocationException{
|
||||||
|
Account account = (Account)UserContext.current().getAccountObject();
|
||||||
|
Long userId = UserContext.current().getUserId();
|
||||||
|
String name = cmd.getName();
|
||||||
|
String displayText = cmd.getDisplayText();
|
||||||
|
String url = cmd.getUrl();
|
||||||
|
Boolean isPublic = cmd.isPublic();
|
||||||
|
Boolean featured = cmd.isFeatured();
|
||||||
|
Long guestOSId = cmd.getOsTypeId();
|
||||||
|
Boolean bootable = cmd.isBootable();
|
||||||
|
Long zoneId = cmd.getZoneId();
|
||||||
|
|
||||||
|
if (isPublic == null) {
|
||||||
|
isPublic = Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zoneId.longValue() == -1) {
|
||||||
|
zoneId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
long accountId = 1L; // default to system account
|
||||||
|
if (account != null) {
|
||||||
|
accountId = account.getId().longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Account accountObj;
|
||||||
|
if (account == null) {
|
||||||
|
accountObj = _accountDao.findById(accountId);
|
||||||
|
} else {
|
||||||
|
accountObj = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isAdmin = (accountObj.getType() == Account.ACCOUNT_TYPE_ADMIN);
|
||||||
|
|
||||||
|
if (!isAdmin && zoneId == null) {
|
||||||
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid zone Id.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if((!url.toLowerCase().endsWith("iso"))&&(!url.toLowerCase().endsWith("iso.zip"))&&(!url.toLowerCase().endsWith("iso.bz2"))
|
||||||
|
&&(!url.toLowerCase().endsWith("iso.gz"))){
|
||||||
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid iso");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean allowPublicUserTemplates = Boolean.parseBoolean(_configDao.getValue("allow.public.user.templates"));
|
||||||
|
if (!isAdmin && !allowPublicUserTemplates && isPublic) {
|
||||||
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Only private ISOs can be created.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAdmin || featured == null) {
|
||||||
|
featured = Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If command is executed via 8096 port, set userId to the id of System account (1)
|
||||||
|
if (userId == null) {
|
||||||
|
userId = Long.valueOf(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bootable == null) {
|
||||||
|
bootable = Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//removing support for file:// type urls (bug: 4239)
|
||||||
|
if(url.toLowerCase().contains("file://")){
|
||||||
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "File:// type urls are currently unsupported");
|
||||||
|
}
|
||||||
|
|
||||||
|
return createTemplateOrIso(userId, zoneId, name, displayText, isPublic.booleanValue(), featured.booleanValue(), ImageFormat.ISO.toString(), FileSystem.cdfs.toString(), url, null, true, 64 /*bits*/, false, guestOSId, bootable);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long registerTemplate(RegisterTemplateCmd cmd) throws InvalidParameterValueException, URISyntaxException, ResourceAllocationException{
|
public Long registerTemplate(RegisterTemplateCmd cmd) throws InvalidParameterValueException, URISyntaxException, ResourceAllocationException{
|
||||||
@ -201,6 +272,13 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
userId = Long.valueOf(1);
|
userId = Long.valueOf(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return createTemplateOrIso(userId, zoneId, name, displayText, isPublic, featured, format, "ext3", url, null, requiresHVM, bits, passwordEnabled, guestOSId, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long createTemplateOrIso(long userId, Long zoneId, String name, String displayText, boolean isPublic, boolean featured, String format, String diskType, String url, String chksum, boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable) throws InvalidParameterValueException,IllegalArgumentException, ResourceAllocationException {
|
||||||
|
try
|
||||||
|
{
|
||||||
if (name.length() > 32)
|
if (name.length() > 32)
|
||||||
{
|
{
|
||||||
throw new InvalidParameterValueException("Template name should be less than 32 characters");
|
throw new InvalidParameterValueException("Template name should be less than 32 characters");
|
||||||
@ -215,9 +293,9 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
throw new IllegalArgumentException("Image format is incorrect " + format + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
|
throw new IllegalArgumentException("Image format is incorrect " + format + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystem fileSystem = FileSystem.valueOf("ext3");
|
FileSystem fileSystem = FileSystem.valueOf(diskType);
|
||||||
if (fileSystem == null) {
|
if (fileSystem == null) {
|
||||||
throw new IllegalArgumentException("File system is incorrect " + "ext3" + ". Supported file systems are " + EnumUtils.listValues(FileSystem.values()));
|
throw new IllegalArgumentException("File system is incorrect " + diskType + ". Supported file systems are " + EnumUtils.listValues(FileSystem.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
URI uri = new URI(url);
|
URI uri = new URI(url);
|
||||||
@ -246,9 +324,8 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new IllegalArgumentException("Unable to find user with id " + userId);
|
throw new IllegalArgumentException("Unable to find user with id " + userId);
|
||||||
}
|
}
|
||||||
|
AccountVO account = _accountDao.findById(user.getAccountId());
|
||||||
AccountVO accountVO = _accountDao.findById(user.getAccountId());
|
if (_accountMgr.resourceLimitExceeded(account, ResourceType.template)) {
|
||||||
if (_accountMgr.resourceLimitExceeded(accountVO, ResourceType.template)) {
|
|
||||||
ResourceAllocationException rae = new ResourceAllocationException("Maximum number of templates and ISOs for account: " + account.getAccountName() + " has been exceeded.");
|
ResourceAllocationException rae = new ResourceAllocationException("Maximum number of templates and ISOs for account: " + account.getAccountName() + " has been exceeded.");
|
||||||
rae.setResourceType("template");
|
rae.setResourceType("template");
|
||||||
throw rae;
|
throw rae;
|
||||||
@ -265,9 +342,12 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
throw new IllegalArgumentException("Cannot use reserved names for templates");
|
throw new IllegalArgumentException("Cannot use reserved names for templates");
|
||||||
}
|
}
|
||||||
|
|
||||||
return create(userId, zoneId, name, displayText, isPublic, featured, imgfmt, fileSystem, uri, null, requiresHVM, bits, passwordEnabled, guestOSId, true);
|
return create(userId, zoneId, name, displayText, isPublic, featured, imgfmt, fileSystem, uri, chksum, requiresHvm, bits, enablePassword, guestOSId, bootable);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid URL " + url);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long create(long userId, Long zoneId, String name, String displayText, boolean isPublic, boolean featured, ImageFormat format, FileSystem fs, URI url, String chksum, boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable) {
|
public Long create(long userId, Long zoneId, String name, String displayText, boolean isPublic, boolean featured, ImageFormat format, FileSystem fs, URI url, String chksum, boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user