Search in sources :

Example 1 with CheckNetworkAnswer

use of com.cloud.agent.api.CheckNetworkAnswer in project cloudstack by apache.

the class Ovm3HypervisorNetwork method execute.

/* this might have to change in the future, works for now... */
public CheckNetworkAnswer execute(CheckNetworkCommand cmd) {
    LOGGER.debug("Checking if network name setup is done on " + config.getAgentHostname());
    List<PhysicalNetworkSetupInfo> infoList = cmd.getPhysicalNetworkInfoList();
    /* here we assume all networks are set */
    for (PhysicalNetworkSetupInfo info : infoList) {
        if (info.getGuestNetworkName() == null) {
            info.setGuestNetworkName(config.getAgentGuestNetworkName());
        }
        if (info.getPublicNetworkName() == null) {
            info.setPublicNetworkName(config.getAgentPublicNetworkName());
        }
        if (info.getPrivateNetworkName() == null) {
            info.setPrivateNetworkName(config.getAgentPrivateNetworkName());
        }
        if (info.getStorageNetworkName() == null) {
            info.setStorageNetworkName(config.getAgentStorageNetworkName());
        }
        if (!isNetworkSetupByName(info.getGuestNetworkName())) {
            String msg = "Guest Physical Network id:" + info.getPhysicalNetworkId() + ", Guest Network is not configured on the backend by name " + info.getGuestNetworkName();
            LOGGER.error(msg);
            return new CheckNetworkAnswer(cmd, false, msg);
        }
        if (!isNetworkSetupByName(info.getPrivateNetworkName())) {
            String msg = "Private Physical Network id:" + info.getPhysicalNetworkId() + ", Private Network is not configured on the backend by name " + info.getPrivateNetworkName();
            LOGGER.error(msg);
            return new CheckNetworkAnswer(cmd, false, msg);
        }
        if (!isNetworkSetupByName(info.getPublicNetworkName())) {
            String msg = "Public Physical Network id:" + info.getPhysicalNetworkId() + ", Public Network is not configured on the backend by name " + info.getPublicNetworkName();
            LOGGER.error(msg);
            return new CheckNetworkAnswer(cmd, false, msg);
        }
    /* Storage network is optional, will revert to private otherwise */
    }
    return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done");
}
Also used : CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Example 2 with CheckNetworkAnswer

use of com.cloud.agent.api.CheckNetworkAnswer in project cloudstack by apache.

the class LibvirtCheckNetworkCommandWrapper method execute.

@Override
public Answer execute(final CheckNetworkCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final List<PhysicalNetworkSetupInfo> phyNics = command.getPhysicalNetworkInfoList();
    String errMsg = null;
    for (final PhysicalNetworkSetupInfo nic : phyNics) {
        if (!libvirtComputingResource.checkNetwork(Networks.TrafficType.Guest, nic.getGuestNetworkName())) {
            errMsg = "Can not find network: " + nic.getGuestNetworkName();
            break;
        } else if (!libvirtComputingResource.checkNetwork(Networks.TrafficType.Management, nic.getPrivateNetworkName())) {
            errMsg = "Can not find network: " + nic.getPrivateNetworkName();
            break;
        } else if (!libvirtComputingResource.checkNetwork(Networks.TrafficType.Public, nic.getPublicNetworkName())) {
            errMsg = "Can not find network: " + nic.getPublicNetworkName();
            break;
        }
    }
    if (errMsg != null) {
        return new CheckNetworkAnswer(command, false, errMsg);
    } else {
        return new CheckNetworkAnswer(command, true, null);
    }
}
Also used : CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Example 3 with CheckNetworkAnswer

use of com.cloud.agent.api.CheckNetworkAnswer in project cloudstack by apache.

the class OvmResourceBase method execute.

protected CheckNetworkAnswer execute(CheckNetworkCommand cmd) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking if network name setup is done on the resource");
    }
    List<PhysicalNetworkSetupInfo> infoList = cmd.getPhysicalNetworkInfoList();
    boolean errorout = false;
    String msg = "";
    for (PhysicalNetworkSetupInfo info : infoList) {
        if (!isNetworkSetupByName(info.getGuestNetworkName())) {
            msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Guest Network is not configured on the backend by name " + info.getGuestNetworkName();
            errorout = true;
            break;
        }
        if (!isNetworkSetupByName(info.getPrivateNetworkName())) {
            msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Private Network is not configured on the backend by name " + info.getPrivateNetworkName();
            errorout = true;
            break;
        }
        if (!isNetworkSetupByName(info.getPublicNetworkName())) {
            msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Public Network is not configured on the backend by name " + info.getPublicNetworkName();
            errorout = true;
            break;
        }
    }
    if (errorout) {
        s_logger.error(msg);
        return new CheckNetworkAnswer(cmd, false, msg);
    } else {
        return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done");
    }
}
Also used : CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Example 4 with CheckNetworkAnswer

use of com.cloud.agent.api.CheckNetworkAnswer in project cloudstack by apache.

the class CitrixCheckNetworkCommandWrapper method execute.

@Override
public Answer execute(final CheckNetworkCommand command, final CitrixResourceBase citrixResourceBase) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking if network name setup is done on the resource");
    }
    final List<PhysicalNetworkSetupInfo> infoList = command.getPhysicalNetworkInfoList();
    try {
        boolean errorout = false;
        String msg = "";
        for (final PhysicalNetworkSetupInfo info : infoList) {
            if (!citrixResourceBase.isNetworkSetupByName(info.getGuestNetworkName())) {
                msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Guest Network is not configured on the backend by name " + info.getGuestNetworkName();
                errorout = true;
                break;
            }
            if (!citrixResourceBase.isNetworkSetupByName(info.getPrivateNetworkName())) {
                msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Private Network is not configured on the backend by name " + info.getPrivateNetworkName();
                errorout = true;
                break;
            }
            if (!citrixResourceBase.isNetworkSetupByName(info.getPublicNetworkName())) {
                msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Public Network is not configured on the backend by name " + info.getPublicNetworkName();
                errorout = true;
                break;
            }
        /*if(!isNetworkSetupByName(info.getStorageNetworkName())){
                    msg = "For Physical Network id:"+ info.getPhysicalNetworkId() + ", Storage Network is not configured on the backend by name " + info.getStorageNetworkName();
                    errorout = true;
                    break;
                }*/
        }
        if (errorout) {
            s_logger.error(msg);
            return new CheckNetworkAnswer(command, false, msg);
        } else {
            return new CheckNetworkAnswer(command, true, "Network Setup check by names is done");
        }
    } catch (final XenAPIException e) {
        final String msg = "CheckNetworkCommand failed with XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid();
        s_logger.warn(msg, e);
        return new CheckNetworkAnswer(command, false, msg);
    } catch (final Exception e) {
        final String msg = "CheckNetworkCommand failed with Exception:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid();
        s_logger.warn(msg, e);
        return new CheckNetworkAnswer(command, false, msg);
    }
}
Also used : CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Example 5 with CheckNetworkAnswer

use of com.cloud.agent.api.CheckNetworkAnswer in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    final long hostId = host.getId();
    final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    final String dataCenter = startup.getDataCenter();
    long dcId = -1;
    Zone dc = _zoneRepository.findByName(dataCenter);
    if (dc == null) {
        try {
            dcId = Long.parseLong(dataCenter);
            dc = _zoneRepository.findOne(dcId);
        } catch (final NumberFormatException e) {
        }
    }
    if (dc == null) {
        throw new IllegalArgumentException("Host " + startup.getPrivateIpAddress() + " sent incorrect data center: " + dataCenter);
    }
    dcId = dc.getId();
    final HypervisorType hypervisorType = startup.getHypervisorType();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Host's hypervisorType is: " + hypervisorType);
    }
    final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<>();
    // list all physicalnetworks in the zone & for each get the network names
    final List<PhysicalNetworkVO> physicalNtwkList = _physicalNetworkDao.listByZone(dcId);
    for (final PhysicalNetworkVO pNtwk : physicalNtwkList) {
        final String publicName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Public, hypervisorType);
        final String privateName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Management, hypervisorType);
        final String guestName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Guest, hypervisorType);
        final String storageName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Storage, hypervisorType);
        // String controlName = _pNTrafficTypeDao._networkModel.getNetworkTag(pNtwk.getId(), TrafficType.Control, hypervisorType);
        final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
        info.setPhysicalNetworkId(pNtwk.getId());
        info.setGuestNetworkName(guestName);
        info.setPrivateNetworkName(privateName);
        info.setPublicNetworkName(publicName);
        info.setStorageNetworkName(storageName);
        final PhysicalNetworkTrafficTypeVO mgmtTraffic = _pNTrafficTypeDao.findBy(pNtwk.getId(), TrafficType.Management);
        if (mgmtTraffic != null) {
            final String vlan = mgmtTraffic.getVlan();
            info.setMgmtVlan(vlan);
        }
        networkInfoList.add(info);
    }
    // send the names to the agent
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Sending CheckNetworkCommand to check the Network is setup correctly on Agent");
    }
    final CheckNetworkCommand nwCmd = new CheckNetworkCommand(networkInfoList);
    final CheckNetworkAnswer answer = (CheckNetworkAnswer) _agentMgr.easySend(hostId, nwCmd);
    if (answer == null) {
        s_logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId());
        throw new ConnectionException(true, "Unable to get an answer to the CheckNetworkCommand from agent: " + host.getId());
    }
    if (!answer.getResult()) {
        s_logger.warn("Unable to setup agent " + hostId + " due to " + answer.getDetails());
        final String msg = "Incorrect Network setup on agent, Reinitialize agent after network names are setup, details : " + answer.getDetails();
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, host.getPodId(), msg, msg);
        throw new ConnectionException(true, msg);
    } else {
        if (answer.needReconnect()) {
            throw new ConnectionException(false, "Reinitialize agent after network setup.");
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Network setup is correct on Agent");
        }
        return;
    }
}
Also used : Zone(com.cloud.db.model.Zone) ArrayList(java.util.ArrayList) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Aggregations

CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)13 PhysicalNetworkSetupInfo (com.cloud.network.PhysicalNetworkSetupInfo)9 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)6 Answer (com.cloud.agent.api.Answer)2 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)2 ConnectionException (com.cloud.exception.ConnectionException)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 PhysicalNetworkTrafficTypeVO (com.cloud.network.dao.PhysicalNetworkTrafficTypeVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Zone (com.cloud.db.model.Zone)1 DataCenterVO (com.cloud.dc.DataCenterVO)1