mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
get vmware works
This commit is contained in:
parent
dfd6a29fba
commit
90de46c4fe
@ -57,6 +57,7 @@ public class VolumeObjectTO implements DataTO {
|
||||
this.setVolumeId(volume.getId());
|
||||
this.chainInfo = volume.getChainInfo();
|
||||
this.volumeType = volume.getVolumeType();
|
||||
this.name = volume.getName();
|
||||
this.setId(volume.getId());
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,12 @@
|
||||
<artifactId>cloud-plugin-hypervisor-xen</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-plugin-hypervisor-vmware</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -36,23 +38,33 @@ import com.cloud.agent.api.SetupCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.HostEnvironment;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.vmware.VmwareServerDiscoverer;
|
||||
import com.cloud.hypervisor.xen.resource.XcpOssResource;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager {
|
||||
private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class);
|
||||
private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>();
|
||||
@Inject
|
||||
HostDao hostDao;
|
||||
@Inject
|
||||
ClusterDao clusterDao;
|
||||
@Inject
|
||||
ClusterDetailsDao clusterDetailsDao;
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
// TODO Auto-generated method stub
|
||||
@ -104,14 +116,39 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
|
||||
ServerResource resource = null;
|
||||
if (host.getHypervisorType() == HypervisorType.XenServer) {
|
||||
resource = new XcpOssResource();
|
||||
try {
|
||||
resource.configure(host.getName(), params);
|
||||
|
||||
} catch (ConfigurationException e) {
|
||||
logger.debug("Failed to load resource:" + e.toString());
|
||||
}
|
||||
} else if (host.getHypervisorType() == HypervisorType.VMware) {
|
||||
ClusterVO cluster = clusterDao.findById(host.getClusterId());
|
||||
String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
String userName = clusterDetailsDao.findDetail(cluster.getId(), "username").getValue();
|
||||
String password = clusterDetailsDao.findDetail(cluster.getId(), "password").getValue();
|
||||
VmwareServerDiscoverer discover = new VmwareServerDiscoverer();
|
||||
|
||||
Map<? extends ServerResource, Map<String, String>> resources = discover.find(host.getDataCenterId(), host.getPodId(), host.getClusterId(), uri, userName, password, null);
|
||||
for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
|
||||
resource = entry.getKey();
|
||||
}
|
||||
if (resource == null) {
|
||||
throw new CloudRuntimeException("can't find resource");
|
||||
}
|
||||
} catch (DiscoveryException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
resource.configure(host.getName(), params);
|
||||
hostResourcesMap.put(hostId, resource);
|
||||
} catch (ConfigurationException e) {
|
||||
logger.debug("Failed to load resource:" + e.toString());
|
||||
}
|
||||
hostResourcesMap.put(hostId, resource);
|
||||
HostEnvironment env = new HostEnvironment();
|
||||
SetupCommand cmd = new SetupCommand(env);
|
||||
cmd.setNeedSetup(true);
|
||||
|
||||
@ -41,6 +41,7 @@ import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.hypervisor.HypervisorGuruManager;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@ -52,6 +53,8 @@ public class RemoteHostEndPoint implements EndPoint {
|
||||
AgentManager agentMgr;
|
||||
@Inject
|
||||
HostEndpointRpcServer rpcServer;
|
||||
@Inject
|
||||
protected HypervisorGuruManager _hvGuruMgr;
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
public RemoteHostEndPoint() {
|
||||
@ -83,7 +86,8 @@ public class RemoteHostEndPoint implements EndPoint {
|
||||
public Answer sendMessage(Command cmd) {
|
||||
String errMsg = null;
|
||||
try {
|
||||
return agentMgr.send(getId(), cmd);
|
||||
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
|
||||
return agentMgr.send(newHostId, cmd);
|
||||
} catch (AgentUnavailableException e) {
|
||||
errMsg = e.toString();
|
||||
s_logger.debug("Failed to send command, due to Agent:" + getId() + ", " + e.toString());
|
||||
@ -160,7 +164,8 @@ public class RemoteHostEndPoint implements EndPoint {
|
||||
@Override
|
||||
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
|
||||
try {
|
||||
agentMgr.send(this.hostId, new Commands(cmd), new CmdRunner(callback));
|
||||
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(this.hostId, cmd);
|
||||
agentMgr.send(newHostId, new Commands(cmd), new CmdRunner(callback));
|
||||
} catch (AgentUnavailableException e) {
|
||||
throw new CloudRuntimeException("Unable to send message", e);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
@Inject
|
||||
HostDao hostDao;
|
||||
private String findOneHostInaScope = "select id from host where "
|
||||
+ " status = 'Up' and hypervisor_type != 'VMware' and type in ('Routing', 'SecondaryStorageVM') ";
|
||||
+ " status = 'Up' and type in ('Routing', 'SecondaryStorageVM') ";
|
||||
private String findOneHostOnPrimaryStorage = "select id from host where "
|
||||
+ "status = 'Up' and type = 'Routing' ";
|
||||
|
||||
|
||||
@ -28,6 +28,7 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants.VMDetails;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -286,7 +287,8 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
|
||||
cmd instanceof CopyVolumeCommand ||
|
||||
cmd instanceof CreateVolumeOVACommand ||
|
||||
cmd instanceof PrepareOVAPackingCommand ||
|
||||
cmd instanceof CreateVolumeFromSnapshotCommand) {
|
||||
cmd instanceof CreateVolumeFromSnapshotCommand ||
|
||||
cmd instanceof CopyCommand) {
|
||||
needDelegation = true;
|
||||
}
|
||||
/* Fang: remove this before checking in */
|
||||
|
||||
@ -328,14 +328,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
|
||||
DataTO srcData = cmd.getSrcTO();
|
||||
TemplateObjectTO template = (TemplateObjectTO)srcData;
|
||||
DataStoreTO imageStore = template.getDataStore();
|
||||
DataTO destData = cmd.getDestTO();
|
||||
VolumeObjectTO volume = (VolumeObjectTO)destData;
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
|
||||
if (imageStore != null && !(imageStore instanceof NfsTO)) {
|
||||
return new CopyCmdAnswer("unsupported protocol");
|
||||
}
|
||||
NfsTO nfsImageStore = (NfsTO)imageStore;
|
||||
PrimaryDataStoreTO srcStore = (PrimaryDataStoreTO)template.getDataStore();
|
||||
|
||||
|
||||
try {
|
||||
VmwareContext context = this.hostService.getServiceContext(null);
|
||||
@ -351,7 +348,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
|
||||
// attach volume id to make the name unique
|
||||
String vmdkName = volume.getName() + "-" + volume.getId();
|
||||
if (nfsImageStore == null) {
|
||||
if (srcStore == null) {
|
||||
// create a root volume for blank VM
|
||||
String dummyVmName = this.hostService.getWorkerName(context, cmd, 0);
|
||||
|
||||
@ -379,8 +376,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
vmMo.destroy();
|
||||
}
|
||||
} else {
|
||||
String templateUrl = nfsImageStore.getUrl() + File.separator + template.getPath();
|
||||
VirtualMachineMO vmTemplate = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUrl), true);
|
||||
String templatePath = template.getPath();
|
||||
VirtualMachineMO vmTemplate = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templatePath), true);
|
||||
if (vmTemplate == null) {
|
||||
s_logger.warn("Template host in vSphere is not in connected state, request template reload");
|
||||
return new CopyCmdAnswer("Template host in vSphere is not in connected state, request template reload");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user