add xenserver backend code: download template from http directly

This commit is contained in:
Edison Su 2012-12-18 18:34:13 -08:00
parent 644b783110
commit 0581ea763a
20 changed files with 403 additions and 51 deletions

View File

@ -19,6 +19,7 @@
package org.apache.cloudstack.engine.subsystem.api.storage;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
@ -35,7 +36,7 @@ public interface PrimaryDataStoreInfo {
public long getId();
public String getUuid();
public Volume.State getManagedState();
public DataCenterResourceEntity.State getManagedState();
public String getName();
public String getType();
public PrimaryDataStoreLifeCycle getLifeCycle();

View File

@ -32,7 +32,7 @@ public interface VolumeInfo {
public String getPath();
public PrimaryDataStoreInfo getDataStore() ;
public String getTemplateUuid();
public String getTemplatePath() ;
public String getTemplatePath();
public VolumeType getType();
public VolumeDiskType getDiskType();
public long getId();

View File

@ -91,4 +91,16 @@ public class ImageDataStoreImpl implements ImageDataStore {
return to;
}
@Override
public String getType() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getUri() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -23,7 +23,7 @@ import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorage;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
@ -48,7 +48,7 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
@Override
public boolean copyTemplate(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep) {
ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore);
CopyTemplateToPrimaryStorage copyCommand = new CopyTemplateToPrimaryStorage(imageTo);
CopyTemplateToPrimaryStorageCmd copyCommand = new CopyTemplateToPrimaryStorageCmd(imageTo);
ep.sendMessage(copyCommand);
return true;
}
@ -56,7 +56,7 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
@Override
public void copyTemplateAsync(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep, AsyncCompletionCallback<CommandResult> callback) {
ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore);
CopyTemplateToPrimaryStorage copyCommand = new CopyTemplateToPrimaryStorage(imageTo);
CopyTemplateToPrimaryStorageCmd copyCommand = new CopyTemplateToPrimaryStorageCmd(imageTo);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this).setParentCallback(callback)
.setOperationName("defaultImageStrategy.copytemplate.callback")
.setContextParam("templateStore", templateStore);

View File

