Search in sources :

Example 1 with PreparePxeServerCommand

use of com.cloud.agent.api.baremetal.PreparePxeServerCommand in project cloudstack by apache.

the class BareMetalPingServiceImpl method prepare.

@Override
public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, Network network, DeployDestination dest, ReservationContext context) {
    QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
    sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.PING.toString());
    sc.and(sc.entity().getPodId(), Op.EQ, dest.getPod().getId());
    BaremetalPxeVO pxeVo = sc.find();
    if (pxeVo == null) {
        throw new CloudRuntimeException("No PING PXE server found in pod: " + dest.getPod().getId() + ", you need to add it before starting VM");
    }
    long pxeServerId = pxeVo.getHostId();
    String mac = pxeNic.getMacAddress();
    String ip = pxeNic.getIPv4Address();
    String gateway = pxeNic.getIPv4Gateway();
    String mask = pxeNic.getIPv4Netmask();
    String dns = pxeNic.getIPv4Dns1();
    if (dns == null) {
        dns = pxeNic.getIPv4Dns2();
    }
    try {
        String tpl = profile.getTemplate().getUrl();
        assert tpl != null : "How can a null template get here!!!";
        PreparePxeServerCommand cmd = new PreparePxeServerCommand(ip, mac, mask, gateway, dns, tpl, profile.getVirtualMachine().getInstanceName(), dest.getHost().getName());
        PreparePxeServerAnswer ans = (PreparePxeServerAnswer) _agentMgr.send(pxeServerId, cmd);
        if (!ans.getResult()) {
            s_logger.warn("Unable tot program PXE server: " + pxeVo.getId() + " because " + ans.getDetails());
            return false;
        }
        IpmISetBootDevCommand bootCmd = new IpmISetBootDevCommand(BootDev.pxe);
        Answer anw = _agentMgr.send(dest.getHost().getId(), bootCmd);
        if (!anw.getResult()) {
            s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + anw.getDetails());
        }
        return anw.getResult();
    } catch (Exception e) {
        s_logger.warn("Cannot prepare PXE server", e);
        return false;
    }
}
Also used : Answer(com.cloud.agent.api.Answer) PreparePxeServerAnswer(com.cloud.agent.api.baremetal.PreparePxeServerAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparePxeServerCommand(com.cloud.agent.api.baremetal.PreparePxeServerCommand) IpmISetBootDevCommand(com.cloud.agent.api.baremetal.IpmISetBootDevCommand) PreparePxeServerAnswer(com.cloud.agent.api.baremetal.PreparePxeServerAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO)

Aggregations

Answer (com.cloud.agent.api.Answer)1 IpmISetBootDevCommand (com.cloud.agent.api.baremetal.IpmISetBootDevCommand)1 PreparePxeServerAnswer (com.cloud.agent.api.baremetal.PreparePxeServerAnswer)1 PreparePxeServerCommand (com.cloud.agent.api.baremetal.PreparePxeServerCommand)1 BaremetalPxeVO (com.cloud.baremetal.database.BaremetalPxeVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1