Search in sources :

Example 26 with Network

use of com.xensource.xenapi.Network in project cloudstack by apache.

the class CitrixOvsSetTagAndFlowCommandWrapper method execute.

@Override
public Answer execute(final OvsSetTagAndFlowCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        final String bridge = nw.getBridge(conn);
        /*
             * If VM is domainRouter, this will try to set flow and tag on its
             * none guest network nic. don't worry, it will fail silently at
             * host plugin side
             */
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_set_tag_and_flow", "bridge", bridge, "vmName", command.getVmName(), "tag", command.getTag(), "vlans", command.getVlans(), "seqno", command.getSeqNo());
        s_logger.debug("set flow for " + command.getVmName() + " " + result);
        if (result != null && result.equalsIgnoreCase("SUCCESS")) {
            return new OvsSetTagAndFlowAnswer(command, true, result);
        } else {
            return new OvsSetTagAndFlowAnswer(command, false, result);
        }
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to set tag and flow", e);
    } catch (final XenAPIException e) {
        s_logger.error("Failed to set tag and flow", e);
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to set tag and flow", e);
    }
    return new OvsSetTagAndFlowAnswer(command, false, "EXCEPTION");
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsSetTagAndFlowAnswer(com.cloud.agent.api.OvsSetTagAndFlowAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 27 with Network

use of com.xensource.xenapi.Network in project cloudstack by apache.

the class CitrixOvsVpcPhysicalTopologyConfigCommandWrapper method execute.

@Override
public Answer execute(final OvsVpcPhysicalTopologyConfigCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName());
        final String bridgeName = nw.getBridge(conn);
        final long sequenceNo = command.getSequenceNumber();
        final String result = citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge", bridgeName, "config", command.getVpcConfigInJson(), "host-id", ((Long) command.getHostId()).toString(), "seq-no", Long.toString(sequenceNo));
        if (result.startsWith("SUCCESS")) {
            return new Answer(command, true, result);
        } else {
            return new Answer(command, false, result);
        }
    } catch (final Exception e) {
        s_logger.warn("caught exception while updating host with latest VPC topology", e);
        return new Answer(command, false, e.getMessage());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection)

Example 28 with Network

use of com.xensource.xenapi.Network in project cloudstack by apache.

the class CitrixOvsDestroyTunnelCommandWrapper method execute.

@Override
public Answer execute(final OvsDestroyTunnelCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName());
        if (nw == null) {
            s_logger.warn("Unable to find tunnel network for GRE key:" + command.getBridgeName());
            return new Answer(command, false, "No network found");
        }
        final String bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", command.getInPortName());
        if (result.equalsIgnoreCase("SUCCESS")) {
            return new Answer(command, true, result);
        } else {
            return new Answer(command, false, result);
        }
    } catch (final Exception e) {
        s_logger.warn("caught execption when destroy ovs tunnel", e);
        return new Answer(command, false, e.getMessage());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection)

Example 29 with Network

use of com.xensource.xenapi.Network in project cloudstack by apache.

the class CitrixResourceBase method configureTunnelNetwork.

/**
     * This method creates a XenServer network and configures it for being used
     * as a L2-in-L3 tunneled network
     */
public synchronized Network configureTunnelNetwork(final Connection conn, final Long networkId, final long hostId, final String bridgeName) {
    try {
        final Network nw = findOrCreateTunnelNetwork(conn, bridgeName);
        // Invoke plugin to setup the bridge which will be used by this
        // network
        final String bridge = nw.getBridge(conn);
        final Map<String, String> nwOtherConfig = nw.getOtherConfig(conn);
        final String configuredHosts = nwOtherConfig.get("ovs-host-setup");
        boolean configured = false;
        if (configuredHosts != null) {
            final String[] hostIdsStr = configuredHosts.split(",");
            for (final String hostIdStr : hostIdsStr) {
                if (hostIdStr.equals(((Long) hostId).toString())) {
                    configured = true;
                    break;
                }
            }
        }
        if (!configured) {
            String result;
            if (bridgeName.startsWith("OVS-DR-VPC-Bridge")) {
                result = callHostPlugin(conn, "ovstunnel", "setup_ovs_bridge_for_distributed_routing", "bridge", bridge, "key", bridgeName, "xs_nw_uuid", nw.getUuid(conn), "cs_host_id", ((Long) hostId).toString());
            } else {
                result = callHostPlugin(conn, "ovstunnel", "setup_ovs_bridge", "bridge", bridge, "key", bridgeName, "xs_nw_uuid", nw.getUuid(conn), "cs_host_id", ((Long) hostId).toString());
            }
            // Note down the fact that the ovs bridge has been setup
            final String[] res = result.split(":");
            if (res.length != 2 || !res[0].equalsIgnoreCase("SUCCESS")) {
                // TODO: Should make this error not fatal?
                throw new CloudRuntimeException("Unable to pre-configure OVS bridge " + bridge);
            }
        }
        return nw;
    } catch (final Exception e) {
        s_logger.warn("createandConfigureTunnelNetwork failed", e);
        return null;
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.xensource.xenapi.Network) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 30 with Network

use of com.xensource.xenapi.Network in project cloudstack by apache.

the class XenServer56Resource method disableVlanNetwork.

@Override
public void disableVlanNetwork(final Connection conn, final Network network) {
    try {
        final Network.Record networkr = network.getRecord(conn);
        if (!networkr.nameLabel.startsWith("VLAN")) {
            return;
        }
        final String bridge = networkr.bridge.trim();
        for (final PIF pif : networkr.PIFs) {
            final PIF.Record pifr = pif.getRecord(conn);
            if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.getUuid())) {
                continue;
            }
            final VLAN vlan = pifr.VLANMasterOf;
            if (vlan != null) {
                final String vlannum = pifr.VLAN.toString();
                final String device = pifr.device.trim();
                if (vlannum.equals("-1")) {
                    return;
                }
                try {
                    vlan.destroy(conn);
                    final Host host = Host.getByUuid(conn, _host.getUuid());
                    host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
                    host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
                    host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
                    host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
                } catch (final XenAPIException e) {
                    s_logger.trace("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString());
                }
            }
            return;
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to disable VLAN network due to " + e.toString();
        s_logger.warn(msg, e);
    } catch (final Exception e) {
        final String msg = "Unable to disable VLAN network due to " + e.getMessage();
        s_logger.warn(msg, e);
    }
}
Also used : Network(com.xensource.xenapi.Network) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VLAN(com.xensource.xenapi.VLAN) PIF(com.xensource.xenapi.PIF) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException)

Aggregations

Network (com.xensource.xenapi.Network)46 Connection (com.xensource.xenapi.Connection)35 XenAPIException (com.xensource.xenapi.Types.XenAPIException)32 XmlRpcException (org.apache.xmlrpc.XmlRpcException)30 Answer (com.cloud.agent.api.Answer)24 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Test (org.junit.Test)19 RebootAnswer (com.cloud.agent.api.RebootAnswer)16 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)16 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)16 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 NicTO (com.cloud.agent.api.to.NicTO)10 VIF (com.xensource.xenapi.VIF)10 VM (com.xensource.xenapi.VM)8 HashMap (java.util.HashMap)8 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)7 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)6 Host (com.xensource.xenapi.Host)6 PIF (com.xensource.xenapi.PIF)6