Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine/schema/src/com/cloud/host/dao/HostDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat

List<HostVO> findHypervisorHostInCluster(long clusterId);

HostVO findOlderHypervisorHostInCluster(long clusterId);

/**
* @param type
* @param clusterId
Expand Down
17 changes: 17 additions & 0 deletions engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,23 @@ public List<HostVO> findHypervisorHostInCluster(long clusterId) {
return listBy(sc);
}

@Override
public HostVO findOlderHypervisorHostInCluster(long clusterId) {
SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
sc.setParameters("type", Host.Type.Routing);
sc.setParameters("cluster", clusterId);
sc.setParameters("status", Status.Up);
sc.setParameters("resourceState", ResourceState.Enabled);
Filter orderByFilter = new Filter(HostVO.class, "created", true, null, null);

List<HostVO> hosts = search(sc, orderByFilter, null, false);
if (hosts != null && hosts.size() > 0) {
return hosts.get(0);
}

return null;
}

@Override
public List<Long> listAllHosts(long zoneId) {
SearchCriteria<Long> sc = HostIdSearch.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -71,6 +72,8 @@
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.host.dao.HostDao;
import com.cloud.host.HostVO;
import com.cloud.host.Host;
import com.cloud.host.Status;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
Expand Down Expand Up @@ -120,6 +123,7 @@
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SshHelper;
import com.cloud.utils.UriUtils;
import com.cloud.vm.DomainRouterVO;

public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService {
Expand All @@ -138,6 +142,8 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Inject
private NetworkModel _netMgr;
@Inject
private HostDao _hostDao;
@Inject
private ClusterDao _clusterDao;
@Inject
private ClusterDetailsDao _clusterDetailsDao;
Expand Down Expand Up @@ -374,6 +380,29 @@ private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Excep
}
}

private HostMO getOlderHostInCluster(Long clusterId, VmwareContext serviceContext) throws Exception {
HostVO host = _hostDao.findOlderHypervisorHostInCluster(clusterId);
if (host == null) {
return null;
}

ManagedObjectReference morSrcHost = HypervisorHostHelper.getHypervisorHostMorFromGuid(host.getGuid());
if (morSrcHost == null) {
Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
if (clusterDetails.get("url") == null) {
return null;
}

URI uriForHost = new URI(UriUtils.encodeURIComponent(clusterDetails.get("url") + "/" + host.getName()));
morSrcHost = serviceContext.getHostMorByPath(URLDecoder.decode(uriForHost.getPath(), "UTF-8"));
if (morSrcHost == null) {
return null;
}
}

return new HostMO(serviceContext, morSrcHost);
}

@Override
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId, String hostInventoryPath)
throws Exception {
Expand Down Expand Up @@ -426,6 +455,11 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
// For ESX host, we need to enable host firewall to allow VNC access
HostMO hostMo = new HostMO(serviceContext, mor);
prepareHost(hostMo, privateTrafficLabel);
HostMO olderHostMo = getOlderHostInCluster(clusterId, serviceContext);
if (olderHostMo != null) {
hostMo.copyPortGroupsFromHost(olderHostMo);
}

returnedHostList.add(mor);
return returnedHostList;
} else {
Expand Down
73 changes: 73 additions & 0 deletions vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
import com.vmware.vim25.HostOpaqueNetworkInfo;
import com.vmware.vim25.HostPortGroup;
import com.vmware.vim25.HostPortGroupPort;
import com.vmware.vim25.HostPortGroupSpec;
import com.vmware.vim25.HostRuntimeInfo;
import com.vmware.vim25.HostSystemConnectionState;
Expand Down Expand Up @@ -127,6 +128,43 @@ public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Excep
return null;
}

public List<HostPortGroupSpec> getHostPortGroupSpecs() throws Exception {
HostNetworkInfo hostNetInfo = getHostNetworkInfo();
if (hostNetInfo == null) {
return null;
}

List<HostPortGroup> portGroups = hostNetInfo.getPortgroup();
if (portGroups == null) {
return null;
}

List<HostPortGroupSpec> portGroupSpecs = new ArrayList<HostPortGroupSpec>();
for (HostPortGroup portGroup : portGroups) {
if (!isVMKernelPort(portGroup)) {
portGroupSpecs.add(portGroup.getSpec());
}
}

return portGroupSpecs;
}

private boolean isVMKernelPort(HostPortGroup portGroup) {
assert (portGroup != null);
List<HostPortGroupPort> ports = portGroup.getPort();
if (ports == null) {
return false;
}

for (HostPortGroupPort port : ports) {
if (port.getType().equalsIgnoreCase("host")) {
return true;
}
}

return false;
}

@Override
public String getHyperHostName() throws Exception {
return getName();
Expand Down Expand Up @@ -1110,4 +1148,39 @@ public String getNetworkName(String netMorVal) throws Exception {
}
return networkName;
}

public void createPortGroup(HostPortGroupSpec spec) throws Exception {
if (spec == null) {
return;
}

synchronized (_mor.getValue().intern()) {
HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO();
if (hostNetMo == null) {
return;
}

ManagedObjectReference morNetwork = getNetworkMor(spec.getName());
if (morNetwork == null) {
hostNetMo.addPortGroup(spec);
}
}
}

public void copyPortGroupsFromHost(HostMO srcHost) throws Exception {
if (srcHost == null) {
return;
}

List<HostPortGroupSpec> portGroupSpecs = srcHost.getHostPortGroupSpecs();
if (portGroupSpecs == null || portGroupSpecs.isEmpty()) {
s_logger.debug("No port groups in the host: " + srcHost.getName());
return;
}

for (HostPortGroupSpec spec : portGroupSpecs) {
s_logger.debug("Creating port group: " + spec.getName() + " in the host: " + getName());
createPortGroup(spec);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,30 @@ public void action(Long param) {
}
}

public static ManagedObjectReference getHypervisorHostMorFromGuid(String guid) {
if (guid == null) {
return null;
}

String[] tokens = guid.split("@");
if (tokens == null || tokens.length != 2) {
s_logger.error("Invalid content in host guid");
return null;
}

String[] hostTokens = tokens[0].split(":");
if (hostTokens == null || hostTokens.length != 2) {
s_logger.error("Invalid content in host guid");
return null;
}

ManagedObjectReference morHyperHost = new ManagedObjectReference();
morHyperHost.setType(hostTokens[0]);
morHyperHost.setValue(hostTokens[1]);

return morHyperHost;
}

public static String getScsiController(Pair<String, String> controllerInfo, String recommendedController) {
String rootDiskController = controllerInfo.first();
String dataDiskController = controllerInfo.second();
Expand Down