From be40e979e03e41ddcd831d9c330902f76908ca64 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 25 Feb 2021 15:00:38 +0100 Subject: Refactor disk image representation and add unit tests --- .../org/openslx/util/vm/QemuMetaDataUtils.java | 188 --------------------- 1 file changed, 188 deletions(-) delete mode 100644 src/main/java/org/openslx/util/vm/QemuMetaDataUtils.java (limited to 'src/main/java/org/openslx/util/vm/QemuMetaDataUtils.java') diff --git a/src/main/java/org/openslx/util/vm/QemuMetaDataUtils.java b/src/main/java/org/openslx/util/vm/QemuMetaDataUtils.java deleted file mode 100644 index 42c3fb6..0000000 --- a/src/main/java/org/openslx/util/vm/QemuMetaDataUtils.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.openslx.util.vm; - -import java.util.ArrayList; - -import org.openslx.libvirt.domain.device.Disk; -import org.openslx.libvirt.domain.device.Interface; -import org.openslx.libvirt.domain.device.Disk.BusType; -import org.openslx.libvirt.domain.device.Sound; -import org.openslx.util.vm.VmMetaData.DriveBusType; -import org.openslx.util.vm.VmMetaData.EthernetDevType; -import org.openslx.util.vm.VmMetaData.SoundCardType; - -/** - * Collection of utils to convert data types from bwLehrpool to Libvirt and vice versa. - * - * @author Manuel Bentele - * @version 1.0 - */ -public class QemuMetaDataUtils -{ - /** - * Converts a Libvirt disk device bus type to a VM metadata driver bus type. - * - * @param busType Libvirt disk device bus type. - * @return VM metadata bus type of the disk drive. - */ - public static DriveBusType convertBusType( Disk.BusType busType ) - { - DriveBusType type = null; - - switch ( busType ) { - case IDE: - type = DriveBusType.IDE; - break; - case SATA: - type = DriveBusType.SATA; - break; - case SCSI: - type = DriveBusType.SCSI; - break; - default: - type = null; - break; - } - - return type; - } - - /** - * Converts a VM metadata driver bus type to a Libvirt disk device bus type. - * - * @param busType VM metadata bus type of the disk drive. - * @return Libvirt disk device bus type. - */ - public static Disk.BusType convertBusType( DriveBusType busType ) - { - Disk.BusType type = null; - - switch ( busType ) { - case IDE: - type = BusType.IDE; - break; - case SATA: - type = BusType.SATA; - break; - case SCSI: - type = BusType.SCSI; - break; - } - - return type; - } - - /** - * Converts a Libvirt sound device model to a VM metadata sound card type. - * - * @param soundDeviceModel Libvirt sound device model. - * @return VM metadata sound card type. - */ - public static SoundCardType convertSoundDeviceModel( Sound.Model soundDeviceModel ) - { - SoundCardType type = SoundCardType.NONE; - - switch ( soundDeviceModel ) { - case AC97: - type = SoundCardType.AC; - break; - case ES1370: - type = SoundCardType.ES; - break; - case ICH6: - type = SoundCardType.HD_AUDIO; - break; - case ICH9: - type = SoundCardType.HD_AUDIO; - break; - case SB16: - type = SoundCardType.SOUND_BLASTER; - break; - } - - return type; - } - - /** - * Converts a Libvirt network device model to a VM metadata ethernet device type. - * - * @param soundDeviceModel Libvirt network device model. - * @return VM metadata ethernet device type. - */ - public static EthernetDevType convertNetworkDeviceModel( Interface.Model networkDeviceModel ) - { - EthernetDevType type = EthernetDevType.NONE; - - switch ( networkDeviceModel ) { - case E1000: - type = EthernetDevType.E1000; - break; - case E1000E: - type = EthernetDevType.E1000E; - break; - case PCNET: - type = EthernetDevType.PCNETPCI2; - break; - case VIRTIO: - type = EthernetDevType.PARAVIRT; - break; - case VIRTIO_NET_PCI: - type = EthernetDevType.PARAVIRT; - break; - case VIRTIO_NET_PCI_NON_TRANSITIONAL: - type = EthernetDevType.PARAVIRT; - break; - case VIRTIO_NET_PCI_TRANSITIONAL: - type = EthernetDevType.PARAVIRT; - break; - case VMXNET3: - type = EthernetDevType.VMXNET3; - break; - default: - type = EthernetDevType.AUTO; - break; - } - - return type; - } - - /** - * Returns an item from a given {@link ArrayList}. - * - * The item is selected by a given index. If the item is not available within the - * {@link ArrayList}, null is returned. - * - * @param type of the {@link ArrayList}. - * @param array {@link ArrayList} of type T. - * @param index selects the item from the {@link ArrayList}. - * @return selected item of the {@link ArrayList}. - */ - public static T getArrayIndex( ArrayList array, int index ) - { - T ret; - - try { - ret = array.get( index ); - } catch ( IndexOutOfBoundsException e ) { - ret = null; - } - - return ret; - } - - /** - * Creates an alphabetical device name constructed from a device prefix and a device number. - * - * @param devicePrefix prefix of the constructed device name. - * @param deviceNumber number of the device. - * @return alphabetical device name. - */ - public static String createAlphabeticalDeviceName( String devicePrefix, int deviceNumber ) - { - if ( deviceNumber < 0 || deviceNumber >= ( 'z' - 'a' ) ) { - String errorMsg = new String( "Device number is out of range to be able to create a valid device name." ); - throw new IllegalArgumentException( errorMsg ); - } - - return devicePrefix + ( 'a' + deviceNumber ); - } -} -- cgit v1.2.3-55-g7522