/** * Copyright (C) 2011 Cloud.com, Inc. All rights reserved. */ package com.cloud.baremetal; import java.util.Map; import javax.ejb.Local; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.baremetal.PxeServerManager.PxeServerType; import com.cloud.dc.dao.DataCenterDao; import com.cloud.deploy.DeployDestination; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.uservm.UserVm; import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Inject; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.ReservationContext; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile.Param; @Local(value = {PxeServerManager.class}) public class PxeServerManagerImpl implements PxeServerManager { private static final org.apache.log4j.Logger s_logger = Logger.getLogger(PxeServerManagerImpl.class); protected String _name; @Inject DataCenterDao _dcDao; @Inject HostDao _hostDao; @Inject AgentManager _agentMgr; @Inject ExternalDhcpManager exDhcpMgr; @Inject(adapter=PxeServerService.class) protected Adapters _services; @Override public boolean configure(String name, Map params) throws ConfigurationException { _name = name; return true; } @Override public boolean start() { return true; } @Override public boolean stop() { return true; } @Override public String getName() { return _name; } protected PxeServerService getServiceByType(String type) { PxeServerService _service; _service = _services.get(type); if (_service == null) { throw new CloudRuntimeException("Cannot find PXE service for " + type); } return _service; } @Override public Host addPxeServer(PxeServerProfile profile) { return getServiceByType(profile.getType()).addPxeServer(profile); } @Override public PxeServerResponse getApiResponse(Host pxeServer) { PxeServerResponse response = new PxeServerResponse(); response.setId(pxeServer.getId()); return response; } @Override public boolean prepare(PxeServerType type, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, Long pxeServerId) { return getServiceByType(type.getName()).prepare(profile, dest, context, pxeServerId); } @Override public boolean prepareCreateTemplate(PxeServerType type, Long pxeServerId, UserVm vm, String templateUrl) { return getServiceByType(type.getName()).prepareCreateTemplate(pxeServerId, vm, templateUrl); } @Override public PxeServerType getPxeServerType(HostVO host) { if (host.getResource().equalsIgnoreCase(PingPxeServerResource.class.getName())) { return PxeServerType.PING; } else { throw new CloudRuntimeException("Unkown PXE server resource " + host.getResource()); } } }