From 9e1525c0321d61357fa2c51d45cf8ee78ded5dbf Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 27 Feb 2014 15:17:38 -0800 Subject: [PATCH] CS-19377 [Baremetal] After deploy VM on Baremetal host, BM host fail to be PXE booted (cherry picked from commit 793a6a7177e7b2737b01c328951c86da1ba1808b) Signed-off-by: Animesh Chaturvedi --- .../networkservice/BaremetalDhcpElement.java | 14 +++++++++++--- .../networkservice/BaremetalDhcpManagerImpl.java | 7 +++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java index 8057cd42f91..b3fdab5b030 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java @@ -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 baremetalCaps = new HashMap(); - 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>(); 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 phyq = QueryBuilder.create(PhysicalNetworkVO.class); + phyq.and(phyq.entity().getDataCenterId(), Op.EQ, dest.getDataCenter().getId()); + PhysicalNetworkVO phynw = phyq.find(); + QueryBuilder 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; } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java index 82397f5b31b..e507b4d8716 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java @@ -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 hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId); + List 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);