diff options
Diffstat (limited to 'src/main/java/org/openslx/util/vm/QemuMetaData.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/QemuMetaData.java | 103 |
1 files changed, 39 insertions, 64 deletions
diff --git a/src/main/java/org/openslx/util/vm/QemuMetaData.java b/src/main/java/org/openslx/util/vm/QemuMetaData.java index 73612ab..8855f9c 100644 --- a/src/main/java/org/openslx/util/vm/QemuMetaData.java +++ b/src/main/java/org/openslx/util/vm/QemuMetaData.java @@ -3,10 +3,8 @@ package org.openslx.util.vm; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.TreeMap; import org.apache.log4j.Logger; @@ -56,26 +54,22 @@ class QemuSoundCardMeta { public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAccelMeta, QemuHWVersionMeta, QemuEthernetDevTypeMeta> { - private final Map<String, String> arguments = new HashMap<>(); //to remove at the end. easier - // the above map's elements will take the place of <args> in the config string - private final QemuConfig config; + private static final Logger LOGGER = Logger.getLogger(QemuMetaData.class); - private String setup; + private static final Virtualizer virtualizer = new Virtualizer(TConst.VIRT_QEMU, "QEMU-KVM"); - private final static String QUOTE = "\""; + private final QemuConfig config; private TreeMap<String, String> option; private LinkedHashMap<String, String> header; - private static final Logger LOGGER = Logger.getLogger(QemuMetaData.class); - - private static final Virtualizer virtualizer = new Virtualizer(TConst.VIRT_QEMU, "QEMU-KVM"); - private int cdromCounter = 0; private int floppyCounter = 0; + private int netdevCounter = 0; + public static enum EthernetType { NAT("qnet1"), BRIDGED("qnet0"), HOST_ONLY("qnet2"); @@ -84,10 +78,6 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce private EthernetType(String vnet) { this.vmnet = vnet; } - - public String getVMnet() { - return this.vmnet; - } } public QemuMetaData(List<OperatingSystem> osList, File config) { @@ -126,7 +116,7 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce @Override public void applySettingsForLocalEdit() { - //nothing for VmWare + //nothing ! for VMware } @Override @@ -140,11 +130,11 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce option = new TreeMap<>(); option = config.get(DRIVE.getHeader(), DRIVE.getID()); - // Drive Filename && Bus if (option != null) { - option.replace("file", diskImagePath); + option.remove("file"); + option.put("file", diskImagePath); if (option.get("if") == null) { - + } else { switch (option.get("if")) { case "ide": @@ -163,12 +153,10 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce } else { LOGGER.error("Missing disk"); } - //Setting settings header = new LinkedHashMap<>(); header.put(DRIVE.getHeader(), DRIVE.getID()); config.set(header, option); - // Device option = new TreeMap<>(); option = config.get(DEVICE.getHeader(), DEVICE.getID()); @@ -177,14 +165,14 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce header = new LinkedHashMap<>(); header.put(DEVICE.getHeader(), null); - option.put("drive",DRIVE.getID()); + option.put("drive", DRIVE.getID()); if (bus != null) { if (bus.equals(DriveBusType.IDE)) { option.put("driver", "ide-hd"); } else if (bus.equals(DriveBusType.SCSI)) { option.put("driver", "scsi-hd"); } - }else{ + } else { //Shouldn't come to this but to check TODO } config.set(header, option); @@ -218,7 +206,7 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce @Override public boolean addRam(int mem) { option = new TreeMap<>(); - option.put("size", ""+ mem); + option.put("size", "" + mem); header = new LinkedHashMap<>(); header.put(MEMORY.getHeader(), null); @@ -239,7 +227,7 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce option.put("file", image); header = new LinkedHashMap<>(); - header.put(DRIVE.getHeader(),"floppy" + floppyCounter); + header.put(DRIVE.getHeader(), "floppy" + floppyCounter); config.set(header, option); floppyCounter++; } @@ -250,7 +238,7 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce option.put("media", "cdrom"); option.put("file", image); header = new LinkedHashMap<>(); - header.put(DRIVE.getHeader(), "cdrom" + cdromCounter); + header.put(DRIVE.getHeader(), "cdrom" + cdromCounter); config.set(header, option); cdromCounter++; return true; @@ -259,7 +247,7 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce @Override public boolean addCpuCoreCount(int nrOfCores) { option = new TreeMap<>(); - option.put("cpus", nrOfCores+""); + option.put("cpus", nrOfCores + ""); header = new LinkedHashMap<>(); header.put(SMP.getHeader(), null); @@ -269,13 +257,13 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce @Override public void setSoundCard(VmMetaData.SoundCardType type) { - //Not possible will be set as comment in config file + //TODO Not possible will be set as comment in config file } @Override public VmMetaData.SoundCardType getSoundCard() { - //not possible to set just write comment - return null; + //TODO set to default, just write comment + return VmMetaData.SoundCardType.DEFAULT; } @Override @@ -300,33 +288,20 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce @Override public void setEthernetDevType(int cardIndex, VmMetaData.EthernetDevType type) { + //TODO QemuEthernetDevTypeMeta dev = networkCards.get(type); + header = new LinkedHashMap<>(); + header.put(DEVICE.getHeader(), "net" + netdevCounter); option = new TreeMap<>(); - option.put("driver", "\"" + dev.value + "\""); - option.put("netdev", "\"net" + cardIndex + "\""); -// config.set("[device]", option); + option.put("driver", dev.value); + //option.put("netdev", "net" + cardIndex); + config.set(header, option); + netdevCounter++; } @Override public VmMetaData.EthernetDevType getEthernetDevType(int cardIndex) { -// QemuEthernetDevTypeMeta ethernetDevTypeMeta = null; -// for (String key : config.get().keySet()) { -// if (key.equals("[dev" + cardIndex + "]")) {//wont work dev0 -// if (config.get(key).get("netdev").equals("\"net" + cardIndex + "\"")) { -// String devs = config.get(key).get("driver"); -// -// for (EthernetDevType type : VmMetaData.EthernetDevType.values()) { -// ethernetDevTypeMeta = networkCards.get(type); -// if (ethernetDevTypeMeta == null) { -// continue; -// } -// if (devs.equals(ethernetDevTypeMeta.value)) { -// return type; -// } -// } -// } -// } -// } + //TO DO return EthernetDevType.AUTO; } @@ -334,21 +309,19 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce public boolean addEthernet(VmMetaData.EtherType type) { boolean ret = false; int index = 0; + //TODO use existing interface if given or create a new one for (;; ++index) { - DEVICE.setID("dev"+index); + DEVICE.setID("netType" + index); TreeMap<String, String> dev = config.get(DEVICE.getHeader(), DEVICE.getID()); - if (dev == null) { + if (dev == null || dev.get("netdev") == null) { break; - } else { - if (dev.get("netdev") == null) { - break; - } } + } - + switch (type) { - case NAT: + case NAT: ret = addEthernet(index, EthernetType.NAT); break; case BRIDGED: @@ -363,23 +336,25 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce } return ret; } - - public boolean addEthernet(int index, EthernetType type){ - NETDEV.setID("net"+index); + + public boolean addEthernet(int index, EthernetType type) { + NETDEV.setID("net" + index); header = new LinkedHashMap<>(); header.put(NETDEV.getHeader(), NETDEV.getID()); //netdev option = new TreeMap<>(); + //device tap,ifname=nat1 option.put("ifname", type.vmnet); option.put("type", "tap"); config.set(header, option); //device header = new LinkedHashMap<>(); - header.put(DEVICE.getHeader(), ""); + header.put(DEVICE.getHeader(), "netType" + netdevCounter); option = new TreeMap<>(); option.put("driver", "e1000"); option.put("netdev", NETDEV.getID()); config.set(header, option); + netdevCounter++; return true; } @@ -396,7 +371,7 @@ public final class QemuMetaData extends VmMetaData<QemuSoundCardMeta, QemuDDAcce } else { option.put("usb", "off"); } - + header = new LinkedHashMap<>(); header.put(MACHINE.getHeader(), MACHINE.getID()); config.set(header, option); |