Search in sources :

Example 11 with TemplateProfile

use of com.cloud.storage.TemplateProfile in project cloudstack by apache.

the class TemplateManagerImpl method deleteTemplate.

@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_DELETE, eventDescription = "deleting template", async = true)
public boolean deleteTemplate(DeleteTemplateCmd cmd) {
    Long templateId = cmd.getId();
    Account caller = CallContext.current().getCallingAccount();
    VMTemplateVO template = _tmpltDao.findById(templateId);
    if (template == null) {
        throw new InvalidParameterValueException("unable to find template with id " + templateId);
    }
    _accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
    if (template.getFormat() == ImageFormat.ISO) {
        throw new InvalidParameterValueException("Please specify a valid template.");
    }
    TemplateAdapter adapter = getAdapter(template.getHypervisorType());
    TemplateProfile profile = adapter.prepareDelete(cmd);
    return adapter.delete(profile);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateProfile(com.cloud.storage.TemplateProfile) ActionEvent(com.cloud.event.ActionEvent)

Example 12 with TemplateProfile

use of com.cloud.storage.TemplateProfile in project cloudstack by apache.

the class HypervisorTemplateAdapter method prepareDelete.

@Override
public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
    TemplateProfile profile = super.prepareDelete(cmd);
    Long zoneId = profile.getZoneId();
    if (zoneId != null && (storeMgr.getImageStore(zoneId) == null)) {
        throw new InvalidParameterValueException("Failed to find a secondary storage in the specified zone.");
    }
    return profile;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TemplateProfile(com.cloud.storage.TemplateProfile)

Example 13 with TemplateProfile

use of com.cloud.storage.TemplateProfile in project cloudstack by apache.

the class HypervisorTemplateAdapter method prepare.

@Override
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
    TemplateProfile profile = super.prepare(cmd);
    String url = profile.getUrl();
    UriUtils.validateUrl(cmd.getFormat(), url);
    profile.setUrl(url);
    // Check that the resource limit for secondary storage won't be exceeded
    _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()), ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
    return profile;
}
Also used : TemplateProfile(com.cloud.storage.TemplateProfile)

Example 14 with TemplateProfile

use of com.cloud.storage.TemplateProfile in project cloudstack by apache.

the class HypervisorTemplateAdapter method prepare.

@Override
public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException {
    TemplateProfile profile = super.prepare(cmd);
    // Check that the resource limit for secondary storage won't be exceeded
    _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()), ResourceType.secondary_storage);
    return profile;
}
Also used : TemplateProfile(com.cloud.storage.TemplateProfile)

Example 15 with TemplateProfile

use of com.cloud.storage.TemplateProfile in project cloudstack by apache.

the class HypervisorTemplateAdapter method prepare.

@Override
public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
    TemplateProfile profile = super.prepare(cmd);
    String url = profile.getUrl();
    UriUtils.validateUrl(ImageFormat.ISO.getFileExtension(), url);
    profile.setUrl(url);
    // Check that the resource limit for secondary storage won't be exceeded
    _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()), ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
    return profile;
}
Also used : TemplateProfile(com.cloud.storage.TemplateProfile)

Aggregations

TemplateProfile (com.cloud.storage.TemplateProfile)16 VMTemplateVO (com.cloud.storage.VMTemplateVO)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 Account (com.cloud.user.Account)6 ActionEvent (com.cloud.event.ActionEvent)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 UserVO (com.cloud.user.UserVO)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 GuestOS (com.cloud.storage.GuestOS)1 ImageFormat (com.cloud.storage.Storage.ImageFormat)1 AccountVO (com.cloud.user.AccountVO)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 URL (java.net.URL)1 GetUploadParamsResponse (org.apache.cloudstack.api.response.GetUploadParamsResponse)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)1 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)1