/** * Find a device in the map with the given type. */ public static VmDevice findVmDeviceByType(Map<?, VmDevice> vmManagedDeviceMap, String typeName) { for (VmDevice vmDevice : vmManagedDeviceMap.values()) { if (vmDevice.getDevice().equals(typeName)) { return vmDevice; } } return null; }
@Override public String getValue(VmDeviceFeEntity deviceEntity) { return deviceEntity.getVmDevice().getDevice(); } };
public VmDeviceType getDeviceType() { return VmDeviceType.getByName(super.getDevice()); }
public static boolean isDisk(VmDevice device) { return device.getType() == VmDeviceGeneralType.DISK && device.getDevice().equals(VmDeviceType.DISK.getName()); }
public static boolean isMemory(VmDevice device) { return VmDeviceGeneralType.MEMORY == device.getType() && VmDeviceType.MEMORY.getName().equals(device.getDevice()); }
public static boolean isVirtIoScsiDeviceExists(Collection<VmDevice> devices) { for (VmDevice device : devices) { if (device.getType() == VmDeviceGeneralType.CONTROLLER && device.getDevice().equals(VmDeviceType.VIRTIOSCSI.getName())) { return true; } } return false; }
public static boolean isBridge(VmDevice device) { return device.getType() == VmDeviceGeneralType.INTERFACE && device.getDevice().equals(VmDeviceType.BRIDGE.getName()); }
public static boolean isHostDevInterface(VmDevice device) { return device.getType() == VmDeviceGeneralType.INTERFACE && device.getDevice().equals(VmDeviceType.HOST_DEVICE.getName()); }
public static boolean isCD(VmDevice device) { return device.getType() == VmDeviceGeneralType.DISK && device.getDevice().equals(VmDeviceType.CDROM.getName()); }
@Override public void onSuccess(QueryReturnValue returnValue) { final Collection<VmDevice> vmDevices = returnValue.getReturnValue(); final ArrayList<VmDeviceFeEntity> frontendDevices = new ArrayList<>(); for (VmDevice vmDevice : vmDevices) { // exclude USB controller devices with model property set to 'none' if (vmDevice.getDevice().equals(VmDeviceType.USB.getName()) && vmDevice.getType() == VmDeviceGeneralType.CONTROLLER && (vmDevice.getSpecParams().get(MODEL)) != null && vmDevice.getSpecParams().get(MODEL).equals(UsbControllerModel.NONE.libvirtName)) { continue; } frontendDevices.add(new VmDeviceFeEntity( vmDevice, vm, idsOfDevicesBeingUnplugged.contains(vmDevice.getId()))); } setItems(frontendDevices); } }) {};
protected void updateGraphics(Guid id) { Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(id), new AsyncQuery<QueryReturnValue>(returnValue -> { List<VmDevice> graphicsVmDevs = returnValue.getReturnValue(); List<GraphicsType> graphicsTypes = new ArrayList<>(); for (VmDevice graphicsVmDev : graphicsVmDevs) { graphicsTypes.add(GraphicsType.fromString(graphicsVmDev.getDevice())); } boolean hasSpiceAndVnc = graphicsTypes.size() == 2 && graphicsTypes.containsAll(Arrays.asList(GraphicsType.SPICE, GraphicsType.VNC)); boolean canBeSelected = getModel().getGraphicsType().getItems().contains(UnitVmModel.GraphicsTypes.SPICE_AND_VNC); if (hasSpiceAndVnc && canBeSelected) { getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.SPICE_AND_VNC); } else if (graphicsVmDevs.size() == 1) { GraphicsType type = GraphicsType.fromString(graphicsVmDevs.get(0).getDevice()); getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.fromGraphicsType(type)); } })); }
@SuppressWarnings("unchecked") public VmPayload(VmDevice dev) { super(dev.getId(), dev.getType(), dev.getDevice(), dev.getAddress(), dev.getSpecParams(), dev.isManaged(), dev.isPlugged(), dev.getReadOnly(), dev.getAlias(), dev.getCustomProperties(), dev.getSnapshotId(), dev.getLogicalName()); if (dev.getSpecParams() != null) { Map<String, Object> payload = (Map<String, Object>)dev.getSpecParams().get(SpecParamsPayload); this.volumeId = (String)payload.get(SpecParamsVolumeIdType); this.files = (HashMap<String, String>)payload.get(SpecParamsFileType); } }
public GraphicsDevice(VmDevice vmDev) { this(GraphicsType.fromString(vmDev.getDevice()).getCorrespondingDeviceType()); setId(vmDev.getId()); setSpecParams(vmDev.getSpecParams()); }
private void writeCd() { Collection<VmDevice> devices = vmBase.getManagedDeviceMap().values(); for (VmDevice vmDevice : devices) { if (vmDevice.getDevice().equals(VmDeviceType.CDROM.getName())) { _writer.writeStartElement("Item"); _writer.writeElement(RASD_URI, "Caption", "CDROM"); _writer.writeElement(RASD_URI, "InstanceId", vmDevice.getId().getDeviceId().toString()); _writer.writeElement(RASD_URI, "ResourceType", OvfHardware.CD); writeVmDeviceInfo(vmDevice); _writer.writeEndElement(); // item break; // only one CD is currently supported } } }
private void writeOtherDevices() { List<VmDevice> devices = vmBase.getUnmanagedDeviceList(); Collection<VmDevice> managedDevices = vmBase.getManagedDeviceMap().values(); for (VmDevice device : managedDevices) { if (VmDeviceCommonUtils.isSpecialDevice(device.getDevice(), device.getType())) { devices.add(device); } } for (VmDevice vmDevice : devices) { _writer.writeStartElement("Item"); _writer.writeElement(RASD_URI, "ResourceType", OvfHardware.OTHER); _writer.writeElement(RASD_URI, "InstanceId", vmDevice.getId().getDeviceId().toString()); writeVmDeviceInfo(vmDevice); _writer.writeEndElement(); // item } }
public VmHostDevice(VmDevice device) { this(); setId(device.getId()); setDevice(device.getDevice()); setSpecParams(device.getSpecParams()); setAddress(device.getAddress()); setAlias(device.getAlias()); }
private void writeVmDeviceInfo(VmDevice vmDevice) { _writer.writeElement(VMD_TYPE, String.valueOf(vmDevice.getType().getValue())); _writer.writeElement(VMD_DEVICE, String.valueOf(vmDevice.getDevice())); _writer.writeElement(VMD_ADDRESS, vmDevice.getAddress()); _writer.writeElement(VMD_BOOT_ORDER, String.valueOf(vmDevice.getBootOrder())); _writer.writeElement(VMD_IS_PLUGGED, String.valueOf(vmDevice.isPlugged())); _writer.writeElement(VMD_IS_READONLY, String.valueOf(vmDevice.getReadOnly())); _writer.writeElement(VMD_ALIAS, String.valueOf(vmDevice.getAlias())); if (vmDevice.getSpecParams() != null && vmDevice.getSpecParams().size() != 0 && !VmPayload.isPayload(vmDevice.getSpecParams())) { _writer.writeStartElement(VMD_SPEC_PARAMS); _writer.writeMap(vmDevice.getSpecParams()); _writer.writeEndElement(); } if (vmDevice.getCustomProperties() != null && !vmDevice.getCustomProperties().isEmpty()) { _writer.writeElement(VMD_CUSTOM_PROP, DevicePropertiesUtils.getInstance().convertProperties(vmDevice.getCustomProperties())); } if (vmDevice.getSnapshotId() != null) { _writer.writeElement(VMD_SNAPSHOT_PROP, String.valueOf(vmDevice.getSnapshotId())); } }
VmDevice vmDevice = readOtherHardwareItem(item); readVirtioSerial = readVirtioSerial || VmDeviceType.VIRTIOSERIAL.getName().equals(vmDevice.getDevice()); break;
@Override public String toString() { return ToStringBuilder.forInstance(this) .append("id", id) .append("device", getDevice()) .append("type", getType()) .append("specParams", getSpecParams()) .append("address", getAddress()) .append("managed", isManaged()) .append("plugged", isPlugged()) .append("readOnly", getReadOnly()) .append("deviceAlias", getAlias()) .append("customProperties", getCustomProperties()) .append("snapshotId", getSnapshotId()) .append("logicalName", getLogicalName()) .append("hostDevice", getHostDevice()) .build(); }
@Override protected MapSqlParameterSource createFullParametersMapper(VmDevice entity) { return createIdParameterMapper(entity.getId()) .addValue("device", entity.getDevice()) .addValue("type", entity.getType().getValue()) .addValue("address", entity.getAddress()) .addValue("spec_params", SerializationFactory.getSerializer().serialize(entity.getSpecParams())) .addValue("is_managed", entity.isManaged()) .addValue("is_plugged", entity.isPlugged()) .addValue("is_readonly", entity.getReadOnly()) .addValue("alias", entity.getAlias()) .addValue("custom_properties", SerializationFactory.getSerializer().serialize(entity.getCustomProperties())) .addValue("snapshot_id", entity.getSnapshotId()) .addValue("logical_name", entity.getLogicalName()) .addValue("host_device", entity.getHostDevice()); }