Search in sources :

Example 21 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixResourceBase method setupLinkLocalNetwork.

public void setupLinkLocalNetwork(final Connection conn) {
    try {
        final Network.Record rec = new Network.Record();
        final Set<Network> networks = Network.getByNameLabel(conn, _linkLocalPrivateNetworkName);
        Network linkLocal = null;
        if (networks.size() == 0) {
            rec.nameDescription = "link local network used by system vms";
            rec.nameLabel = _linkLocalPrivateNetworkName;
            final Map<String, String> configs = new HashMap<String, String>();
            configs.put("ip_begin", NetUtils.getLinkLocalGateway());
            configs.put("ip_end", NetUtils.getLinkLocalIpEnd());
            configs.put("netmask", NetUtils.getLinkLocalNetMask());
            configs.put("vswitch-disable-in-band", "true");
            rec.otherConfig = configs;
            linkLocal = Network.create(conn, rec);
        } else {
            linkLocal = networks.iterator().next();
            if (!linkLocal.getOtherConfig(conn).containsKey("vswitch-disable-in-band")) {
                linkLocal.addToOtherConfig(conn, "vswitch-disable-in-band", "true");
            }
        }
        /* Make sure there is a physical bridge on this network */
        VIF dom0vif = null;
        final Pair<VM, VM.Record> vm = getControlDomain(conn);
        final VM dom0 = vm.first();
        final Set<VIF> vifs = dom0.getVIFs(conn);
        if (vifs.size() != 0) {
            for (final VIF vif : vifs) {
                final Map<String, String> otherConfig = vif.getOtherConfig(conn);
                if (otherConfig != null) {
                    final String nameLabel = otherConfig.get("nameLabel");
                    if (nameLabel != null && nameLabel.equalsIgnoreCase("link_local_network_vif")) {
                        dom0vif = vif;
                    }
                }
            }
        }
        /* create temp VIF0 */
        if (dom0vif == null) {
            s_logger.debug("Can't find a vif on dom0 for link local, creating a new one");
            final VIF.Record vifr = new VIF.Record();
            vifr.VM = dom0;
            vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0);
            if (vifr.device == null) {
                s_logger.debug("Failed to create link local network, no vif available");
                return;
            }
            final Map<String, String> config = new HashMap<String, String>();
            config.put("nameLabel", "link_local_network_vif");
            vifr.otherConfig = config;
            vifr.MAC = "FE:FF:FF:FF:FF:FF";
            vifr.network = linkLocal;
            vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT;
            dom0vif = VIF.create(conn, vifr);
            plugDom0Vif(conn, dom0vif);
        } else {
            s_logger.debug("already have a vif on dom0 for link local network");
            if (!dom0vif.getCurrentlyAttached(conn)) {
                plugDom0Vif(conn, dom0vif);
            }
        }
        final String brName = linkLocal.getBridge(conn);
        callHostPlugin(conn, "vmops", "setLinkLocalIP", "brName", brName);
        _host.setLinkLocalNetwork(linkLocal.getUuid(conn));
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to create local link network", e);
        throw new CloudRuntimeException("Unable to create local link network due to " + e.toString(), e);
    } catch (final XmlRpcException e) {
        s_logger.warn("Unable to create local link network", e);
        throw new CloudRuntimeException("Unable to create local link network due to " + e.toString(), e);
    }
}
Also used : HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VIF(com.xensource.xenapi.VIF) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.xensource.xenapi.Network) VM(com.xensource.xenapi.VM) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 22 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixResourceBase method skipOrRemoveSR.

protected void skipOrRemoveSR(Connection conn, SR sr) {
    if (sr == null) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(logX(sr, "Removing SR"));
    }
    try {
        Set<VDI> vdis = sr.getVDIs(conn);
        for (VDI vdi : vdis) {
            if (MapUtils.isEmpty(vdi.getCurrentOperations(conn))) {
                continue;
            }
            return;
        }
        removeSR(conn, sr);
        return;
    } catch (XenAPIException | XmlRpcException e) {
        s_logger.warn(logX(sr, "Unable to get current opertions " + e.toString()), e);
    }
    String msg = "Remove SR failed";
    s_logger.warn(msg);
}
Also used : XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 23 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class XenServerConnectionPool method join.

protected void join(Connection conn, String masterIp, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException, Types.JoiningHostCannotContainSharedSrs {
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            Pool.join(conn, masterIp, username, password.peek());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
                break;
            }
        }
    }
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 24 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class Xenserver625StorageProcessor method createTemplateFromSnapshot2.

