Search in sources :

Example 51 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class PaloAltoExternalFirewallElement method createPaloAltoFirewallResponse.

@Override
public PaloAltoFirewallResponse createPaloAltoFirewallResponse(ExternalFirewallDeviceVO fwDeviceVO) {
    PaloAltoFirewallResponse response = new PaloAltoFirewallResponse();
    Map<String, String> fwDetails = _hostDetailDao.findDetails(fwDeviceVO.getHostId());
    Host fwHost = _hostDao.findById(fwDeviceVO.getHostId());
    response.setId(fwDeviceVO.getUuid());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(fwDeviceVO.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    response.setDeviceName(fwDeviceVO.getDeviceName());
    if (fwDeviceVO.getCapacity() == 0) {
        long defaultFwCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalFirewallCapacity.key()), 50);
        response.setDeviceCapacity(defaultFwCapacity);
    } else {
        response.setDeviceCapacity(fwDeviceVO.getCapacity());
    }
    response.setProvider(fwDeviceVO.getProviderName());
    response.setDeviceState(fwDeviceVO.getDeviceState().name());
    response.setIpAddress(fwHost.getPrivateIpAddress());
    response.setPublicInterface(fwDetails.get("publicInterface"));
    response.setUsageInterface(fwDetails.get("usageInterface"));
    response.setPrivateInterface(fwDetails.get("privateInterface"));
    response.setPublicZone(fwDetails.get("publicZone"));
    response.setPrivateZone(fwDetails.get("privateZone"));
    response.setNumRetries(fwDetails.get("numRetries"));
    response.setTimeout(fwDetails.get("timeout"));
    response.setObjectName("paloaltofirewall");
    return response;
}
Also used : PaloAltoFirewallResponse(com.cloud.api.response.PaloAltoFirewallResponse) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Host(com.cloud.host.Host)

Example 52 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class RandomAllocator method allocateTo.

@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    ServiceOffering offering = vmProfile.getServiceOffering();
    List<Host> suitableHosts = new ArrayList<Host>();
    List<Host> hostsCopy = new ArrayList<Host>(hosts);
    if (type == Host.Type.Storage) {
        return suitableHosts;
    }
    String hostTag = offering.getHostTag();
    if (hostTag != null) {
        s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId + " having host tag:" + hostTag);
    } else {
        s_logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
    }
    // list all computing hosts, regardless of whether they support routing...it's random after all
    if (hostTag != null) {
        hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag));
    } else {
        hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId));
    }
    s_logger.debug("Random Allocator found " + hostsCopy.size() + "  hosts");
    if (hostsCopy.size() == 0) {
        return suitableHosts;
    }
    Collections.shuffle(hostsCopy);
    for (Host host : hostsCopy) {
        if (suitableHosts.size() == returnUpTo) {
            break;
        }
        if (!avoid.shouldAvoid(host)) {
            suitableHosts.add(host);
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, " + "skipping this and trying other available hosts");
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Random Host Allocator returning " + suitableHosts.size() + " suitable hosts");
    }
    return suitableHosts;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Example 53 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class BaremetalKickStartServiceImpl method addPxeServer.

@Override
@DB
public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) {
    AddBaremetalKickStartPxeCmd kcmd = (AddBaremetalKickStartPxeCmd) 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");
    }
    List<HostVO> pxes = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe, zoneId);
    if (!pxes.isEmpty()) {
        throw new IllegalArgumentException("Already had a PXE server zone: " + zoneId);
    }
    String tftpDir = kcmd.getTftpDir();
    if (tftpDir == null) {
        throw new IllegalArgumentException("No TFTP directory specified");
    }
    URI uri;
    try {
        uri = new URI(cmd.getUrl());
    } catch (Exception e) {
        s_logger.debug(e);
        throw new IllegalArgumentException(e.getMessage());
    }
    String ipAddress = uri.getHost();
    if (ipAddress == null) {
        ipAddress = cmd.getUrl();
    }
    String guid = getPxeServerGuid(Long.toString(zoneId), BaremetalPxeType.KICK_START.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_IP, ipAddress);
    params.put(BaremetalPxeService.PXE_PARAM_USERNAME, cmd.getUsername());
    params.put(BaremetalPxeService.PXE_PARAM_PASSWORD, cmd.getPassword());
    params.put(BaremetalPxeService.PXE_PARAM_TFTP_DIR, tftpDir);
    params.put(BaremetalPxeService.PXE_PARAM_GUID, guid);
    resource = new BaremetalKickStartPxeResource();
    try {
        resource.configure("KickStart PXE resource", params);
    } catch (Exception e) {
        throw new CloudRuntimeException(e.getMessage(), e);
    }
    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.setPhysicalNetworkId(kcmd.getPhysicalNetworkId());
    vo.setDeviceType(BaremetalPxeType.KICK_START.toString());
    _pxeDao.persist(vo);
    return vo;
}
Also used : HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) URI(java.net.URI) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) AddBaremetalKickStartPxeCmd(org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd) Map(java.util.Map) HashMap(java.util.HashMap) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO) DB(com.cloud.utils.db.DB)

Example 54 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class AddGloboDnsHostCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        Host host = _globoDnsElementService.addGloboDnsHost(physicalNetworkId, username, password, url);
        SuccessResponse response = new SuccessResponse(getCommandName());
        response.setSuccess((host == null ? false : true));
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Host(com.cloud.host.Host)

Example 55 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class GloboDnsElement method shutdownProviderInstances.

@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    PhysicalNetwork pNtwk = _physicalNetworkDao.findById(provider.getPhysicalNetworkId());
    Host host = getGloboDnsHost(pNtwk.getDataCenterId());
    if (host != null) {
        _resourceMgr.deleteHost(host.getId(), true, false);
    }
    return true;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) Host(com.cloud.host.Host)

Aggregations

Host (com.cloud.host.Host)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)37 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)31 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)29 ServerApiException (org.apache.cloudstack.api.ServerApiException)20 ConfigurationException (javax.naming.ConfigurationException)17 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)16 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)16 DB (com.cloud.utils.db.DB)14 Map (java.util.Map)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)13 Answer (com.cloud.agent.api.Answer)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11 DataCenter (com.cloud.dc.DataCenter)10 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)10 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)10 HostVO (com.cloud.host.HostVO)9 StoragePool (com.cloud.storage.StoragePool)9