Search in sources :

Example 1 with VGPUType

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

the class XenServer620SP1Resource method getGPUGroupDetails.

@Override
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final Connection conn) throws XenAPIException, XmlRpcException {
    final HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Set<PGPU> pgpus = host.getPGPUs(conn);
    final Iterator<PGPU> iter = pgpus.iterator();
    while (iter.hasNext()) {
        final PGPU pgpu = iter.next();
        final GPUGroup gpuGroup = pgpu.getGPUGroup(conn);
        final Set<VGPUType> enabledVGPUTypes = gpuGroup.getEnabledVGPUTypes(conn);
        final String groupName = gpuGroup.getNameLabel(conn);
        HashMap<String, VgpuTypesInfo> gpuCapacity = new HashMap<String, VgpuTypesInfo>();
        if (groupDetails.get(groupName) != null) {
            gpuCapacity = groupDetails.get(groupName);
        }
        // Get remaining capacity of all the enabled VGPU in a PGPU
        if (enabledVGPUTypes != null) {
            final Iterator<VGPUType> it = enabledVGPUTypes.iterator();
            while (it.hasNext()) {
                final VGPUType type = it.next();
                final Record record = type.getRecord(conn);
                Long remainingCapacity = pgpu.getRemainingCapacity(conn, type);
                Long maxCapacity = pgpu.getSupportedVGPUMaxCapacities(conn).get(type);
                VgpuTypesInfo entry;
                if ((entry = gpuCapacity.get(record.modelName)) != null) {
                    remainingCapacity += entry.getRemainingCapacity();
                    maxCapacity += entry.getMaxCapacity();
                    entry.setRemainingCapacity(remainingCapacity);
                    entry.setMaxVmCapacity(maxCapacity);
                    gpuCapacity.put(record.modelName, entry);
                } else {
                    final VgpuTypesInfo vgpuTypeRecord = new VgpuTypesInfo(null, record.modelName, record.framebufferSize, record.maxHeads, record.maxResolutionX, record.maxResolutionY, maxCapacity, remainingCapacity, maxCapacity);
                    gpuCapacity.put(record.modelName, vgpuTypeRecord);
                }
            }
        }
        groupDetails.put(groupName, gpuCapacity);
    }
    return groupDetails;
}
Also used : HashMap(java.util.HashMap) VGPUType(com.xensource.xenapi.VGPUType) Host(com.xensource.xenapi.Host) PGPU(com.xensource.xenapi.PGPU) Record(com.xensource.xenapi.VGPUType.Record) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo) GPUGroup(com.xensource.xenapi.GPUGroup)

Example 2 with VGPUType

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

the class XenServer620SP1Resource method createVGPU.

@Override
public void createVGPU(final Connection conn, final StartCommand cmd, final VM vm, final GPUDeviceTO gpuDevice) throws XenAPIException, XmlRpcException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Creating VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] in gpu group" + gpuDevice.getGpuGroup() + " for VM " + cmd.getVirtualMachine().getName());
    }
    final Set<GPUGroup> groups = GPUGroup.getByNameLabel(conn, gpuDevice.getGpuGroup());
    assert groups.size() == 1 : "Should only have 1 group but found " + groups.size();
    final GPUGroup gpuGroup = groups.iterator().next();
    final Set<VGPUType> vgpuTypes = gpuGroup.getEnabledVGPUTypes(conn);
    final Iterator<VGPUType> iter = vgpuTypes.iterator();
    VGPUType vgpuType = null;
    while (iter.hasNext()) {
        final VGPUType entry = iter.next();
        if (entry.getModelName(conn).equals(gpuDevice.getVgpuType())) {
            vgpuType = entry;
        }
    }
    // Only allow device = "0" for now, as XenServer supports just a single vGPU per VM.
    final String device = "0";
    final Map<String, String> other_config = new HashMap<String, String>();
    VGPU.create(conn, vm, gpuGroup, device, other_config, vgpuType);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Created VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] for VM " + cmd.getVirtualMachine().getName());
    }
    // Calculate and set remaining GPU capacity in the host.
    cmd.getVirtualMachine().getGpuDevice().setGroupDetails(getGPUGroupDetails(conn));
}
Also used : HashMap(java.util.HashMap) VGPUType(com.xensource.xenapi.VGPUType) GPUGroup(com.xensource.xenapi.GPUGroup)

Aggregations

GPUGroup (com.xensource.xenapi.GPUGroup)2 VGPUType (com.xensource.xenapi.VGPUType)2 HashMap (java.util.HashMap)2 VgpuTypesInfo (com.cloud.agent.api.VgpuTypesInfo)1 Host (com.xensource.xenapi.Host)1 PGPU (com.xensource.xenapi.PGPU)1 Record (com.xensource.xenapi.VGPUType.Record)1