Search in sources :

Example 61 with HostVO

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

the class NiciraNvpElement method createNiciraNvpDeviceResponse.

@Override
public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(NiciraNvpDeviceVO niciraNvpDeviceVO) {
    HostVO niciraNvpHost = hostDao.findById(niciraNvpDeviceVO.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
    response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(niciraNvpDeviceVO.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    response.setId(niciraNvpDeviceVO.getUuid());
    response.setProviderName(niciraNvpDeviceVO.getProviderName());
    response.setHostName(niciraNvpHost.getDetail("ip"));
    response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
    response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
    response.setL2GatewayServiceUuid(niciraNvpHost.getDetail("l2gatewayserviceuuid"));
    response.setObjectName("niciranvpdevice");
    return response;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse) HostVO(com.cloud.host.HostVO)

Example 62 with HostVO

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

the class NiciraNvpElement method implement.

@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
    if (!canHandle(network, Service.Connectivity)) {
        return false;
    }
    if (network.getBroadcastUri() == null) {
        s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
        return false;
    }
    List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    Account owner = context.getAccount();
    if (network.getGuestType().equals(GuestType.Shared)) {
        // Support Shared Networks
        String lSwitchUuid = BroadcastDomainType.getValue(network.getBroadcastUri());
        String ownerName = context.getDomain().getName() + "-" + context.getAccount().getAccountName();
        return sharedNetworkSupport(network, lSwitchUuid, ownerName, niciraNvpHost);
    } else if (network.getGuestType().equals(GuestType.Isolated) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
        // Implement SourceNat immediately as we have al the info already
        s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
        PublicIp sourceNatIp = ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
        String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
        String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
        // assuming a vlan:
        String vtag = sourceNatIp.getVlanTag();
        BroadcastDomainType tiep = null;
        try {
            tiep = BroadcastDomainType.getTypeOf(vtag);
        } catch (URISyntaxException use) {
            throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
        }
        if (tiep == BroadcastDomainType.Vlan) {
            vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
        } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
            throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
        }
        long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
        CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
        CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
        if (answer.getResult() == false) {
            s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
            return false;
        }
        NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
        niciraNvpRouterMappingDao.persist(routermapping);
    }
    return true;
}
Also used : Account(com.cloud.user.Account) CreateLogicalRouterCommand(com.cloud.agent.api.CreateLogicalRouterCommand) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) PublicIp(com.cloud.network.addr.PublicIp) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalRouterAnswer(com.cloud.agent.api.CreateLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 63 with HostVO

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

the class NiciraNvpElement method applyIps.

/**
 * From interface IpDeployer
 *
 * @param network
 * @param ipAddress
 * @param services
 * @return
 * @throws ResourceUnavailableException
 */
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException {
    if (services.contains(Service.SourceNat)) {
        // Only if we need to provide SourceNat we need to configure the logical router
        // SourceNat is required for StaticNat and PortForwarding
        List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
        if (devices.isEmpty()) {
            s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
            return false;
        }
        NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
        HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
        hostDao.loadDetails(niciraNvpHost);
        NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
        if (routermapping == null) {
            s_logger.error("No logical router uuid found for network " + network.getDisplayText());
            return false;
        }
        List<String> cidrs = new ArrayList<String>();
        for (PublicIpAddress ip : ipAddress) {
            if (ip.getState() == IpAddress.State.Releasing) {
                // the Logical Router
                continue;
            }
            cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
        }
        ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
        ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
        // FIXME answer can be null if the host is down
        return answer.getResult();
    } else {
        s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
    }
    return true;
}
Also used : PublicIpAddress(com.cloud.network.PublicIpAddress) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand)

Example 64 with HostVO

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

the class NetscalerElement method applyElasticLoadBalancerRules.