public Answer createTemplateFromSnapshot2(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final SnapshotObjectTO snapshotObjTO = (SnapshotObjectTO) cmd.getSrcTO();
    final TemplateObjectTO templateObjTO = (TemplateObjectTO) cmd.getDestTO();
    if (!(snapshotObjTO.getDataStore() instanceof PrimaryDataStoreTO) || !(templateObjTO.getDataStore() instanceof NfsTO)) {
        return null;
    }
    NfsTO destStore = null;
    PrimaryDataStoreTO srcStore = null;
    URI destUri = null;
    try {
        srcStore = (PrimaryDataStoreTO) snapshotObjTO.getDataStore();
        destStore = (NfsTO) templateObjTO.getDataStore();
        destUri = new URI(destStore.getUrl());
    } catch (final Exception ex) {
        s_logger.debug("Invalid URI", ex);
        return new CopyCmdAnswer("Invalid URI: " + ex.toString());
    }
    SR srcSr = null;
    SR destSr = null;
    final String destDir = templateObjTO.getPath();
    VDI destVdi = null;
    boolean result = false;
    try {
        final Map<String, String> srcDetails = cmd.getOptions();
        final String iScsiName = srcDetails.get(DiskTO.IQN);
        final String storageHost = srcDetails.get(DiskTO.STORAGE_HOST);
        final String chapInitiatorUsername = srcDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String chapInitiatorSecret = srcDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
        String srType = null;
        srType = CitrixResourceBase.SRType.LVMOISCSI.toString();
        srcSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false, srType, true);
        final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
        final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes());
        mountNfs(conn, destNfsPath, localDir);
        makeDirectory(conn, localDir + "/" + destDir);
        destSr = createFileSR(conn, localDir + "/" + destDir);
        // there should only be one VDI in this SR
        final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
        destVdi = srcVdi.copy(conn, destSr);
        final String nameLabel = "cloud-" + UUID.randomUUID().toString();
        destVdi.setNameLabel(conn, nameLabel);
        // scan makes XenServer pick up VDI physicalSize
        destSr.scan(conn);
        final String templateUuid = destVdi.getUuid(conn);
        final String templateFilename = templateUuid + ".vhd";
        final long virtualSize = destVdi.getVirtualSize(conn);
        final long physicalSize = destVdi.getPhysicalUtilisation(conn);
        // create the template.properties file
        String templatePath = destNfsPath + "/" + destDir;
        templatePath = templatePath.replaceAll("//", "/");
        result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, templateObjTO.getId());
        if (!result) {
            throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir");
        }
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(destDir + "/" + templateFilename);
        newTemplate.setFormat(Storage.ImageFormat.VHD);
        newTemplate.setHypervisorType(HypervisorType.XenServer);
        newTemplate.setSize(virtualSize);
        newTemplate.setPhysicalSize(physicalSize);
        newTemplate.setName(templateUuid);
        result = true;
        return new CopyCmdAnswer(newTemplate);
    // } catch (Exception ex) {
    // s_logger.error("Failed to create a template from a snapshot",
    // ex);
    //
    // return new
    // CopyCmdAnswer("Failed to create a template from a snapshot: " +
    // ex.toString());
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } catch (final XenAPIException e) {
        s_logger.error("Failed to create a template from a snapshot due to xenapi error", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to create a template from a snapshot due to rpc error", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } finally {
        if (!result) {
            if (destVdi != null) {
                try {
                    destVdi.destroy(conn);
                } catch (final Exception e) {
                    s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e);
                }
            }
        }
        if (srcSr != null) {
            hypervisorResource.removeSR(conn, srcSr);
        }
        if (destSr != null) {
            hypervisorResource.removeSR(conn, destSr);
        }
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 25 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class XenServer56FenceCommandWrapper method execute.

@Override
public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) {
    final Connection conn = xenServer56.getConnection();
    try {
        final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid());
        if (alive == null) {
            s_logger.debug("Failed to check heartbeat,  so unable to fence");
            return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence");
        }
        if (alive) {
            s_logger.debug("Heart beat is still going so unable to fence");
            return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence");
        }
        final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName());
        for (final VM vm : vms) {
            s_logger.info("Fence command for VM " + command.getVmName());
            vm.powerStateReset(conn);
            vm.destroy(conn);
        }
        return new FenceAnswer(command);
    } catch (final XmlRpcException e) {
        s_logger.warn("Unable to fence", e);
        return new FenceAnswer(command, false, e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to fence", e);
        return new FenceAnswer(command, false, e.getMessage());
    } catch (final Exception e) {
        s_logger.warn("Unable to fence", e);
        return new FenceAnswer(command, false, e.getMessage());
    }
}
Also used : VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) FenceAnswer(com.cloud.agent.api.FenceAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException)

Aggregations

XmlRpcException (org.apache.xmlrpc.XmlRpcException)100 XenAPIException (com.xensource.xenapi.Types.XenAPIException)75 Connection (com.xensource.xenapi.Connection)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 Answer (com.cloud.agent.api.Answer)33 IOException (java.io.IOException)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 Network (com.xensource.xenapi.Network)25 Test (org.junit.Test)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Host (com.xensource.xenapi.Host)21 RebootAnswer (com.cloud.agent.api.RebootAnswer)20 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)20 HashMap (java.util.HashMap)20 VM (com.xensource.xenapi.VM)17 VDI (com.xensource.xenapi.VDI)16 ConfigurationException (javax.naming.ConfigurationException)16 SR (com.xensource.xenapi.SR)15 InternalErrorException (com.cloud.exception.InternalErrorException)13