Search in sources :

Example 11 with Pool

use of com.xensource.xenapi.Pool in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method callHostPluginThroughMaster.

protected String callHostPluginThroughMaster(final Connection conn, final String plugin, final String cmd, final String... params) {
    final Map<String, String> args = new HashMap<>();
    try {
        final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
        if (poolRecs.size() != 1) {
            throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + _host.getUuid());
        }
        final Host master = poolRecs.values().iterator().next().master;
        for (int i = 0; i < params.length; i += 2) {
            args.put(params[i], params[i + 1]);
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
        }
        final String result = master.callPlugin(conn, plugin, cmd, args);
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin Result: " + result);
        }
        return result.replace("\n", "");
    } catch (final Types.HandleInvalid e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle);
    } catch (final XenAPIException e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e);
    } catch (final XmlRpcException e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e);
    }
    return null;
}
Also used : Types(com.xensource.xenapi.Types) HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 12 with Pool

use of com.xensource.xenapi.Pool in project cosmic by MissionCriticalCloud.

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;
        }
        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, 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 13 with Pool

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

the class XenServerResourceNewBase method initialize.

@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
    final StartupCommand[] cmds = super.initialize();
    final Connection conn = getConnection();
    Pool pool;
    try {
        pool = Pool.getByUuid(conn, _host.getPool());
        final Pool.Record poolr = pool.getRecord(conn);
        final Host.Record masterRecord = poolr.master.getRecord(conn);
        if (_host.getUuid().equals(masterRecord.uuid)) {
            _listener = new VmEventListener(true);
        // 
        // TODO disable event listener for now. Wait until everything else is ready
        // 
        // _listener.start();
        } else {
            _listener = new VmEventListener(false);
        }
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to determine who is the master", e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to determine who is the master", e);
    }
    return cmds;
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Pool(com.xensource.xenapi.Pool) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 14 with Pool

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

the class CitrixResourceBase method callHostPluginThroughMaster.

protected String callHostPluginThroughMaster(final Connection conn, final String plugin, final String cmd, final String... params) {
    final Map<String, String> args = new HashMap<String, String>();
    try {
        final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
        if (poolRecs.size() != 1) {
            throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + _host.getUuid());
        }
        final Host master = poolRecs.values().iterator().next().master;
        for (int i = 0; i < params.length; i += 2) {
            args.put(params[i], params[i + 1]);
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
        }
        final String result = master.callPlugin(conn, plugin, cmd, args);
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin Result: " + result);
        }
        return result.replace("\n", "");
    } catch (final Types.HandleInvalid e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle);
    } catch (final XenAPIException e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e);
    } catch (final XmlRpcException e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e);
    }
    return null;
}
Also used : Types(com.xensource.xenapi.Types) HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 15 with Pool

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

the class CitrixClusterVMMetaDataSyncCommandWrapper method execute.

@Override
public Answer execute(final ClusterVMMetaDataSyncCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    // check if this is master
    try {
        final Pool pool = Pool.getByUuid(conn, citrixResourceBase.getHost().getPool());
        final Pool.Record poolr = pool.getRecord(conn);
        final Host.Record hostr = poolr.master.getRecord(conn);
        if (!citrixResourceBase.getHost().getUuid().equals(hostr.uuid)) {
            return new ClusterVMMetaDataSyncAnswer(command.getClusterId(), null);
        }
    } catch (final Throwable e) {
        s_logger.warn("Check for master failed, failing the Cluster sync VMMetaData command");
        return new ClusterVMMetaDataSyncAnswer(command.getClusterId(), null);
    }
    final HashMap<String, String> vmMetadatum = citrixResourceBase.clusterVMMetaDataSync(conn);
    return new ClusterVMMetaDataSyncAnswer(command.getClusterId(), vmMetadatum);
}
Also used : ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) Connection(com.xensource.xenapi.Connection) Pool(com.xensource.xenapi.Pool) Host(com.xensource.xenapi.Host)

Aggregations

Pool (com.xensource.xenapi.Pool)16 Connection (com.xensource.xenapi.Connection)14 XenAPIException (com.xensource.xenapi.Types.XenAPIException)13 XmlRpcException (org.apache.xmlrpc.XmlRpcException)13 Host (com.xensource.xenapi.Host)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 Types (com.xensource.xenapi.Types)6 StartupCommand (com.cloud.agent.api.StartupCommand)4 HashMap (java.util.HashMap)4 Answer (com.cloud.agent.api.Answer)2 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)2 ClusterVMMetaDataSyncCommand (com.cloud.agent.api.ClusterVMMetaDataSyncCommand)2 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 SetupAnswer (com.cloud.agent.api.SetupAnswer)2 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)2 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 ClusterVO (com.cloud.dc.ClusterVO)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2