Search in sources :

Example 1 with OvsFetchInterfaceAnswer

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

the class CitrixOvsFetchInterfaceCommandWrapper method execute.

@Override
public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResourceBase citrixResourceBase) {
    String label = command.getLabel();
    //FIXME: this is a tricky to pass the network checking in XCP. I temporary get default label from Host.
    if (citrixResourceBase.isXcp()) {
        label = citrixResourceBase.getLabel();
    }
    s_logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp());
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final XsLocalNetwork nw = citrixResourceBase.getNetworkByName(conn, label);
        if (nw == null) {
            throw new CloudRuntimeException("Unable to locate the network with name-label: " + label + " on host: " + citrixResourceBase.getHost().getIp());
        }
        s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn));
        final PIF pif = nw.getPif(conn);
        final PIF.Record pifRec = pif.getRecord(conn);
        s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")");
        return new OvsFetchInterfaceAnswer(command, true, "Interface " + pifRec.device + " retrieved successfully", pifRec.IP, pifRec.netmask, pifRec.MAC);
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    }
}
Also used : XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) PIF(com.xensource.xenapi.PIF) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 2 with OvsFetchInterfaceAnswer

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

the class LibvirtOvsFetchInterfaceCommandWrapper method execute.

@Override
public Answer execute(final OvsFetchInterfaceCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String label = command.getLabel();
    s_logger.debug("Will look for network with name-label:" + label);
    try {
        final String ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'");
        final String mask = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f4");
        final String mac = Script.runSimpleBashScript("ifconfig " + label + " | grep HWaddr | awk -F \" \" '{print $5}'");
        return new OvsFetchInterfaceAnswer(command, true, "Interface " + label + " retrieved successfully", ipadd, mask, mac);
    } catch (final Exception e) {
        s_logger.warn("Caught execption when fetching interface", e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    }
}
Also used : OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer)

Example 3 with OvsFetchInterfaceAnswer

use of com.cloud.agent.api.OvsFetchInterfaceAnswer 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)

Aggregations

OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)3 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)1 OvsTunnelInterfaceVO (com.cloud.network.ovs.dao.OvsTunnelInterfaceVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Connection (com.xensource.xenapi.Connection)1 PIF (com.xensource.xenapi.PIF)1 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1