Roy Golan has uploaded a new change for review.

Change subject: core: introduce osinfo service instead of Config values
......................................................................

core: introduce osinfo service instead of Config values

osinfo service is a replacement for Config values for items like
minimum RAM of a particular Operating System. It aims to use a system
library which has all that information with its own database and
lifecycle i.e data could be upgraded without specific engine care.

wiki: http://www.ovirt.org/Integrating_libosinfo_with_Ovirt_engine

Change-Id: Ibd75679a1a1af5d5a0925e181b5dfd6e87574a75
Signed-off-by: Roy Golan <rgo...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
R 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidationUtils.java
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/LibosinfoClient.java
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSIdentifiers.java
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoRemoteService.java
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoService.java
6 files changed, 506 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/12936/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
index 68d996a..3c8c143 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
@@ -10,6 +10,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.context.CompensationContext;
 import org.ovirt.engine.core.bll.network.MacPoolManager;
+import org.ovirt.engine.core.bll.validator.VmValidationUtils;
 import org.ovirt.engine.core.common.backendinterfaces.BaseHandler;
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
@@ -33,7 +34,6 @@
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
-import org.ovirt.engine.core.common.utils.VmValidationUtils;
 import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
@@ -342,7 +342,7 @@
         boolean result = VmValidationUtils.isMemorySizeLegal(osType, 
memSizeInMB, clsuter_version);
         if (!result) {
             
reasons.add(VdcBllMessages.ACTION_TYPE_FAILED_ILLEGAL_MEMORY_SIZE.toString());
-            reasons.add(String.format("$minMemorySize %s", 
VmValidationUtils.getMinMemorySizeInMb()));
+            reasons.add(String.format("$minMemorySize %s", 
VmValidationUtils.getMinMemorySizeInMb(osType)));
             reasons.add(String.format("$maxMemorySize %s",
                     VmValidationUtils.getMaxMemorySizeInMb(osType, 
clsuter_version)));
         }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmValidationUtils.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidationUtils.java
similarity index 62%
rename from 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmValidationUtils.java
rename to 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidationUtils.java
index 2f2b8b5..3131887 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmValidationUtils.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmValidationUtils.java
@@ -1,11 +1,15 @@
-package org.ovirt.engine.core.common.utils;
+package org.ovirt.engine.core.bll.validator;
 
 import org.ovirt.engine.core.common.businessentities.VmOsType;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.utils.osinfo.LibosinfoClient;
+import org.ovirt.engine.core.utils.osinfo.OSIdentifiers;
+import org.ovirt.engine.core.utils.osinfo.OSInfoService;
 
 public class VmValidationUtils {
     private static final String X64BIT = "x64";
+    private static OSInfoService osinfoService = LibosinfoClient.getService();
 
     /**
      * Check if the memory size is within the correct limits (as per the 
configuration), taking into account the
@@ -17,16 +21,26 @@
      * @return Is the memory within the configured limits or not.
      */
     public static boolean isMemorySizeLegal(VmOsType osType, int memSizeInMB, 
String clsuter_version) {
-        return memSizeInMB >= getMinMemorySizeInMb() && memSizeInMB <= 
getMaxMemorySizeInMb(osType, clsuter_version);
+        return memSizeInMB >= getMinMemorySizeInMb(osType)
+                && memSizeInMB <= getMaxMemorySizeInMb(osType, 
clsuter_version);
     }
 
     /**
      * Get the configured minimum VM memory size allowed.
      *
+     * @param osType
+     *            The type of OS to get the maximum memory for.
+     *
      * @return The minimum VM memory size allowed (as per configuration).
      */
-    public static Integer getMinMemorySizeInMb() {
-        return Config.<Integer> GetValue(ConfigValues.VMMinMemorySizeInMB);
+    public static Integer getMinMemorySizeInMb(VmOsType osType) {
+        long minimumRam =
+                osinfoService.getMinimumRam(OSIdentifiers.from(osType), 
osType.getIs64Bit() ? "x86_64" : "i386");
+        return (int) (minimumRam == -1 ? -1 : bytesToMegaBytes(minimumRam));
+    }
+
+    private static long bytesToMegaBytes(long value) {
+        return value / (1024 * 1024);
     }
 
     /**
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/LibosinfoClient.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/LibosinfoClient.java
new file mode 100644
index 0000000..760c974
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/LibosinfoClient.java
@@ -0,0 +1,136 @@
+package org.ovirt.engine.core.utils.osinfo;
+
+import java.io.ObjectInputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.ovirt.engine.core.common.businessentities.VmOsType;
+import org.ovirt.engine.core.utils.LocalConfig;
+import org.ovirt.engine.core.utils.log.Log;
+import org.ovirt.engine.core.utils.log.LogFactory;
+
+/**
+ * The RMI client that will launch an external VM which<br>
+ * queries the libosinfo.so over JNA.<br>
+ * <br>
+ * Use {@link LibosinfoClient#getService()} method to get an {@link 
OSInfoService}<br>
+ * instance in hand. <br>
+ *<br>
+ * TODO after we're sure the external VM works fine, no crashes or memory 
leaks <br>
+ * we can inhibit it in the backend and dump the RMI approach when needed.
+ */
+public class LibosinfoClient {
+    private static final LibosinfoClient instance = new LibosinfoClient();
+
+    // We need to save the reference to the external VM so that we can
+    // kill it when finished:
+    private Process libosinfoRMIServer;
+
+    // These are the references to the stub of the remote server and to
+    // the proxy that hides the remoting details:
+    private OSInfoRemoteService stub;
+    private OSInfoService proxy;
+
+    private static final Log log = LogFactory.getLog(LibosinfoClient.class);
+
+    private LibosinfoClient() {
+        addShutdownHookForLibosinfoServerVM();
+        startLibosinfoServerVM();
+        readStubFromServerStdOut();
+        newLibosinfoRMIProxy();
+    }
+
+    public static OSInfoService getService() {
+        return instance.proxy;
+    }
+
+    private void addShutdownHookForLibosinfoServerVM() {
+        // Remember to stop the external VM:
+        Runtime.getRuntime().addShutdownHook(new Thread("External 
LibosinfoServer VM killer") {
+            public void run() {
+                if (libosinfoRMIServer != null) {
+                    libosinfoRMIServer.destroy();
+                }
+            }
+        });
+    }
+
+    private void startLibosinfoServerVM() {
+        // Run a new java virtual machine:
+        try {
+            // ProcessBuilder builder = buildShellProcessCmd();
+            ProcessBuilder builder = buildExternalJavaProcessCmd();
+
+            // good for error handling problems. all errors of the remote VM 
are
+            // redirected to the current stream
+            builder.redirectErrorStream(true);
+
+            libosinfoRMIServer = builder.start();
+
+        } catch (Exception exception) {
+            System.out.println("Can't start exernal VM.");
+        }
+    }
+
+    private ProcessBuilder buildExternalJavaProcessCmd() {
+        ProcessBuilder builder = new ProcessBuilder();
+        String java = System.getProperty("java.home") + "/bin/java";
+
+        String engineEarLib = LocalConfig.getInstance().getUsrDir().getPath() 
+ "/engine.ear/lib/"; // base engine.ear
+                                                                               
                     // folder
+        String classpath =
+                engineEarLib + "tools.jar" + ":" +
+                        engineEarLib + "utils.jar" +
+                        ":/usr/share/java/jna.jar";
+
+        String options = "-Djava.rmi.server.hostname=localhost";
+        String mainClassName = 
"org.ovirt.engine.core.osinfo.server.LibosinfoServer";
+
+        builder.command(java, "-cp", classpath, options, mainClassName);
+        return builder;
+    }
+
+    private ProcessBuilder buildShellProcessCmd() {
+        ProcessBuilder builder = new ProcessBuilder();
+        String cmd = LocalConfig.getInstance().getUsrDir().getPath() + 
"/bin/engine-libosinfo-server.sh/";
+        return builder.command(cmd);
+    }
+
+    private void newLibosinfoRMIProxy() {
+        // Create a proxy that hides the remote exceptions:
+        proxy = (OSInfoService) Proxy.newProxyInstance(
+                Thread.currentThread().getContextClassLoader(),
+                new Class<?>[] { OSInfoService.class },
+                new InvocationHandler() {
+                    @Override
+                    public Object invoke(final Object proxy, final Method 
method, final Object[] args) throws Throwable {
+                        // Find the same method in the target, as the only 
difference is
+                        // that the target method can throw remote exceptions:
+                        final Method stubMethod =
+                                stub.getClass().getMethod(method.getName(), 
method.getParameterTypes());
+
+                        // Invoke the remote method (here we could retry, or 
restart the external VM
+                        // if something fails:
+                        return stubMethod.invoke(stub, args);
+                    }
+                }
+                );
+    }
+
+    private void readStubFromServerStdOut() {
+        // Read and deserialize the stub from the output of the VM:
+        try {
+            ObjectInputStream in = new 
ObjectInputStream(libosinfoRMIServer.getInputStream());
+            stub = (OSInfoRemoteService) in.readObject();
+        } catch (Exception exception) {
+            log.error("Can't deserialize server stub.");
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        OSInfoService client = LibosinfoClient.getService();
+        
System.out.println(client.getMinimumNumberOfCpus(OSIdentifiers.from(VmOsType.Windows2008),
 "x86_64"));
+
+    }
+}
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSIdentifiers.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSIdentifiers.java
new file mode 100644
index 0000000..45e7008
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSIdentifiers.java
@@ -0,0 +1,286 @@
+package org.ovirt.engine.core.utils.osinfo;
+
+import static org.ovirt.engine.core.common.businessentities.VmOsType.*;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.VmOsType;
+
+public enum OSIdentifiers {
+    CentOS_6_0("http://centos.org/centos/6.0";),
+    CentOS_6_1("http://centos.org/centos/6.1";),
+    Debian_Bo("http://debian.org/debian/1.3";),
+    Debian_Buzz("http://debian.org/debian/1.0";),
+    Debian_Etch("http://debian.org/debian/4";),
+    Debian_Hamm("http://debian.org/debian/2.0";),
+    Debian_Lenny("http://debian.org/debian/5";),
+    Debian_Potato("http://debian.org/debian/2.2";),
+    Debian_Rex("http://debian.org/debian/1.2";),
+    Debian_Sarge("http://debian.org/debian/3.1";),
+    Debian_Silnk("http://debian.org/debian/2.1";),
+    Debian_Squeeze("http://debian.org/debian/6";),
+    Debian_Woody("http://debian.org/debian/3";),
+    Fedora_10("http://fedoraproject.org/fedora/10";),
+    Fedora_11("http://fedoraproject.org/fedora/11";),
+    Fedora_12("http://fedoraproject.org/fedora/12";),
+    Fedora_13("http://fedoraproject.org/fedora/13";),
+    Fedora_14("http://fedoraproject.org/fedora/14";),
+    Fedora_15("http://fedoraproject.org/fedora/15";),
+    Fedora_16("http://fedoraproject.org/fedora/16";),
+    Fedora_17("http://fedoraproject.org/fedora/17";),
+    Fedora_7("http://fedoraproject.org/fedora/7";),
+    Fedora_8("http://fedoraproject.org/fedora/8";),
+    Fedora_9("http://fedoraproject.org/fedora/9";),
+    Fedora_Core_1("http://fedoraproject.org/fedora/1";),
+    Fedora_Core_2("http://fedoraproject.org/fedora/2";),
+    Fedora_Core_3("http://fedoraproject.org/fedora/3";),
+    Fedora_Core_4("http://fedoraproject.org/fedora/4";),
+    Fedora_Core_5("http://fedoraproject.org/fedora/5";),
+    Fedora_Core_6("http://fedoraproject.org/fedora/6";),
+    FreeBSD_1_0("http://freebsd.org/freebsd/1.0";),
+    FreeBSD_2_0("http://freebsd.org/freebsd/2.0";),
+    FreeBSD_2_0_5("http://freebsd.org/freebsd/2.0.5";),
+    FreeBSD_2_2_8("http://freebsd.org/freebsd/2.2.8";),
+    FreeBSD_2_2_9("http://freebsd.org/freebsd/2.2.9";),
+    FreeBSD_3_0("http://freebsd.org/freebsd/3.0";),
+    FreeBSD_3_2("http://freebsd.org/freebsd/3.2";),
+    FreeBSD_4_0("http://freebsd.org/freebsd/4.0";),
+    FreeBSD_4_1("http://freebsd.org/freebsd/4.1";),
+    FreeBSD_4_10("http://freebsd.org/freebsd/4.10";),
+    FreeBSD_4_11("http://freebsd.org/freebsd/4.11";),
+    FreeBSD_4_2("http://freebsd.org/freebsd/4.2";),
+    FreeBSD_4_3("http://freebsd.org/freebsd/4.3";),
+    FreeBSD_4_4("http://freebsd.org/freebsd/4.4";),
+    FreeBSD_4_5("http://freebsd.org/freebsd/4.5";),
+    FreeBSD_4_6("http://freebsd.org/freebsd/4.6";),
+    FreeBSD_4_7("http://freebsd.org/freebsd/4.7";),
+    FreeBSD_4_8("http://freebsd.org/freebsd/4.8";),
+    FreeBSD_4_9("http://freebsd.org/freebsd/4.9";),
+    FreeBSD_5_0("http://freebsd.org/freebsd/5.0";),
+    FreeBSD_5_1("http://freebsd.org/freebsd/5.1";),
+    FreeBSD_5_2("http://freebsd.org/freebsd/5.2";),
+    FreeBSD_5_2_1("http://freebsd.org/freebsd/5.2.1";),
+    FreeBSD_5_3("http://freebsd.org/freebsd/5.3";),
+    FreeBSD_5_4("http://freebsd.org/freebsd/5.4";),
+    FreeBSD_5_5("http://freebsd.org/freebsd/5.5";),
+    FreeBSD_6_0("http://freebsd.org/freebsd/6.0";),
+    FreeBSD_6_1("http://freebsd.org/freebsd/6.1";),
+    FreeBSD_6_2("http://freebsd.org/freebsd/6.2";),
+    FreeBSD_6_3("http://freebsd.org/freebsd/6.3";),
+    FreeBSD_6_4("http://freebsd.org/freebsd/6.4";),
+    FreeBSD_7_0("http://freebsd.org/freebsd/7.0";),
+    FreeBSD_7_1("http://freebsd.org/freebsd/7.1";),
+    FreeBSD_7_2("http://freebsd.org/freebsd/7.2";),
+    FreeBSD_7_3("http://freebsd.org/freebsd/7.3";),
+    FreeBSD_7_4("http://freebsd.org/freebsd/7.4";),
+    FreeBSD_8_0("http://freebsd.org/freebsd/8.0";),
+    FreeBSD_8_1("http://freebsd.org/freebsd/8.1";),
+    FreeBSD_8_2("http://freebsd.org/freebsd/8.2";),
+    FreeBSD_9_0("http://freebsd.org/freebsd/9.0";),
+    Mandrake_Linux_10_0("http://mandriva.com/mandrake/10.0";),
+    Mandrake_Linux_10_1("http://mandriva.com/mandrake/10.1";),
+    Mandrake_Linux_10_2("http://mandriva.com/mandrake/10.2";),
+    Mandrake_Linux_5_1("http://mandriva.com/mandrake/5.1";),
+    Mandrake_Linux_5_2("http://mandriva.com/mandrake/5.2";),
+    Mandrake_Linux_5_3("http://mandriva.com/mandrake/5.3";),
+    Mandrake_Linux_6_0("http://mandriva.com/mandrake/6.0";),
+    Mandrake_Linux_6_1("http://mandriva.com/mandrake/6.1";),
+    Mandrake_Linux_7_0("http://mandriva.com/mandrake/7.0";),
+    Mandrake_Linux_7_1("http://mandriva.com/mandrake/7.1";),
+    Mandrake_Linux_7_2("http://mandriva.com/mandrake/7.2";),
+    Mandrake_Linux_8_0("http://mandriva.com/mandrake/8.0";),
+    Mandrake_Linux_8_1("http://mandriva.com/mandrake/8.1";),
+    Mandrake_Linux_8_2("http://mandriva.com/mandrake/8.2";),
+    Mandrake_Linux_9_0("http://mandriva.com/mandrake/9.0";),
+    Mandrake_Linux_9_1("http://mandriva.com/mandrake/9.1";),
+    Mandrake_Linux_9_2("http://mandriva.com/mandrake/9.2";),
+    Mandriva_Enterprise_Server_5_0("http://mandriva.com/mes/5.0";),
+    Mandriva_Enterprise_Server_5_1("http://mandriva.com/mes/5.1";),
+    Mandriva_Linux_2006_0("http://mandriva.com/mandriva/2006.0";),
+    Mandriva_Linux_2007("http://mandriva.com/mandriva/2007";),
+    Mandriva_Linux_2007_Spring("http://mandriva.com/mandriva/2007.1";),
+    Mandriva_Linux_2008("http://mandriva.com/mandriva/2008.0";),
+    Mandriva_Linux_2008_Spring("http://mandriva.com/mandriva/2008.1";),
+    Mandriva_Linux_2009("http://mandriva.com/mandriva/2009.0";),
+    Mandriva_Linux_2009_Spring("http://mandriva.com/mandriva/2009.1";),
+    Mandriva_Linux_2010("http://mandriva.com/mandriva/2010.0";),
+    Mandriva_Linux_2010_2("http://mandriva.com/mandriva/2010.2";),
+    Mandriva_Linux_2010_Spring("http://mandriva.com/mandriva/2010.1";),
+    Mandriva_Linux_2011("http://mandriva.com/mandriva/2011";),
+    Microsoft_MS_DOS_6_22("http://microsoft.com/msdos/6.22";),
+    Microsoft_Windows_1_0("http://microsoft.com/win/1.0";),
+    Microsoft_Windows_2000("http://microsoft.com/win/2k";),
+    Microsoft_Windows_2_0("http://microsoft.com/win/2.0";),
+    Microsoft_Windows_2_1("http://microsoft.com/win/2.1";),
+    Microsoft_Windows_3_1("http://microsoft.com/win/3.1";),
+    Microsoft_Windows_7("http://microsoft.com/win/7";, Windows7, Windows7x64),
+    Microsoft_Windows_8("http://microsoft.com/win/8";, Windows8, 
Windows2008x64),
+    Microsoft_Windows_95("http://microsoft.com/win/95";),
+    Microsoft_Windows_98("http://microsoft.com/win/98";),
+    Microsoft_Windows_Millennium_Edition("http://microsoft.com/win/me";),
+    Microsoft_Windows_NT_Server_3_1("http://microsoft.com/winnt/3.1";),
+    Microsoft_Windows_NT_Server_3_5("http://microsoft.com/winnt/3.5";),
+    Microsoft_Windows_NT_Server_3_51("http://microsoft.com/winnt/3.51";),
+    Microsoft_Windows_NT_Server_4_0("http://microsoft.com/winnt/4.0";),
+    Microsoft_Windows_Server_2003("http://microsoft.com/win/2k3";, Windows2003, 
Windows2003x64),
+    Microsoft_Windows_Server_2003_R2("http://microsoft.com/win/2k3r2";, 
Windows2003, Windows2003x64),
+    Microsoft_Windows_Server_2008("http://microsoft.com/win/2k8";, Windows2008),
+    Microsoft_Windows_Server_2008_R2("http://microsoft.com/win/2k8r2";, 
Windows2008R2x64),
+    Microsoft_Windows_Vista("http://microsoft.com/win/vista";),
+    Microsoft_Windows_XP("http://microsoft.com/win/xp";, WindowsXP),
+    NetBSD_0_8("http://netbsd.org/netbsd/0.8";),
+    NetBSD_0_9("http://netbsd.org/netbsd/0.9";),
+    NetBSD_1_0("http://netbsd.org/netbsd/1.0";),
+    NetBSD_1_1("http://netbsd.org/netbsd/1.1";),
+    NetBSD_1_2("http://netbsd.org/netbsd/1.2";),
+    NetBSD_1_3("http://netbsd.org/netbsd/1.3";),
+    NetBSD_1_4("http://netbsd.org/netbsd/1.4";),
+    NetBSD_1_5("http://netbsd.org/netbsd/1.5";),
+    NetBSD_1_6("http://netbsd.org/netbsd/1.6";),
+    NetBSD_2_0("http://netbsd.org/netbsd/2.0";),
+    NetBSD_3_0("http://netbsd.org/netbsd/3.0";),
+    NetBSD_4_0("http://netbsd.org/netbsd/4.0";),
+    NetBSD_5_0("http://netbsd.org/netbsd/5.0";),
+    NetBSD_5_1("http://netbsd.org/netbsd/5.1";),
+    Novell_Netware_4("http://novell.com/netware4";),
+    Novell_Netware_5("http://novell.com/netware5";),
+    Novell_Netware_6("http://novell.com/netware6";),
+    OpenBSD_4_2("http://openbsd.org/openbsd/4.2";),
+    OpenBSD_4_3("http://openbsd.org/openbsd/4.3";),
+    OpenBSD_4_4("http://openbsd.org/openbsd/4.4";),
+    OpenBSD_4_5("http://openbsd.org/openbsd/4.5";),
+    OpenBSD_4_8("http://openbsd.org/openbsd/4.8";),
+    OpenBSD_4_9("http://openbsd.org/openbsd/4.9";),
+    OpenBSD_5_0("http://openbsd.org/openbsd/5.0";),
+    Red_Hat_Enterprise_Linux_2_1("http://redhat.com/rhel/2.1";),
+    Red_Hat_Enterprise_Linux_2_1_Update_1("http://redhat.com/rhel/2.1.1";),
+    Red_Hat_Enterprise_Linux_2_1_Update_2("http://redhat.com/rhel/2.1.2";),
+    Red_Hat_Enterprise_Linux_2_1_Update_3("http://redhat.com/rhel/2.1.3";),
+    Red_Hat_Enterprise_Linux_2_1_Update_4("http://redhat.com/rhel/2.1.4";),
+    Red_Hat_Enterprise_Linux_2_1_Update_5("http://redhat.com/rhel/2.1.5";),
+    Red_Hat_Enterprise_Linux_2_1_Update_6("http://redhat.com/rhel/2.1.6";),
+    Red_Hat_Enterprise_Linux_2_1_Update_7("http://redhat.com/rhel/2.1.7";),
+    Red_Hat_Enterprise_Linux_3("http://redhat.com/rhel/3";, RHEL3, RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_1("http://redhat.com/rhel/3.1";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_2("http://redhat.com/rhel/3.2";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_3("http://redhat.com/rhel/3.3";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_4("http://redhat.com/rhel/3.4";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_5("http://redhat.com/rhel/3.5";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_6("http://redhat.com/rhel/3.6";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_7("http://redhat.com/rhel/3.7";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_8("http://redhat.com/rhel/3.8";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_3_Update_9("http://redhat.com/rhel/3.9";, RHEL3, 
RHEL3x64),
+    Red_Hat_Enterprise_Linux_4_0("http://redhat.com/rhel/4.0";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_1("http://redhat.com/rhel/4.1";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_2("http://redhat.com/rhel/4.2";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_3("http://redhat.com/rhel/4.3";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_4("http://redhat.com/rhel/4.4";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_5("http://redhat.com/rhel/4.5";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_6("http://redhat.com/rhel/4.6";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_7("http://redhat.com/rhel/4.7";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_8("http://redhat.com/rhel/4.8";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_4_9("http://redhat.com/rhel/4.9";, RHEL4, 
RHEL4x64),
+    Red_Hat_Enterprise_Linux_5_0("http://redhat.com/rhel/5.0";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_1("http://redhat.com/rhel/5.1";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_2("http://redhat.com/rhel/5.2";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_3("http://redhat.com/rhel/5.3";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_4("http://redhat.com/rhel/5.4";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_5("http://redhat.com/rhel/5.5";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_6("http://redhat.com/rhel/5.6";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_7("http://redhat.com/rhel/5.7";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_5_8("http://redhat.com/rhel/5.8";, RHEL5, 
RHEL5x64),
+    Red_Hat_Enterprise_Linux_6_0("http://redhat.com/rhel/6.0";, RHEL6, 
RHEL6x64),
+    Red_Hat_Enterprise_Linux_6_1("http://redhat.com/rhel/6.1";, RHEL6, 
RHEL6x64),
+    Red_Hat_Enterprise_Linux_6_2("http://redhat.com/rhel/6.2";, RHEL6, 
RHEL6x64),
+    Red_Hat_Linux_1_0("http://redhat.com/rhl/1.0";),
+    Red_Hat_Linux_1_1("http://redhat.com/rhl/1.1";),
+    Red_Hat_Linux_2_0("http://redhat.com/rhl/2.0";),
+    Red_Hat_Linux_2_1("http://redhat.com/rhl/2.1";),
+    Red_Hat_Linux_3_0_3("http://redhat.com/rhl/3.0.3";),
+    Red_Hat_Linux_4_0("http://redhat.com/rhl/4.0";),
+    Red_Hat_Linux_4_1("http://redhat.com/rhl/4.1";),
+    Red_Hat_Linux_4_2("http://redhat.com/rhl/4.2";),
+    Red_Hat_Linux_5_0("http://redhat.com/rhl/5.0";),
+    Red_Hat_Linux_5_1("http://redhat.com/rhl/5.1";),
+    Red_Hat_Linux_5_2("http://redhat.com/rhl/5.2";),
+    Red_Hat_Linux_6_0("http://redhat.com/rhl/6.0";),
+    Red_Hat_Linux_6_1("http://redhat.com/rhl/6.1";),
+    Red_Hat_Linux_6_2("http://redhat.com/rhl/6.2";),
+    Red_Hat_Linux_7("http://redhat.com/rhl/7";),
+    Red_Hat_Linux_7_1("http://redhat.com/rhl/7.1";),
+    Red_Hat_Linux_7_2("http://redhat.com/rhl/7.2";),
+    Red_Hat_Linux_7_3("http://redhat.com/rhl/7.3";),
+    Red_Hat_Linux_8_0("http://redhat.com/rhl/8.0";),
+    Red_Hat_Linux_9("http://redhat.com/rhl/9";),
+    Sun_OpenSolaris_2009_06("http://oracle.com/opensolaris/2009.06";),
+    Sun_Solaris_10("http://sun.com/solaris/10";),
+    Sun_Solaris_9("http://sun.com/solaris/9";),
+    Suse_Linux_Enterprise_Desktop_10("http://suse.com/sled/10";),
+    Suse_Linux_Enterprise_Desktop_11("http://suse.com/sled/11";),
+    Suse_Linux_Enterprise_Desktop_9("http://suse.com/sled/9";),
+    Suse_Linux_Enterprise_Server_10("http://suse.com/sles/10";),
+    Suse_Linux_Enterprise_Server_11("http://suse.com/sles/11";),
+    Suse_Linux_Enterprise_Server_9("http://suse.com/sles/9";),
+    Ubuntu_Breezy_Badger("http://ubuntu.com/ubuntu/5.10";),
+    Ubuntu_Dapper_Drake_LTS("http://ubuntu.com/ubuntu/6.06";),
+    Ubuntu_Edgy_Eft("http://ubuntu.com/ubuntu/6.10";),
+    Ubuntu_Feisty_Fawn("http://ubuntu.com/ubuntu/7.04";),
+    Ubuntu_Gutsy_Gibbon("http://ubuntu.com/ubuntu/7.10";),
+    Ubuntu_Hardy_Heron_LTS("http://ubuntu.com/ubuntu/8.04";),
+    Ubuntu_Hoary_Hedgehog("http://ubuntu.com/ubuntu/5.04";),
+    Ubuntu_Intrepid_Ibex("http://ubuntu.com/ubuntu/8.10";),
+    Ubuntu_Jaunty_Jackalope("http://ubuntu.com/ubuntu/9.04";),
+    Ubuntu_Karmic_Koala("http://ubuntu.com/ubuntu/9.10";),
+    Ubuntu_Lucid_Lynx_LTS("http://ubuntu.com/ubuntu/10.04";),
+    Ubuntu_Maverick_Meerkat("http://ubuntu.com/ubuntu/10.10";),
+    Ubuntu_Natty_Narwhal("http://ubuntu.com/ubuntu/11.04";),
+    Ubuntu_Oneiric_Ocelot("http://ubuntu.com/ubuntu/11.10";),
+    Ubuntu_Precise_Pangolin_LTS("http://ubuntu.com/ubuntu/12.04";),
+    Ubuntu_Warty_Warthog("http://ubuntu.com/ubuntu/4.10";),
+    openSUSE_10_2("http://opensuse.org/opensuse/10.2";),
+    openSUSE_10_3("http://opensuse.org/opensuse/10.3";),
+    openSUSE_11_0("http://opensuse.org/opensuse/11.0";),
+    openSUSE_11_1("http://opensuse.org/opensuse/11.1";),
+    openSUSE_11_2("http://opensuse.org/opensuse/11.2";),
+    openSUSE_11_3("http://opensuse.org/opensuse/11.3";),
+    openSUSE_11_4("http://opensuse.org/opensuse/11.4";),
+    openSUSE_12_1("http://opensuse.org/opensuse/12.1";),
+    ;
+    private String id;
+    private List<VmOsType> osTypes;
+
+    private static Map<VmOsType, OSIdentifiers> osTypeLookup =
+            new HashMap<VmOsType, OSIdentifiers>();
+
+    static {
+        for (OSIdentifiers member : values()) {
+            if (!member.osTypes.contains(VmOsType.Other)) {
+                for (VmOsType osType : member.osTypes) {
+                    osTypeLookup.put(osType, member);
+                }
+            }
+        }
+    }
+
+    private OSIdentifiers(String id) {
+        this.id = id;
+        this.osTypes = Arrays.asList(new VmOsType[] { VmOsType.Other });
+    }
+
+    private OSIdentifiers(String id, VmOsType... osType) {
+        this.id = id;
+        this.osTypes = Arrays.asList(osType);
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public static String from(VmOsType osType) {
+        return osTypeLookup.get(osType).getId();
+    }
+
+}
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoRemoteService.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoRemoteService.java
new file mode 100644
index 0000000..d4bd65b
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoRemoteService.java
@@ -0,0 +1,16 @@
+package org.ovirt.engine.core.utils.osinfo;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface OSInfoRemoteService extends Remote {
+
+    int getMinimumNumberOfCpus(String osId, String cpuArch) throws 
RemoteException;
+
+    int getRecommendedNumberOfCpus(String osId, String cpuArch) throws 
RemoteException;
+
+    long getMinimumRam(String osId, String cpuArch) throws RemoteException;
+
+    long getRecommendedRam(String osId, String cpuArch) throws RemoteException;
+
+}
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoService.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoService.java
new file mode 100644
index 0000000..c2102bb
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OSInfoService.java
@@ -0,0 +1,48 @@
+package org.ovirt.engine.core.utils.osinfo;
+
+
+public interface OSInfoService {
+
+    /**
+     *
+     * @param osId
+     *            A Unique OS type identifier. See {@link OSIdentifiers}
+     * @param cpuArch
+     *            representing 32, 64, and ppc cpu architecture. <br>
+     *
+     * @return the minimum number of CPUs, or -1
+     */
+    public int getMinimumNumberOfCpus(String osId, String cpuArch);
+
+    /**
+     *
+     * @param osId
+     *            A Unique OS type identifier. See {@link OSIdentifiers}
+     * @param cpuArch
+     *            representing 32, 64, and ppc cpu architecture. <br>
+     *
+     * @return the recommended number of CPUs, or -1
+     */
+    public int getRecommendedNumberOfCpus(String osId, String cpuArch);
+
+    /**
+     *
+     * @param osId
+     *            A Unique OS type identifier. See {@link OSIdentifiers}
+     * @param cpuArch
+     *            representing 32, 64, and ppc cpu architecture. <br>
+     *
+     * @return the minimum RAM in bytes for the matching os and cpu 
architecture, or -1
+     */
+    public long getMinimumRam(String osId, String cpuArch);
+
+    /**
+     * @param osId
+     *            A Unique OS type identifier. See {@link OSIdentifiers}
+     * @param cpuArch
+     *            representing 32, 64, and ppc cpu architecture. <br>
+     * @return the minimum RAM in bytes for the matching os and cpu 
architecture, or -1
+     */
+    public long getRecommendedRam(String osId, String cpuArch);
+
+}


--
To view, visit http://gerrit.ovirt.org/12936
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd75679a1a1af5d5a0925e181b5dfd6e87574a75
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to