Search in sources :

Example 1 with OvsTunnelInterfaceVO

use of com.cloud.network.ovs.dao.OvsTunnelInterfaceVO in project cloudstack by apache.

the class OvsTunnelManagerImpl method getGreEndpointIP.

private String getGreEndpointIP(Host host, Network nw) throws AgentUnavailableException, OperationTimedoutException {
    String endpointIp = null;
    // Fetch fefault name for network label from configuration
    String physNetLabel = _configDao.getValue(Config.OvsTunnelNetworkDefaultLabel.key());
    Long physNetId = nw.getPhysicalNetworkId();
    PhysicalNetworkTrafficType physNetTT = _physNetTTDao.findBy(physNetId, TrafficType.Guest);
    HypervisorType hvType = host.getHypervisorType();
    String label = null;
    switch(hvType) {
        case XenServer:
            label = physNetTT.getXenNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        case KVM:
            label = physNetTT.getKvmNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        default:
            throw new CloudRuntimeException("Hypervisor " + hvType.toString() + " unsupported by OVS Tunnel Manager");
    }
    // Try to fetch GRE endpoint IP address for cloud db
    // If not found, then find it on the hypervisor
    OvsTunnelInterfaceVO tunnelIface = _tunnelInterfaceDao.getByHostAndLabel(host.getId(), physNetLabel);
    if (tunnelIface == null) {
        //Now find and fetch configuration for physical interface
        //for network with label on target host
        Commands fetchIfaceCmds = new Commands(new OvsFetchInterfaceCommand(physNetLabel));
        s_logger.debug("Ask host " + host.getId() + " to retrieve interface for phy net with label:" + physNetLabel);
        Answer[] fetchIfaceAnswers = _agentMgr.send(host.getId(), fetchIfaceCmds);
        //And finally save it for future use
        endpointIp = handleFetchInterfaceAnswer(fetchIfaceAnswers, host.getId());
    } else {
        endpointIp = tunnelIface.getIp();
    }
    return endpointIp;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) OvsTunnelInterfaceVO(com.cloud.network.ovs.dao.OvsTunnelInterfaceVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Commands(com.cloud.agent.manager.Commands) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 2 with OvsTunnelInterfaceVO

use of com.cloud.network.ovs.dao.OvsTunnelInterfaceVO in project cloudstack by apache.

the class OvsTunnelManagerImpl method handleFetchInterfaceAnswer.

private String handleFetchInterfaceAnswer(Answer[] answers, Long hostId) {
    OvsFetchInterfaceAnswer ans = (OvsFetchInterfaceAnswer) answers[0];
    if (ans.getResult()) {
        if (ans.getIp() != null && !("".equals(ans.getIp()))) {
            OvsTunnelInterfaceVO ti = createInterfaceRecord(ans.getIp(), ans.getNetmask(), ans.getMac(), hostId, ans.getLabel());
            return ti.getIp();
        }
    }
    // Fetch interface failed!
    s_logger.warn("Unable to fetch the IP address for the GRE tunnel endpoint" + ans.getDetails());
    return null;
}
Also used : OvsTunnelInterfaceVO(com.cloud.network.ovs.dao.OvsTunnelInterfaceVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer)

Example 3 with OvsTunnelInterfaceVO

use of com.cloud.network.ovs.dao.OvsTunnelInterfaceVO in project cloudstack by apache.

the class OvsTunnelManagerImpl method createInterfaceRecord.

@DB
protected OvsTunnelInterfaceVO createInterfaceRecord(String ip, String netmask, String mac, long hostId, String label) {
    OvsTunnelInterfaceVO ti = null;
    try {
        ti = new OvsTunnelInterfaceVO(ip, netmask, mac, hostId, label);
        // TODO: Is locking really necessary here?
        OvsTunnelInterfaceVO lock = _tunnelInterfaceDao.acquireInLockTable(Long.valueOf(1));
        if (lock == null) {
            s_logger.warn("Cannot lock table ovs_tunnel_account");
            return null;
        }
        _tunnelInterfaceDao.persist(ti);
        _tunnelInterfaceDao.releaseFromLockTable(lock.getId());
    } catch (EntityExistsException e) {
        s_logger.debug("A record for the interface for network " + label + " on host id " + hostId + " already exists");
    }
    return ti;
}
Also used : OvsTunnelInterfaceVO(com.cloud.network.ovs.dao.OvsTunnelInterfaceVO) EntityExistsException(javax.persistence.EntityExistsException) DB(com.cloud.utils.db.DB)

Aggregations

OvsTunnelInterfaceVO (com.cloud.network.ovs.dao.OvsTunnelInterfaceVO)3 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)2 Answer (com.cloud.agent.api.Answer)1 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)1 OvsFetchInterfaceCommand (com.cloud.agent.api.OvsFetchInterfaceCommand)1 Commands (com.cloud.agent.manager.Commands)1 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)1 PhysicalNetworkTrafficType (com.cloud.network.PhysicalNetworkTrafficType)1 DB (com.cloud.utils.db.DB)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 EntityExistsException (javax.persistence.EntityExistsException)1