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