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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations