diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index b9f338dc6f4..2a2ab8e69bd 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -1727,6 +1727,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { } else { assert false : "Did someone add a new Startup command?"; } + + Long id = null; HostVO server = _hostDao.findByGuid(startup.getGuid()); @@ -1976,9 +1978,26 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { if (type == Host.Type.Routing) { StartupRoutingCommand scc = (StartupRoutingCommand) startup; + HypervisorType hypervisorType = scc.getHypervisorType(); boolean doCidrCheck = true; + + /*KVM:Enforcement that all the hosts in the cluster have the same os type, for migration*/ + if (scc.getHypervisorType() == HypervisorType.KVM) { + List hostsInCluster = _hostDao.listByCluster(clusterId); + if (!hostsInCluster.isEmpty()) { + HostVO oneHost = hostsInCluster.get(0); + _hostDao.loadDetails(oneHost); + String hostOsInCluster = oneHost.getDetail("Host.OS"); + String hostOs = scc.getHostDetails().get("Host.OS"); + if (!hostOsInCluster.equalsIgnoreCase(hostOs)) { + throw new IllegalArgumentException("Can't add host: " + startup.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," + + "in which there are " + hostOsInCluster + " hosts added"); + } + } + } + // If this command is from the agent simulator, don't do the CIDR // check if (scc.getAgentTag() != null && startup.getAgentTag().equalsIgnoreCase("vmops-simulator")) diff --git a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java index c05e8db3956..9eeb82fb6f6 100644 --- a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java +++ b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java @@ -197,9 +197,9 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, InetAddress ia = InetAddress.getByName(hostname); agentIp = ia.getHostAddress(); String guid = UUID.nameUUIDFromBytes(agentIp.getBytes()).toString(); - guid = guid + "-LibvirtComputingResource";/*tail added by agent.java*/ - if (_hostDao.findByGuid(guid) != null) { - s_logger.debug("Skipping " + agentIp + " because " + guid + " is already in the database."); + String guidWithTail = guid + "-LibvirtComputingResource";/*tail added by agent.java*/ + if (_hostDao.findByGuid(guidWithTail) != null) { + s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); return null; } @@ -233,11 +233,11 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer, kvmResource.configure("kvm agent", params); resources.put(kvmResource, details); - HostVO connectedHost = waitForHostConnect(dcId, podId, clusterId, guid); + HostVO connectedHost = waitForHostConnect(dcId, podId, clusterId, guidWithTail); if (connectedHost == null) return null; - details.put("guid", guid); + details.put("guid", guidWithTail); /*set cluster hypervisor type to xenserver*/ ClusterVO clu = _clusterDao.findById(clusterId); clu.setHypervisorType(HypervisorType.KVM.toString()); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 6910478c99c..36dc3ebbafd 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1524,7 +1524,7 @@ public class ManagementServerImpl implements ManagementServer { return true; } - private UserVm deployVirtualMachineImpl(long userId, long accountId, long dataCenterId, long serviceOfferingId, long templateId, Long diskOfferingId, + private UserVm deployVirtualMachineImpl(long userId, long accountId, long dataCenterId, long serviceOfferingId, VMTemplateVO template, Long diskOfferingId, String domain, String password, String displayName, String group, String userData, String [] networkGroups, long startEventId, long size) throws ResourceAllocationException, InsufficientStorageCapacityException, ExecutionException, StorageUnavailableException, ConcurrentOperationException { @@ -1533,12 +1533,14 @@ public class ManagementServerImpl implements ManagementServer { AccountVO account = _accountDao.findById(accountId); DataCenterVO dc = _dcDao.findById(dataCenterId); ServiceOfferingVO offering = _offeringsDao.findById(serviceOfferingId); - VMTemplateVO template = _templateDao.findById(templateId); - + // Make sure a valid template ID was specified if (template == null) { throw new InvalidParameterValueException("Please specify a valid template or ISO ID."); } + + long templateId = template.getId(); + byte [] decodedUserData = null; if (userData != null) { if (userData.length() >= 2* UserVmManager.MAX_USER_DATA_LENGTH_BYTES) { @@ -1869,7 +1871,12 @@ public class ManagementServerImpl implements ManagementServer { if (isIso && diskOffering == null) { throw new InvalidParameterValueException("Please specify a valid disk offering ID."); } - + + if (isIso) { + /*iso template doesn;t have hypervisor type, temporarily set it's type as user specified, pass it to storage allocator */ + template.setHypervisorType(HypervisorType.getType(cmd.getHypervisor())); + } + //if it is a custom disk offering,AND the size passed in here is <= 0; error out if(diskOffering != null && diskOffering.isCustomized() && size <= 0){ throw new InvalidParameterValueException("Please specify a valid disk size for VM creation; custom disk offering has no size set"); @@ -1891,6 +1898,8 @@ public class ManagementServerImpl implements ManagementServer { } } } + + byte [] decodedUserData = null; if (userData != null) { @@ -1930,7 +1939,7 @@ public class ManagementServerImpl implements ManagementServer { Long eventId = cmd.getStartEventId(); try { - return deployVirtualMachineImpl(userId, accountId, dataCenterId, serviceOfferingId, templateId, diskOfferingId, domain, password, displayName, group, userData, networkGroups, eventId, size); + return deployVirtualMachineImpl(userId, accountId, dataCenterId, serviceOfferingId, template, diskOfferingId, domain, password, displayName, group, userData, networkGroups, eventId, size); } catch (ResourceAllocationException e) { if(s_logger.isDebugEnabled()) s_logger.debug("Unable to deploy VM: " + e.getMessage());