*
* @param request
* @return
*/
public boolean modifyImageAttribute(EC2ModifyImageAttribute request) {
CloudStackInfoResponse updateTemplatePermissions = null;
try {
// reset case
if (request.getReset() != null) {
updateTemplatePermissions = getApi().updateTemplatePermissions(request.getImageId(), null, null,
null, null, "reset");
}
// add users
List<String> addedUsers = request.getAddedUsers();
if (addedUsers != null && ! addedUsers.isEmpty()) {
String accounts = new String();
for (String usr : addedUsers) {
accounts = accounts + "," + usr;
}
updateTemplatePermissions = getApi().updateTemplatePermissions(request.getImageId(), accounts, null,
null, null, "add");
}
// remove users
List<String> removedUsers = request.getRemovedUsers();
if (removedUsers != null && ! removedUsers.isEmpty()) {
String accounts = new String();
for (String usr : removedUsers) {
accounts = accounts + "," + usr;
}
updateTemplatePermissions = getApi().updateTemplatePermissions(request.getImageId(), accounts, null,
null, null, "remove");
}
// Make public
if (request.getIsPublic() != null) {
updateTemplatePermissions = getApi().updateTemplatePermissions(request.getImageId(), null, null,
null, request.getIsPublic(), null);
}
} catch (Exception e) {
logger.error( "EC2 ModifyImage - ", e);
throw new EC2ServiceException(ServerError.InternalError, e.getMessage());
}
// Unfortunately, the error is thrown before we parse the response text returned from CS, so this error
// handling is unnecessary.
if (updateTemplatePermissions != null) {
if (updateTemplatePermissions.getSuccess() != true) {
throw new EC2ServiceException(ServerError.InternalError, updateTemplatePermissions.getDisplayText());
}
return updateTemplatePermissions.getSuccess();
} else
return false;
}