@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.HostEndpointRpcServer;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorage;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
@ -50,7 +50,7 @@ public class MockHypervsiorHostEndPointRpcServer implements HostEndpointRpcServe
public void run() {
try {
Answer answer = new Answer(cmd, false, "unknown command");
if (cmd instanceof CopyTemplateToPrimaryStorage) {
if (cmd instanceof CopyTemplateToPrimaryStorageCmd) {
answer = new CopyTemplateToPrimaryStorageAnswer(cmd, UUID.randomUUID().toString());
} else if (cmd instanceof CreateVolumeFromBaseImageCommand) {
answer = new CreateVolumeAnswer(cmd, UUID.randomUUID().toString());

View File

@ -1,23 +1,25 @@
package org.apache.cloudstack.storage.command;
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
import org.apache.cloudstack.storage.to.TemplateTO;
import org.apache.cloudstack.storage.to.VolumeTO;
import com.cloud.agent.api.Command;
public class CopyTemplateToPrimaryStorage extends Command {
public class CopyTemplateToPrimaryStorageCmd extends Command implements StorageSubSystemCommand {
private ImageOnPrimayDataStoreTO imageTO;
protected CopyTemplateToPrimaryStorage() {
protected CopyTemplateToPrimaryStorageCmd() {
super();
}
public CopyTemplateToPrimaryStorage(ImageOnPrimayDataStoreTO image) {
public CopyTemplateToPrimaryStorageCmd(ImageOnPrimayDataStoreTO image) {
super();
this.imageTO = image;
}
public ImageOnPrimayDataStoreTO getImage() {
return this.imageTO;
}
@Override
public boolean executeInSequence() {

View File

@ -23,14 +23,22 @@ import org.apache.cloudstack.storage.to.VolumeTO;
import com.cloud.agent.api.Command;
public class CreateVolumeFromBaseImageCommand extends Command {
private VolumeTO volume;
private ImageOnPrimayDataStoreTO image;
public class CreateVolumeFromBaseImageCommand extends Command implements StorageSubSystemCommand {
private final VolumeTO volume;
private final ImageOnPrimayDataStoreTO image;
public CreateVolumeFromBaseImageCommand(VolumeTO volume, ImageOnPrimayDataStoreTO image) {
this.volume = volume;
this.image = image;
}
public VolumeTO getVolume() {
return this.volume;
}
public ImageOnPrimayDataStoreTO getImage() {
return this.image;
}
@Override
public boolean executeInSequence() {

View File

@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.command;
public interface StorageSubSystemCommand {
}

View File

@ -31,4 +31,6 @@ public interface TemplateInfo {
String getPath();
String getUuid();
long getVirtualSize();
}

View File

@ -20,4 +20,6 @@ package org.apache.cloudstack.storage.image.store;
public interface ImageDataStoreInfo {
public long getImageDataStoreId();
public String getType();
public String getUri();
}

View File

@ -3,7 +3,18 @@ package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
public class ImageDataStoreTO {
private final String type;
private final String uri;
public ImageDataStoreTO(ImageDataStoreInfo dataStore) {
this.type = dataStore.getType();
this.uri = dataStore.getUri();
}
public String getType() {
return this.type;
}
public String getUri() {
return this.uri;
}
}

View File

@ -21,7 +21,24 @@ package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
public class ImageOnPrimayDataStoreTO {
private final String pathOnPrimaryDataStore;
private final PrimaryDataStoreTO dataStore;
private final TemplateTO template;
public ImageOnPrimayDataStoreTO(TemplateOnPrimaryDataStoreInfo template) {
this.pathOnPrimaryDataStore = template.getPath();
this.dataStore = new PrimaryDataStoreTO(template.getPrimaryDataStore());
this.template = new TemplateTO(template.getTemplate());
}
public String getPathOnPrimaryDataStore() {
return this.pathOnPrimaryDataStore;
}
public PrimaryDataStoreTO getPrimaryDataStore() {
return this.dataStore;
}
public TemplateTO getTemplate() {
return this.template;
}
}

View File

@ -3,7 +3,24 @@ package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
public class PrimaryDataStoreTO {
private final String uuid;
private final String name;
private final String type;
public PrimaryDataStoreTO(PrimaryDataStoreInfo dataStore) {
this.uuid = dataStore.getUuid();
this.name = dataStore.getName();
this.type = dataStore.getType();
}
public String getUuid() {
return this.uuid;
}
public String getName() {
return this.name;
}
public String getType() {
return this.type;
}
}

View File

@ -1,9 +1,39 @@
package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.storage.image.TemplateInfo;
public class TemplateTO {
private final String path;
private final String uuid;
private final VolumeDiskType diskType;
private final ImageDataStoreTO imageDataStore;
private final long size;
public TemplateTO(TemplateInfo template) {
this.path = template.getPath();
this.uuid = template.getUuid();
this.diskType = template.getDiskType();
this.imageDataStore = new ImageDataStoreTO(template.getImageDataStore());
this.size = template.getVirtualSize();
}
public String getPath() {
return this.path;
}
public String getUuid() {
return this.uuid;
}
public VolumeDiskType getDiskType() {
return this.diskType;
}
public ImageDataStoreTO getImageDataStore() {
return this.imageDataStore;
}
public long getSize() {
return this.size;
}
}

View File

@ -1,9 +1,40 @@
package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
public class VolumeTO {
private final String uuid;
private final String path;
private final VolumeType volumeType;
private final VolumeDiskType diskType;
private final PrimaryDataStoreTO dataStore;
public VolumeTO(VolumeInfo volume) {
this.uuid = volume.getUuid();
this.path = volume.getPath();
this.volumeType = volume.getType();
this.diskType = volume.getDiskType();
this.dataStore = new PrimaryDataStoreTO(volume.getDataStore());
}
public String getUuid() {
return this.uuid;
}
public String getPath() {
return this.path;
}
public VolumeType getVolumeType() {
return this.volumeType;
}
public VolumeDiskType getDiskType() {
return this.diskType;
}
public PrimaryDataStoreTO getDataStore() {
return this.dataStore;
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
@ -196,14 +197,14 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
public void createVoluemFromBaseImageAsync(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore, AsyncCompletionCallback<CommandResult> callback) {
VolumeObject vo = (VolumeObject) volume;
vo.setVolumeDiskType(templateStore.getTemplate().getDiskType());
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(callback)
AsyncCallbackDispatcher<DefaultPrimaryDataStore> caller = new AsyncCallbackDispatcher<DefaultPrimaryDataStore>(this);
caller.setCallback(caller.getTarget().createVoluemFromBaseImageAsyncCallback(null, null))
.setOperationName("primarydatastore.createvolumefrombaseImage");
this.driver.createVolumeFromBaseImageAsync(vo, templateStore, caller);
}
@AsyncCallbackHandler(operationName="primarydatastore.createvolumefrombaseImage")
public void createVoluemFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback) {
public Object createVoluemFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback, Object parames) {
AsyncCallbackDispatcher parent = callback.getParentCallback();
CommandResult result = callback.getResult();
parent.complete(result);
@ -222,7 +223,7 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
}
@Override
public Volume.State getManagedState() {
public DataCenterResourceEntity.State getManagedState() {
// TODO Auto-generated method stub
return null;
}

View File

@ -18,9 +18,8 @@
*/
package org.apache.cloudstack.storage.volume.test;
import org.apache.cloudstack.storage.HostEndpointRpcServer;
import org.apache.cloudstack.storage.image.motion.ImageMotionService;
import org.apache.cloudstack.storage.test.MockHypervsiorHostEndPointRpcServer;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -40,9 +39,4 @@ public class TestConfiguration {
public ClusterDao clusterDao() {
return Mockito.mock(ClusterDaoImpl.class);
}
@Bean
public HostEndpointRpcServer rpcServer() {
return new MockHypervsiorHostEndPointRpcServer();
}
}

View File

@ -1,22 +1,15 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-hypervisor-xen</artifactId>
<name>Apache CloudStack Plugin - Hypervisor Xen</name>
@ -27,11 +20,22 @@
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-storage</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-network-ovs</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>xapi</artifactId>
@ -42,6 +46,6 @@
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
</dependency>
</dependencies>
</project>

View File

@ -176,6 +176,7 @@ import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.agent.api.storage.StorageCommand;
import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.PortForwardingRuleTO;
@ -305,6 +306,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
protected boolean _canBridgeFirewall = false;
protected boolean _isOvs = false;
protected List<VIF> _tmpDom0Vif = new ArrayList<VIF>();
protected XenServerStorageResource storageResource;
public enum SRType {
NFS, LVM, ISCSI, ISO, LVMOISCSI, LVMOHBA, EXT, FILE;
@ -557,6 +559,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((Site2SiteVpnCfgCommand) cmd);
} else if (clazz == CheckS2SVpnConnectionsCommand.class) {
return execute((CheckS2SVpnConnectionsCommand) cmd);
} else if (clazz == StorageCommand.class) {
return this.storageResource.handleStorageCommands((StorageCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
@ -5528,9 +5532,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
CheckXenHostInfo();
this.storageResource = getStorageResource();
return true;
}
protected XenServerStorageResource getStorageResource() {
return new XenServerStorageResource(this);
}
private void CheckXenHostInfo() throws ConfigurationException {
Connection conn = _connPool.slaveConnect(_host.ip, _username, _password);

View File

@ -0,0 +1,187 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.cloud.hypervisor.xen.resource;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.cloudstack.storage.to.ImageDataStoreTO;
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.cloudstack.storage.to.TemplateTO;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.utils.exception.CloudRuntimeException;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.PBD;
import com.xensource.xenapi.SR;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.BadServerResponse;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VDI;
public class XenServerStorageResource {
private static final Logger s_logger = Logger.getLogger(XenServerStorageResource.class);
protected CitrixResourceBase hypervisorResource;
public XenServerStorageResource(CitrixResourceBase resource) {
this.hypervisorResource = resource;
}
public Answer handleStorageCommands(StorageSubSystemCommand command) {
if (command instanceof CopyTemplateToPrimaryStorageCmd) {
return this.execute((CopyTemplateToPrimaryStorageCmd)command);
}
return new Answer((Command)command, false, "not implemented yet");
}
private long getTemplateSize(String url) {
HttpGet method = new HttpGet(url);
HttpClient client = new HttpClient();
try {
int responseCode = client.executeMethod(method);
if (responseCode != HttpStatus.SC_OK) {
throw new CloudRuntimeException("http get returns error code:" + responseCode);
}
method.get
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected Answer directDownloadHttpTemplate(TemplateTO template, PrimaryDataStoreTO primarDataStore) {
String primaryStoreUuid = primarDataStore.getUuid();
Connection conn = hypervisorResource.getConnection();
SR poolsr = null;
VDI vdi = null;
try {
Set<SR> srs = SR.getByNameLabel(conn, primaryStoreUuid);
if (srs.size() != 1) {
throw new CloudRuntimeException("storage uuid: " + primaryStoreUuid + " is not unique");
}
poolsr = srs.iterator().next();
VDI.Record vdir = new VDI.Record();
vdir.nameLabel = "Base-Image-" + UUID.randomUUID().toString();
vdir.SR = poolsr;
vdir.type = Types.VdiType.USER;
vdir.virtualSize = template.getSize();
vdi = VDI.create(conn, vdir);
vdir = vdi.getRecord(conn);
String vdiLocation = vdir.location;
Set<PBD> pbds = poolsr.getPBDs(conn);
if (pbds.size() != 1) {
throw new CloudRuntimeException("Don't how to handle multiple pbds:" + pbds.size() + " for sr: " + poolsr.getUuid(conn));
}
PBD pbd = pbds.iterator().next();
PBD.Record pbdRec = pbd.getRecord(conn);
Map<String, String> deviceCfg = pbd.getDeviceConfig(conn);
String pbdLocation = deviceCfg.get("location");
if (pbdLocation == null) {
throw new CloudRuntimeException("Can't get pbd: " + pbd.getUuid(conn) + " location");
}
String vdiPath = pbdLocation + "/" + vdiLocation;
//download a url into vdipath
} catch (BadServerResponse e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XenAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlRpcException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected Answer execute(CopyTemplateToPrimaryStorageCmd cmd) {
ImageOnPrimayDataStoreTO imageTO = cmd.getImage();
TemplateTO template = imageTO.getTemplate();
ImageDataStoreTO imageStore = template.getImageDataStore();
if (imageStore.getType().equalsIgnoreCase("http")) {
return directDownloadHttpTemplate(template, imageTO.getPrimaryDataStore());
} else {
return new Answer(cmd, false, "not implemented yet");
/*
String tmplturl = cmd.getUrl();
String poolName = cmd.getPoolUuid();
int wait = cmd.getWait();
try {
URI uri = new URI(tmplturl);
String tmplpath = uri.getHost() + ":" + uri.getPath();
Connection conn = hypervisorResource.getConnection();
SR poolsr = null;
Set<SR> srs = SR.getByNameLabel(conn, poolName);
if (srs.size() != 1) {
String msg = "There are " + srs.size() + " SRs with same name: " + poolName;
s_logger.warn(msg);
return new PrimaryStorageDownloadAnswer(msg);
} else {
poolsr = srs.iterator().next();
}
String pUuid = poolsr.getUuid(conn);
boolean isISCSI = IsISCSI(poolsr.getType(conn));
String uuid = copy_vhd_from_secondarystorage(conn, tmplpath, pUuid, wait);
VDI tmpl = getVDIbyUuid(conn, uuid);
VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
String snapshotUuid = snapshotvdi.getUuid(conn);
snapshotvdi.setNameLabel(conn, "Template " + cmd.getName());
String parentuuid = getVhdParent(conn, pUuid, snapshotUuid, isISCSI);
VDI parent = getVDIbyUuid(conn, parentuuid);
Long phySize = parent.getPhysicalUtilisation(conn);
tmpl.destroy(conn);
poolsr.scan(conn);
try{
Thread.sleep(5000);
} catch (Exception e) {
}
return new PrimaryStorageDownloadAnswer(snapshotvdi.getUuid(conn), phySize);
} catch (Exception e) {
String msg = "Catch Exception " + e.getClass().getName() + " on host:" + _host.uuid + " for template: "
+ tmplturl + " due to " + e.toString();
s_logger.warn(msg, e);
return new PrimaryStorageDownloadAnswer(msg);
}*/
}
}
}