Search in sources :

Example 6 with BaremetalPxeVO

use of com.cloud.baremetal.database.BaremetalPxeVO in project cloudstack by apache.

the class BaremetalKickStartServiceImpl method preparePxeInBasicZone.

private boolean preparePxeInBasicZone(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) throws AgentUnavailableException, OperationTimedoutException {
    NetworkVO nwVO = _nwDao.findById(nic.getNetworkId());
    QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
    sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString());
    sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, nwVO.getPhysicalNetworkId());
    BaremetalPxeVO pxeVo = sc.find();
    if (pxeVo == null) {
        throw new CloudRuntimeException("No kickstart PXE server found in pod: " + dest.getPod().getId() + ", you need to add it before starting VM");
    }
    VMTemplateVO template = _tmpDao.findById(profile.getTemplateId());
    List<String> tuple = parseKickstartUrl(profile);
    String ks = tuple.get(0);
    String kernel = tuple.get(1);
    String initrd = tuple.get(2);
    PrepareKickstartPxeServerCommand cmd = new PrepareKickstartPxeServerCommand();
    cmd.setKsFile(ks);
    cmd.setInitrd(initrd);
    cmd.setKernel(kernel);
    cmd.setMac(nic.getMacAddress());
    cmd.setTemplateUuid(template.getUuid());
    Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd);
    if (!aws.getResult()) {
        s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails());
        return false;
    }
    return true;
}
Also used : Answer(com.cloud.agent.api.Answer) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateVO(com.cloud.storage.VMTemplateVO) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO)

Example 7 with BaremetalPxeVO

use of com.cloud.baremetal.database.BaremetalPxeVO in project cloudstack by apache.

the class BaremetalKickStartServiceImpl method listPxeServers.

@Override
public List<BaremetalPxeResponse> listPxeServers(ListBaremetalPxeServersCmd cmd) {
    List<BaremetalPxeResponse> responses = new ArrayList<BaremetalPxeResponse>();
    if (cmd.getId() != null) {
        BaremetalPxeVO vo = _pxeDao.findById(cmd.getId());
        responses.add(getApiResponse(vo));
        return responses;
    }
    QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
    sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, cmd.getPhysicalNetworkId());
    List<BaremetalPxeVO> vos = sc.list();
    for (BaremetalPxeVO vo : vos) {
        responses.add(getApiResponse(vo));
    }
    return responses;
}
Also used : ArrayList(java.util.ArrayList) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO)

Example 8 with BaremetalPxeVO

use of com.cloud.baremetal.database.BaremetalPxeVO in project cloudstack by apache.

the class BareMetalPingServiceImpl method addPxeServer.

