Search in sources :

Example 1 with BaremetalDhcpVO

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

the class BaremetalDhcpElement method canHandle.

private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) {
    Pod pod = dest.getPod();
    if (pod != null && dest.getDataCenter().getNetworkType() == NetworkType.Basic && trafficType == TrafficType.Guest) {
        QueryBuilder<BaremetalDhcpVO> sc = QueryBuilder.create(BaremetalDhcpVO.class);
        sc.and(sc.entity().getPodId(), Op.EQ, pod.getId());
        return sc.find() != null;
    }
    return false;
}
Also used : Pod(com.cloud.dc.Pod) BaremetalDhcpVO(com.cloud.baremetal.database.BaremetalDhcpVO)

Example 2 with BaremetalDhcpVO

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

the class BaremetalDhcpManagerImpl method listBaremetalDhcps.

@Override
public List<BaremetalDhcpResponse> listBaremetalDhcps(ListBaremetalDhcpCmd cmd) {
    List<BaremetalDhcpResponse> responses = new ArrayList<BaremetalDhcpResponse>();
    if (cmd.getId() != null) {
        BaremetalDhcpVO vo = _extDhcpDao.findById(cmd.getId());
        responses.add(generateApiResponse(vo));
        return responses;
    }
    QueryBuilder<BaremetalDhcpVO> sc = QueryBuilder.create(BaremetalDhcpVO.class);
    if (cmd.getDeviceType() != null) {
        sc.and(sc.entity().getDeviceType(), Op.EQ, cmd.getDeviceType());
    }
    sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, cmd.getPhysicalNetworkId());
    List<BaremetalDhcpVO> vos = sc.list();
    for (BaremetalDhcpVO vo : vos) {
        responses.add(generateApiResponse(vo));
    }
    return responses;
}
Also used : BaremetalDhcpVO(com.cloud.baremetal.database.BaremetalDhcpVO) ArrayList(java.util.ArrayList)

Example 3 with BaremetalDhcpVO

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

the class BaremetalDhcpManagerImpl method addDchpServer.

@Override
@DB
public BaremetalDhcpVO addDchpServer(AddBaremetalDhcpCmd 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();
    DataCenterVO zone = _dcDao.findById(zoneId);
    PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), BaremetalDhcpManager.BAREMETAL_DHCP_SERVICE_PROVIDER.getName());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + BaremetalDhcpManager.BAREMETAL_DHCP_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> dhcps = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.BaremetalDhcp, null, null, zoneId);
    if (dhcps.size() != 0) {
        throw new IllegalArgumentException("Already had a DHCP server in zone: " + zoneId);
    }
    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) {
        // the url is raw ip. For backforward compatibility, we have to support http://ip format as well
        ipAddress = cmd.getUrl();
    }
    String guid = getDhcpServerGuid(Long.toString(zoneId), "ExternalDhcp", ipAddress);
    Map params = new HashMap<String, String>();
    params.put("type", cmd.getDhcpType());
    params.put("zone", Long.toString(zoneId));
    params.put("ip", ipAddress);
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    params.put("guid", guid);
    String dns = zone.getDns1();
    if (dns == null) {
        dns = zone.getDns2();
    }
    params.put("dns", dns);
    ServerResource resource = null;
    try {
        if (cmd.getDhcpType().equalsIgnoreCase(BaremetalDhcpType.DNSMASQ.toString())) {
            resource = new BaremetalDnsmasqResource();
            resource.configure("Dnsmasq resource", params);
        } else if (cmd.getDhcpType().equalsIgnoreCase(BaremetalDhcpType.DHCPD.toString())) {
            resource = new BaremetalDhcpdResource();
            resource.configure("Dhcpd resource", params);
        } else {
            throw new CloudRuntimeException("Unsupport DHCP server type: " + cmd.getDhcpType());
        }
    } catch (Exception e) {
        s_logger.debug(e);
        throw new CloudRuntimeException(e.getMessage());
    }
    Host dhcpServer = _resourceMgr.addHost(zoneId, resource, Host.Type.BaremetalDhcp, params);
    if (dhcpServer == null) {
        throw new CloudRuntimeException("Cannot add external Dhcp server as a host");
    }
    BaremetalDhcpVO vo = new BaremetalDhcpVO();
    vo.setDeviceType(cmd.getDhcpType());
    vo.setHostId(dhcpServer.getId());
    vo.setNetworkServiceProviderId(ntwkSvcProvider.getId());
    vo.setPhysicalNetworkId(cmd.getPhysicalNetworkId());
    _extDhcpDao.persist(vo);
    return vo;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) BaremetalDhcpVO(com.cloud.baremetal.database.BaremetalDhcpVO) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HashMap(java.util.HashMap) Map(java.util.Map) DB(com.cloud.utils.db.DB)

Example 4 with BaremetalDhcpVO

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

the class AddBaremetalDhcpCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        BaremetalDhcpVO vo = mgr.addDchpServer(this);
        BaremetalDhcpResponse response = mgr.generateApiResponse(vo);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn("Unable to add external dhcp server with url: " + getUrl(), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : BaremetalDhcpVO(com.cloud.baremetal.database.BaremetalDhcpVO) BaremetalDhcpResponse(com.cloud.baremetal.networkservice.BaremetalDhcpResponse) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Aggregations

BaremetalDhcpVO (com.cloud.baremetal.database.BaremetalDhcpVO)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 BaremetalDhcpResponse (com.cloud.baremetal.networkservice.BaremetalDhcpResponse)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 Pod (com.cloud.dc.Pod)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 Host (com.cloud.host.Host)1 HostVO (com.cloud.host.HostVO)1 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 ServerResource (com.cloud.resource.ServerResource)1 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)1 DB (com.cloud.utils.db.DB)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1