Search in sources :

Example 1 with PrepareCreateTemplateCommand

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

the class BareMetalPingServiceImpl method prepareCreateTemplate.

@Override
public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl) {
    List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    if (nics.size() != 1) {
        throw new CloudRuntimeException("Wrong nic number " + nics.size() + " of vm " + vm.getId());
    }
    /* use last host id when VM stopped */
    Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId());
    HostVO host = _hostDao.findById(hostId);
    DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    NicVO nic = nics.get(0);
    String mask = nic.getIPv4Netmask();
    String mac = nic.getMacAddress();
    String ip = nic.getIPv4Address();
    String gateway = nic.getIPv4Gateway();
    String dns = dc.getDns1();
    if (dns == null) {
        dns = dc.getDns2();
    }
    try {
        PrepareCreateTemplateCommand cmd = new PrepareCreateTemplateCommand(ip, mac, mask, gateway, dns, templateUrl);
        Answer ans = _agentMgr.send(pxeServerId, cmd);
        return ans.getResult();
    } catch (Exception e) {
        s_logger.debug("Prepare for creating baremetal template failed", e);
        return false;
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Answer(com.cloud.agent.api.Answer) PreparePxeServerAnswer(com.cloud.agent.api.baremetal.PreparePxeServerAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrepareCreateTemplateCommand(com.cloud.agent.api.baremetal.PrepareCreateTemplateCommand)

Aggregations

Answer (com.cloud.agent.api.Answer)1 PrepareCreateTemplateCommand (com.cloud.agent.api.baremetal.PrepareCreateTemplateCommand)1 PreparePxeServerAnswer (com.cloud.agent.api.baremetal.PreparePxeServerAnswer)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 HostVO (com.cloud.host.HostVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NicVO (com.cloud.vm.NicVO)1