@Override
@DB
public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) {
    AddBaremetalPxePingServerCmd pcmd = (AddBaremetalPxePingServerCmd) cmd;
    PhysicalNetworkVO pNetwork = null;
    long zoneId;
    if (cmd.getPhysicalNetworkId() == null || cmd.getUrl() == null || cmd.getUsername() == null || cmd.getPassword() == null) {
        throw new IllegalArgumentException("At least one of the required parameters(physical network id, url, username, password) is null");
    }
    pNetwork = _physicalNetworkDao.findById(cmd.getPhysicalNetworkId());
    if (pNetwork == null) {
        throw new IllegalArgumentException("Could not find phyical network with ID: " + cmd.getPhysicalNetworkId());
    }
    zoneId = pNetwork.getDataCenterId();
    PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName() + " is not enabled in the physical network: " + cmd.getPhysicalNetworkId() + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + cmd.getPhysicalNetworkId() + "to add this device");
    }
    HostPodVO pod = _podDao.findById(cmd.getPodId());
    if (pod == null) {
        throw new IllegalArgumentException("Could not find pod with ID: " + cmd.getPodId());
    }
    List<HostVO> pxes = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.BaremetalPxe, null, cmd.getPodId(), zoneId);
    if (pxes.size() != 0) {
        throw new IllegalArgumentException("Already had a PXE server in Pod: " + cmd.getPodId() + " zone: " + zoneId);
    }
    String storageServerIp = pcmd.getPingStorageServerIp();
    if (storageServerIp == null) {
        throw new IllegalArgumentException("No IP for storage server specified");
    }
    String pingDir = pcmd.getPingDir();
    if (pingDir == null) {
        throw new IllegalArgumentException("No direcotry for storage server specified");
    }
    String tftpDir = pcmd.getTftpDir();
    if (tftpDir == null) {
        throw new IllegalArgumentException("No TFTP directory specified");
    }
    String cifsUsername = pcmd.getPingStorageServerUserName();
    if (cifsUsername == null || cifsUsername.equalsIgnoreCase("")) {
        cifsUsername = "xxx";
    }
    String cifsPassword = pcmd.getPingStorageServerPassword();
    if (cifsPassword == null || cifsPassword.equalsIgnoreCase("")) {
        cifsPassword = "xxx";
    }
    URI uri;
    try {
        uri = new URI(cmd.getUrl());
    } catch (Exception e) {
        s_logger.debug(e);
        throw new IllegalArgumentException(e.getMessage());
    }
    String ipAddress = uri.getHost();
    String guid = getPxeServerGuid(Long.toString(zoneId) + "-" + pod.getId(), BaremetalPxeType.PING.toString(), ipAddress);
    ServerResource resource = null;
    Map params = new HashMap<String, String>();
    params.put(BaremetalPxeService.PXE_PARAM_ZONE, Long.toString(zoneId));
    params.put(BaremetalPxeService.PXE_PARAM_POD, String.valueOf(pod.getId()));
    params.put(BaremetalPxeService.PXE_PARAM_IP, ipAddress);
    params.put(BaremetalPxeService.PXE_PARAM_USERNAME, cmd.getUsername());
    params.put(BaremetalPxeService.PXE_PARAM_PASSWORD, cmd.getPassword());
    params.put(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_IP, storageServerIp);
    params.put(BaremetalPxeService.PXE_PARAM_PING_ROOT_DIR, pingDir);
    params.put(BaremetalPxeService.PXE_PARAM_TFTP_DIR, tftpDir);
    params.put(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_USERNAME, cifsUsername);
    params.put(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_PASSWORD, cifsPassword);
    params.put(BaremetalPxeService.PXE_PARAM_GUID, guid);
    resource = new BaremetalPingPxeResource();
    try {
        resource.configure("PING PXE resource", params);
    } catch (Exception e) {
        s_logger.debug(e);
        throw new CloudRuntimeException(e.getMessage());
    }
    Host pxeServer = _resourceMgr.addHost(zoneId, resource, Host.Type.BaremetalPxe, params);
    if (pxeServer == null) {
        throw new CloudRuntimeException("Cannot add PXE server as a host");
    }
    BaremetalPxeVO vo = new BaremetalPxeVO();
    vo.setHostId(pxeServer.getId());
    vo.setNetworkServiceProviderId(ntwkSvcProvider.getId());
    vo.setPodId(pod.getId());
    vo.setPhysicalNetworkId(pcmd.getPhysicalNetworkId());
    vo.setDeviceType(BaremetalPxeType.PING.toString());
    _pxeDao.persist(vo);
    return vo;
}
Also used : HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) HostPodVO(com.cloud.dc.HostPodVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) AddBaremetalPxePingServerCmd(org.apache.cloudstack.api.AddBaremetalPxePingServerCmd) HashMap(java.util.HashMap) Map(java.util.Map) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO) DB(com.cloud.utils.db.DB)

Aggregations

BaremetalPxeVO (com.cloud.baremetal.database.BaremetalPxeVO)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)4 Answer (com.cloud.agent.api.Answer)3 Host (com.cloud.host.Host)2 HostVO (com.cloud.host.HostVO)2 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)2 ServerResource (com.cloud.resource.ServerResource)2 DB (com.cloud.utils.db.DB)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IpmISetBootDevCommand (com.cloud.agent.api.baremetal.IpmISetBootDevCommand)1 PreparePxeServerAnswer (com.cloud.agent.api.baremetal.PreparePxeServerAnswer)1 PreparePxeServerCommand (com.cloud.agent.api.baremetal.PreparePxeServerCommand)1 VmDataCommand (com.cloud.agent.api.routing.VmDataCommand)1 BaremetalPxeResponse (com.cloud.baremetal.networkservice.BaremetalPxeResponse)1 HostPodVO (com.cloud.dc.HostPodVO)1 Pod (com.cloud.dc.Pod)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1