public boolean applyElasticLoadBalancerRules(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return true;
    }
    String errMsg = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        try {
            lbDeviceVO = allocateLoadBalancerForNetwork(network);
        } catch (Exception e) {
            errMsg = "Could not allocate a NetSclaer load balancer for configuring elastic load balancer rules due to " + e.getMessage();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
        }
    }
    if (!isNetscalerDevice(lbDeviceVO.getDeviceName())) {
        errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element can not be handle elastic load balancer rules.";
        s_logger.error(errMsg);
        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
    }
    List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
    for (int i = 0; i < loadBalancingRules.size(); i++) {
        LoadBalancingRule rule = loadBalancingRules.get(i);
        boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
        String protocol = rule.getProtocol();
        String algorithm = rule.getAlgorithm();
        String lbUuid = rule.getUuid();
        String srcIp = rule.getSourceIp().addr();
        int srcPort = rule.getSourcePortStart();
        List<LbDestination> destinations = rule.getDestinations();
        if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
            LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            if (rule.isAutoScaleConfig()) {
                loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
            }
            loadBalancersToApply.add(loadBalancer);
        }
    }
    if (loadBalancersToApply.size() > 0) {
        int numLoadBalancersForCommand = loadBalancersToApply.size();
        LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
        LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(loadBalancersForCommand, null);
        HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        Answer answer = _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply elastic load balancer rules to the external load balancer appliance in zone " + network.getDataCenterId() + " due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) HostVO(com.cloud.host.HostVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GlobalLoadBalancerConfigCommand(com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 65 with HostVO

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

the class NetscalerElement method manageGuestNetworkWithNetscalerControlCenter.

public boolean manageGuestNetworkWithNetscalerControlCenter(boolean add, Network guestConfig, NetworkOffering offering) throws ResourceUnavailableException, InsufficientCapacityException, ConfigurationException {
    if (guestConfig.getTrafficType() != TrafficType.Guest) {
        s_logger.trace("External load balancer can only be used for guest networks.");
        return false;
    }
    long zoneId = guestConfig.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    HostVO netscalerControlCenter = null;
    if (add) {
        HostVO lbDeviceVO = null;
        // on restart network, device could have been allocated already,
        // skip allocation if a device is assigned
        lbDeviceVO = getNetScalerControlCenterForNetwork(guestConfig);
        if (lbDeviceVO == null) {
            // allocate a load balancer device for the network
            lbDeviceVO = allocateNCCResourceForNetwork(guestConfig);
            if (lbDeviceVO == null) {
                String msg = "failed to allocate Netscaler ControlCenter Resource for the zone in the network " + guestConfig.getId();
                s_logger.error(msg);
                throw new InsufficientNetworkCapacityException(msg, DataCenter.class, guestConfig.getDataCenterId());
            }
        }
        netscalerControlCenter = _hostDao.findById(lbDeviceVO.getId());
        s_logger.debug("Allocated Netscaler Control Center device:" + lbDeviceVO.getId() + " for the network: " + guestConfig.getId());
    } else {
        // find the load balancer device allocated for the network
        HostVO lbDeviceVO = null;
        // on restart network, device could have been allocated already, skip allocation if a device is assigned
        lbDeviceVO = getNetScalerControlCenterForNetwork(guestConfig);
        if (lbDeviceVO == null) {
            s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." + " Either network implement failed half way through or already network shutdown is completed. So just returning.");
            return true;
        }
        netscalerControlCenter = _hostDao.findById(lbDeviceVO.getId());
        assert (netscalerControlCenter != null) : "There is no device assigned to this network how did shutdown network ended up here??";
    }
    JSONObject networkDetails = new JSONObject();
    JSONObject networkPayload = new JSONObject();
    String selfIp = null;
    try {
        networkDetails.put("id", guestConfig.getId());
        networkDetails.put("vlan", guestConfig.getBroadcastUri());
        networkDetails.put("cidr", guestConfig.getCidr());
        networkDetails.put("gateway", guestConfig.getGateway());
        networkDetails.put("servicepackage_id", offering.getServicePackage());
        networkDetails.put("zone_id", zone.getUuid());
        networkDetails.put("account_id", guestConfig.getAccountId());
        networkDetails.put("add", Boolean.toString(add));
        selfIp = _ipAddrMgr.acquireGuestIpAddress(guestConfig, null);
        if (selfIp == null) {
            String msg = "failed to acquire guest IP address so not implementing the network on the NetscalerControlCenter";
            s_logger.error(msg);
            throw new InsufficientNetworkCapacityException(msg, Network.class, guestConfig.getId());
        }
        networkDetails.put("snip", selfIp);
        // TODO region is hardcoded make it dynamic
        networkDetails.put("region_id", 1);
        networkDetails.put("name", guestConfig.getName());
        networkPayload.put("network", networkDetails);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    NetScalerImplementNetworkCommand cmd = new NetScalerImplementNetworkCommand(zone.getUuid(), netscalerControlCenter.getId(), networkPayload.toString());
    Answer answer = _agentMgr.easySend(netscalerControlCenter.getId(), cmd);
    if (add) {
        // TODO After getting the answer check with the job id and do poll on the job and then save the selfip or acquired guest ip to the Nics table
        if (answer != null) {
            if (answer.getResult() == true) {
                if (add) {
                    // Insert a new NIC for this guest network to reserve the self IP
                    _networkService.savePlaceholderNic(guestConfig, selfIp, null, null);
                }
            } else {
                return false;
            }
        }
    } else {
        if (answer != null) {
            if (answer.getResult() == true) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) NetScalerImplementNetworkCommand(com.cloud.agent.api.NetScalerImplementNetworkCommand) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46