[Baremetal] After deploy VM on Baremetal host, BM host fail to be PXE booted
(cherry picked from commit 793a6a7177)

Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
This commit is contained in:
frank 2014-02-27 15:17:38 -08:00 committed by Animesh Chaturvedi
parent e9a3d41285
commit 9e1525c032
2 changed files with 14 additions and 7 deletions

View File

@ -25,6 +25,8 @@ import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import org.apache.log4j.Logger;
import com.cloud.baremetal.database.BaremetalDhcpVO;
@ -64,12 +66,14 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv
@Inject NicDao _nicDao;
@Inject BaremetalDhcpManager _dhcpMgr;
@Inject
PhysicalNetworkDao phyNwDao;
static {
Capability cap = new Capability(BaremetalDhcpManager.BAREMETAL_DHCP_SERVICE_CAPABITLITY);
Map<Capability, String> baremetalCaps = new HashMap<Capability, String>();
baremetalCaps.put(cap, null);
baremetalCaps.put(Capability.DhcpAccrossMultipleSubnets, Boolean.TRUE.toString());
baremetalCaps.put(cap, null);
baremetalCaps.put(Capability.DhcpAccrossMultipleSubnets, Boolean.TRUE.toString());
capabilities = new HashMap<Service, Map<Capability, String>>();
capabilities.put(Service.Dhcp, baremetalCaps);
}
@ -87,8 +91,12 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv
private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) {
Pod pod = dest.getPod();
if (pod != null && dest.getDataCenter().getNetworkType() == NetworkType.Basic && trafficType == TrafficType.Guest) {
QueryBuilder<PhysicalNetworkVO> phyq = QueryBuilder.create(PhysicalNetworkVO.class);
phyq.and(phyq.entity().getDataCenterId(), Op.EQ, dest.getDataCenter().getId());
PhysicalNetworkVO phynw = phyq.find();
QueryBuilder<BaremetalDhcpVO> sc = QueryBuilder.create(BaremetalDhcpVO.class);
sc.and(sc.entity().getPodId(), Op.EQ,pod.getId());
sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, phynw.getId());
return sc.find() != null;
}

View File

@ -133,14 +133,13 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh
public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile,
DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
Long zoneId = profile.getVirtualMachine().getDataCenterId();
Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, null, zoneId);
if (hosts.size() == 0) {
throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId);
}
if (hosts.size() > 1) {
throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId);
}
HostVO h = hosts.get(0);