@Override
 public void createAsync(
     DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
   CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
   AsyncCallbackDispatcher<BaseImageStoreDriverImpl, DownloadAnswer> caller =
       AsyncCallbackDispatcher.create(this);
   caller.setContext(context);
   if (data.getType() == DataObjectType.TEMPLATE) {
     caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
     if (s_logger.isDebugEnabled()) {
       s_logger.debug("Downloading template to data store " + dataStore.getId());
     }
     _downloadMonitor.downloadTemplateToStorage(data, caller);
   } else if (data.getType() == DataObjectType.VOLUME) {
     caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
     if (s_logger.isDebugEnabled()) {
       s_logger.debug("Downloading volume to data store " + dataStore.getId());
     }
     _downloadMonitor.downloadVolumeToStorage(data, caller);
   }
 }
  @Override
  public VMTemplateVO create(TemplateProfile profile) {
    VMTemplateVO template = persistTemplate(profile);

    if (template == null) {
      throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
    }

    _downloadMonitor.downloadTemplateToStorage(template, profile.getZoneId());
    _resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);

    return template;
  }