Search in sources :

Example 1 with Bond

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

the class CitrixSetupCommandWrapper method execute.

@Override
public Answer execute(final SetupCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
        if (poolRecs.size() != 1) {
            throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + citrixResourceBase.getHost().getUuid());
        }
        final Host master = poolRecs.values().iterator().next().master;
        citrixResourceBase.setupServer(conn, master);
        final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
        citrixResourceBase.setupServer(conn, host);
        if (!citrixResourceBase.setIptables(conn)) {
            s_logger.warn("set xenserver Iptable failed");
            return null;
        }
        if (citrixResourceBase.isSecurityGroupEnabled()) {
            final boolean canBridgeFirewall = citrixResourceBase.canBridgeFirewall(conn);
            citrixResourceBase.setCanBridgeFirewall(canBridgeFirewall);
            if (!canBridgeFirewall) {
                final String msg = "Failed to configure brige firewall";
                s_logger.warn(msg);
                s_logger.warn("Check host " + citrixResourceBase.getHost().getIp() + " for CSP is installed or not and check network mode for bridge");
                return new SetupAnswer(command, msg);
            }
        }
        final boolean r = citrixResourceBase.launchHeartBeat(conn);
        if (!r) {
            return null;
        }
        citrixResourceBase.cleanupTemplateSR(conn);
        try {
            if (command.useMultipath()) {
                // the config value is set to true
                host.addToOtherConfig(conn, "multipathing", "true");
                host.addToOtherConfig(conn, "multipathhandle", "dmp");
            }
        } catch (final Types.MapDuplicateKey e) {
            s_logger.debug("multipath is already set");
        }
        if (command.needSetup()) {
            final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "setup_iscsi", "uuid", citrixResourceBase.getHost().getUuid());
            if (!result.contains("> DONE <")) {
                s_logger.warn("Unable to setup iscsi: " + result);
                return new SetupAnswer(command, result);
            }
            Pair<PIF, PIF.Record> mgmtPif = null;
            final Set<PIF> hostPifs = host.getPIFs(conn);
            for (final PIF pif : hostPifs) {
                final PIF.Record rec = pif.getRecord(conn);
                if (rec.management) {
                    if (rec.VLAN != null && rec.VLAN != -1) {
                        final String msg = new StringBuilder("Unsupported configuration.  Management network is on a VLAN.  host=").append(citrixResourceBase.getHost().getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
                        s_logger.warn(msg);
                        return new SetupAnswer(command, msg);
                    }
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Management network is on pif=" + rec.uuid);
                    }
                    mgmtPif = new Pair<PIF, PIF.Record>(pif, rec);
                    break;
                }
            }
            if (mgmtPif == null) {
                final String msg = "Unable to find management network for " + citrixResourceBase.getHost().getUuid();
                s_logger.warn(msg);
                return new SetupAnswer(command, msg);
            }
            final Map<Network, Network.Record> networks = Network.getAllRecords(conn);
            if (networks == null) {
                final String msg = "Unable to setup as there are no networks in the host: " + citrixResourceBase.getHost().getUuid();
                s_logger.warn(msg);
                return new SetupAnswer(command, msg);
            }
            for (final Network.Record network : networks.values()) {
                if (network.nameLabel.equals("cloud-private")) {
                    for (final PIF pif : network.PIFs) {
                        final PIF.Record pr = pif.getRecord(conn);
                        if (citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + ";  Network=" + network.uuid + "; pif=" + pr.uuid);
                            }
                            if (pr.VLAN != null && pr.VLAN != -1) {
                                final String msg = new StringBuilder("Unsupported configuration.  Network cloud-private is on a VLAN.  Network=").append(network.uuid).append(" ; pif=").append(pr.uuid).toString();
                                s_logger.warn(msg);
                                return new SetupAnswer(command, msg);
                            }
                            if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) {
                                if (pr.bondMasterOf.size() > 1) {
                                    final String msg = new StringBuilder("Unsupported configuration.  Network cloud-private has more than one bond.  Network=").append(network.uuid).append("; pif=").append(pr.uuid).toString();
                                    s_logger.warn(msg);
                                    return new SetupAnswer(command, msg);
                                }
                                final Bond bond = pr.bondMasterOf.iterator().next();
                                final Set<PIF> slaves = bond.getSlaves(conn);
                                for (final PIF slave : slaves) {
                                    final PIF.Record spr = slave.getRecord(conn);
                                    if (spr.management) {
                                        if (!citrixResourceBase.transferManagementNetwork(conn, host, slave, spr, pif)) {
                                            final String msg = new StringBuilder("Unable to transfer management network.  slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" + citrixResourceBase.getHost().getUuid()).toString();
                                            s_logger.warn(msg);
                                            return new SetupAnswer(command, msg);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return new SetupAnswer(command, false);
    } catch (final XmlRpcException e) {
        s_logger.warn("Unable to setup", e);
        return new SetupAnswer(command, e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to setup", e);
        return new SetupAnswer(command, e.getMessage());
    } catch (final Exception e) {
        s_logger.warn("Unable to setup", e);
        return new SetupAnswer(command, e.getMessage());
    }
}
Also used : Types(com.xensource.xenapi.Types) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) PIF(com.xensource.xenapi.PIF) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.xensource.xenapi.Network) Pool(com.xensource.xenapi.Pool) Bond(com.xensource.xenapi.Bond) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 2 with Bond

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

the class CitrixResourceBase method getManagementNetwork.

protected XsLocalNetwork getManagementNetwork(final Connection conn) throws XmlRpcException, XenAPIException {
    PIF mgmtPif = null;
    PIF.Record mgmtPifRec = null;
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Set<PIF> hostPifs = host.getPIFs(conn);
    for (final PIF pif : hostPifs) {
        final PIF.Record rec = pif.getRecord(conn);
        if (rec.management) {
            if (rec.VLAN != null && rec.VLAN != -1) {
                final String msg = new StringBuilder("Unsupported configuration.  Management network is on a VLAN.  host=").append(_host.getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Management network is on pif=" + rec.uuid);
            }
            mgmtPif = pif;
            mgmtPifRec = rec;
            break;
        }
    }
    if (mgmtPif == null) {
        final String msg = "Unable to find management network for " + _host.getUuid();
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    final Bond bond = mgmtPifRec.bondSlaveOf;
    if (!isRefNull(bond)) {
        final String msg = "Management interface is on slave(" + mgmtPifRec.uuid + ") of bond(" + bond.getUuid(conn) + ") on host(" + _host.getUuid() + "), please move management interface to bond!";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    final Network nk = mgmtPifRec.network;
    final Network.Record nkRec = nk.getRecord(conn);
    return new XsLocalNetwork(this, nk, nkRec, mgmtPif, mgmtPifRec);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.xensource.xenapi.Network) Host(com.xensource.xenapi.Host) PIF(com.xensource.xenapi.PIF) Bond(com.xensource.xenapi.Bond)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 Bond (com.xensource.xenapi.Bond)2 Host (com.xensource.xenapi.Host)2 Network (com.xensource.xenapi.Network)2 PIF (com.xensource.xenapi.PIF)2 SetupAnswer (com.cloud.agent.api.SetupAnswer)1 Connection (com.xensource.xenapi.Connection)1 Pool (com.xensource.xenapi.Pool)1 Types (com.xensource.xenapi.Types)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1