Search in sources :

Example 1 with IpmISetBootDevCommand

use of com.cloud.agent.api.baremetal.IpmISetBootDevCommand 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)

Example 2 with IpmISetBootDevCommand

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

the class BaremetalKickStartServiceImpl method prepare.

@Override
public boolean prepare(VirtualMachineProfile profile, NicProfile nic, Network network, DeployDestination dest, ReservationContext context) {
    try {
        if (DataCenter.NetworkType.Basic.equals(dest.getDataCenter().getNetworkType())) {
            if (!preparePxeInBasicZone(profile, nic, dest, context)) {
                return false;
            }
        } else {
            if (!preparePxeInAdvancedZone(profile, nic, network, dest, context)) {
                return false;
            }
        }
        IpmISetBootDevCommand bootCmd = new IpmISetBootDevCommand(BootDev.pxe);
        Answer aws = _agentMgr.send(dest.getHost().getId(), bootCmd);
        if (!aws.getResult()) {
            s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails());
        }
        return aws.getResult();
    } catch (Exception e) {
        s_logger.warn("Cannot prepare PXE server", e);
        return false;
    }
}
Also used : Answer(com.cloud.agent.api.Answer) IpmISetBootDevCommand(com.cloud.agent.api.baremetal.IpmISetBootDevCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

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