Search in sources :

Example 21 with Connection

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

the class CitrixResourceBase method createLocalIsoSR.

public SR createLocalIsoSR(final Connection conn, final String srName) throws XenAPIException, XmlRpcException {
    // if config drive sr already exists then return
    SR sr = getSRByNameLabelandHost(conn, _configDriveSRName + _host.getIp());
    if (sr != null) {
        s_logger.debug("Config drive SR already exist, returing it");
        return sr;
    }
    try {
        final Map<String, String> deviceConfig = new HashMap<String, String>();
        final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
        try {
            sshConnection.connect(null, 60000, 60000);
            if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
                throw new CloudRuntimeException("Unable to authenticate");
            }
            final String cmd = "mkdir -p " + _configDriveIsopath;
            if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
                throw new CloudRuntimeException("Cannot create directory configdrive_iso on XenServer hosts");
            }
        } catch (final IOException e) {
            throw new CloudRuntimeException("Unable to create iso folder", e);
        } finally {
            sshConnection.close();
        }
        s_logger.debug("Created the config drive SR " + srName + " folder path " + _configDriveIsopath);
        deviceConfig.put("location", _configDriveIsopath);
        deviceConfig.put("legacy_mode", "true");
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final String type = SRType.ISO.toString();
        sr = SR.create(conn, host, deviceConfig, new Long(0), _configDriveIsopath, "iso", type, "iso", false, new HashMap<String, String>());
        sr.setNameLabel(conn, srName);
        sr.setNameDescription(conn, deviceConfig.get("location"));
        sr.scan(conn);
        s_logger.debug("Config drive ISO SR at the path " + _configDriveIsopath + " got created in host " + _host);
        return sr;
    } catch (final XenAPIException e) {
        final String msg = "createLocalIsoSR failed! mountpoint " + e.toString();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    } catch (final Exception e) {
        final String msg = "createLocalIsoSR failed! mountpoint:  due to " + e.getMessage();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    }
}
Also used : HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) IOException(java.io.IOException) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 22 with Connection

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

the class CitrixResourceBase method ovsFullSyncStates.

private List<Pair<String, Long>> ovsFullSyncStates() {
    final Connection conn = getConnection();
    final String result = callHostPlugin(conn, "ovsgre", "ovs_get_vm_log", "host_uuid", _host.getUuid());
    final String[] logs = result != null ? result.split(";") : new String[0];
    final List<Pair<String, Long>> states = new ArrayList<Pair<String, Long>>();
    for (final String log : logs) {
        final String[] info = log.split(",");
        if (info.length != 5) {
            s_logger.warn("Wrong element number in ovs log(" + log + ")");
            continue;
        }
        // ','.join([bridge, vmName, vmId, seqno, tag])
        try {
            states.add(new Pair<String, Long>(info[0], Long.parseLong(info[3])));
        } catch (final NumberFormatException nfe) {
            states.add(new Pair<String, Long>(info[0], -1L));
        }
    }
    return states;
}
Also used : Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Example 23 with Connection

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

the class CitrixResourceBase method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
    final Connection conn = getConnection();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        final IpAddressTO[] ips = cmd.getIpAddresses();
        for (final IpAddressTO ip : ips) {
            final VM router = getVM(conn, routerName);
            final VIF correctVif = getVifByMac(conn, router, ip.getVifMacAddress());
            setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif);
        }
    } catch (final Exception e) {
        s_logger.error("Ip Assoc failure on applying one ip due to exception:  ", e);
        return new ExecutionResult(false, e.getMessage());
    }
    return new ExecutionResult(true, null);
}
Also used : VIF(com.xensource.xenapi.VIF) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ExecutionResult(com.cloud.utils.ExecutionResult) 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 24 with Connection

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

the class CitrixResourceBase method initialize.

@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
    final Connection conn = getConnection();
    if (!getHostInfo(conn)) {
        s_logger.warn("Unable to get host information for " + _host.getIp());
        return null;
    }
    final StartupRoutingCommand cmd = new StartupRoutingCommand();
    fillHostInfo(conn, cmd);
    cmd.setHypervisorType(HypervisorType.XenServer);
    cmd.setCluster(_cluster);
    cmd.setPoolSync(false);
    try {
        final Pool pool = Pool.getByUuid(conn, _host.getPool());
        final Pool.Record poolr = pool.getRecord(conn);
        poolr.master.getRecord(conn);
    } catch (final Throwable e) {
        s_logger.warn("Check for master failed, failing the FULL Cluster sync command");
    }
    final StartupStorageCommand sscmd = initializeLocalSR(conn);
    if (sscmd != null) {
        return new StartupCommand[] { cmd, sscmd };
    }
    return new StartupCommand[] { cmd };
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) Pool(com.xensource.xenapi.Pool) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 25 with Connection

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

the class CitrixResourceBase method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
    final Connection conn = getConnection();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final IpAddressTO pubIp = cmd.getIpAddress();
    try {
        final VM router = getVM(conn, routerName);
        final VIF correctVif = getCorrectVif(conn, router, pubIp);
        pubIp.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
    } catch (final Exception e) {
        final String msg = "Ip SNAT failure due to " + e.toString();
        s_logger.error(msg, e);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : VIF(com.xensource.xenapi.VIF) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) URLConnection(java.net.URLConnection) ExecutionResult(com.cloud.utils.ExecutionResult) 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)

Aggregations

Connection (com.xensource.xenapi.Connection)165 XenAPIException (com.xensource.xenapi.Types.XenAPIException)88 XmlRpcException (org.apache.xmlrpc.XmlRpcException)86 Answer (com.cloud.agent.api.Answer)79 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)58 Test (org.junit.Test)53 VDI (com.xensource.xenapi.VDI)47 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)46 SR (com.xensource.xenapi.SR)42 InternalErrorException (com.cloud.exception.InternalErrorException)39 RebootAnswer (com.cloud.agent.api.RebootAnswer)38 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)38 Network (com.xensource.xenapi.Network)35 VM (com.xensource.xenapi.VM)32 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)23 HashMap (java.util.HashMap)23 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)23 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)20 Host (com.xensource.xenapi.Host)19 URI (java.net.URI)19