Search in sources :

Example 1 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class TemplateAdapterBase method prepare.

@Override
public TemplateProfile prepare(final GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException {
    // check if the caller can operate with the template owner
    final Account caller = CallContext.current().getCallingAccount();
    final Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
    _accountMgr.checkAccess(caller, null, true, owner);
    final boolean isRouting = (cmd.isRoutingType() == null) ? false : cmd.isRoutingType();
    Long zoneId = cmd.getZoneId();
    // ignore passed zoneId if we are using region wide image store
    final List<ImageStoreVO> stores = _imgStoreDao.findRegionImageStores();
    if (stores != null && stores.size() > 0) {
        zoneId = -1L;
    }
    return prepare(false, CallContext.current().getCallingUserId(), cmd.getName(), cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), null, cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), zoneId, HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, cmd.isDynamicallyScalable(), isRouting ? TemplateType.ROUTING : TemplateType.USER);
}
Also used : Account(com.cloud.user.Account) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 2 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class ImageStoreProviderManagerImpl method listImageCacheStores.

@Override
public List<DataStore> listImageCacheStores() {
    final List<ImageStoreVO> stores = dataStoreDao.listImageCacheStores();
    final List<DataStore> imageStores = new ArrayList<>();
    for (final ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 3 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class ImageStoreProviderManagerImpl method listImageStoresByScope.

@Override
public List<DataStore> listImageStoresByScope(final ZoneScope scope) {
    final List<ImageStoreVO> stores = dataStoreDao.findByScope(scope);
    final List<DataStore> imageStores = new ArrayList<>();
    for (final ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 4 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class ImageStoreHelper method createImageStore.

public ImageStoreVO createImageStore(final Map<String, Object> params, final Map<String, String> details) {
    ImageStoreVO store = imageStoreDao.findByName((String) params.get("name"));
    if (store != null) {
        return store;
    }
    store = new ImageStoreVO();
    store.setProtocol((String) params.get("protocol"));
    store.setProviderName((String) params.get("providerName"));
    store.setScope((ScopeType) params.get("scope"));
    store.setDataCenterId((Long) params.get("zoneId"));
    final String uuid = (String) params.get("uuid");
    if (uuid != null) {
        store.setUuid(uuid);
    } else {
        store.setUuid(UUID.randomUUID().toString());
    }
    store.setUrl((String) params.get("url"));
    store.setName((String) params.get("name"));
    if (store.getName() == null) {
        store.setName(store.getUuid());
    }
    store.setRole((DataStoreRole) params.get("role"));
    if ("cifs".equalsIgnoreCase((String) params.get("protocol")) && details != null) {
        final String user = details.get("user");
        String password = details.get("password");
        final String domain = details.get("domain");
        String updatedPath = (String) params.get("url");
        if (user == null || password == null) {
            final String errMsg = "Missing cifs user and password details. Add them as details parameter.";
            throw new InvalidParameterValueException(errMsg);
        } else {
            try {
                password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
                details.put("password", password);
                updatedPath += "?user=" + user + "&password=" + password + "&domain=" + domain;
            } catch (final UnsupportedEncodingException e) {
                throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage());
            }
            store.setUrl(updatedPath);
        }
    }
    store = imageStoreDao.persist(store);
    // persist details
    if (details != null) {
        final Iterator<String> keyIter = details.keySet().iterator();
        while (keyIter.hasNext()) {
            final String key = keyIter.next().toString();
            final ImageStoreDetailVO detail = new ImageStoreDetailVO();
            detail.setStoreId(store.getId());
            detail.setName(key);
            String value = details.get(key);
            // encrypt swift key or s3 secret key
            if (key.equals(ApiConstants.KEY)) {
                value = DBEncryptionUtil.encrypt(value);
            }
            detail.setValue(value);
            imageStoreDetailsDao.persist(detail);
        }
    }
    return store;
}
Also used : ImageStoreDetailVO(com.cloud.storage.datastore.db.ImageStoreDetailVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 5 with ImageStoreVO

use of com.cloud.storage.datastore.db.ImageStoreVO in project cosmic by MissionCriticalCloud.

the class StorageCacheManagerImpl method getCacheStores.

protected List<DataStore> getCacheStores() {
    final QueryBuilder<ImageStoreVO> sc = QueryBuilder.create(ImageStoreVO.class);
    sc.and(sc.entity().getRole(), SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
    final List<ImageStoreVO> imageStoreVOs = sc.list();
    final List<DataStore> stores = new ArrayList<>();
    for (final ImageStoreVO vo : imageStoreVOs) {
        stores.add(dataStoreManager.getDataStore(vo.getId(), vo.getRole()));
    }
    return stores;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Aggregations

ImageStoreVO (com.cloud.storage.datastore.db.ImageStoreVO)19 Account (com.cloud.user.Account)8 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 DataCenterVO (com.cloud.dc.DataCenterVO)2 ImageStoreProvider (com.cloud.engine.subsystem.api.storage.ImageStoreProvider)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2 GuestOSVO (com.cloud.storage.GuestOSVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)2 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)2 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 Answer (com.cloud.agent.api.Answer)1 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)1