|
|
d0ea73 |
From 24aef5baa9725e26efd37fa78b83f98629d77eba Mon Sep 17 00:00:00 2001
|
|
|
d0ea73 |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
d0ea73 |
Date: Wed, 21 Feb 2018 17:33:28 +0100
|
|
|
d0ea73 |
Subject: [PATCH] New API: inspect_get_osinfo
|
|
|
d0ea73 |
|
|
|
d0ea73 |
Try to guess the possible osinfo-db short ID for the specified OS.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1544842
|
|
|
d0ea73 |
|
|
|
d0ea73 |
(cherry picked from commit 286b88891c2288fb7f64c9538296599ece04bcb1)
|
|
|
d0ea73 |
---
|
|
|
d0ea73 |
generator/actions_inspection.ml | 14 ++++++
|
|
|
d0ea73 |
lib/Makefile.am | 1 +
|
|
|
d0ea73 |
lib/inspect-osinfo.c | 75 +++++++++++++++++++++++++++++++++
|
|
|
d0ea73 |
3 files changed, 90 insertions(+)
|
|
|
d0ea73 |
create mode 100644 lib/inspect-osinfo.c
|
|
|
d0ea73 |
|
|
|
d0ea73 |
diff --git a/generator/actions_inspection.ml b/generator/actions_inspection.ml
|
|
|
d0ea73 |
index 0ac282435..ff5083114 100644
|
|
|
d0ea73 |
--- a/generator/actions_inspection.ml
|
|
|
d0ea73 |
+++ b/generator/actions_inspection.ml
|
|
|
d0ea73 |
@@ -770,4 +770,18 @@ advice before using trademarks in applications.
|
|
|
d0ea73 |
|
|
|
d0ea73 |
=back" };
|
|
|
d0ea73 |
|
|
|
d0ea73 |
+ { defaults with
|
|
|
d0ea73 |
+ name = "inspect_get_osinfo"; added = (1, 39, 1);
|
|
|
d0ea73 |
+ style = RString (RPlainString, "id"), [String (Mountable, "root")], [];
|
|
|
d0ea73 |
+ shortdesc = "get a possible osinfo short ID corresponding to this operating system";
|
|
|
d0ea73 |
+ longdesc = "\
|
|
|
d0ea73 |
+This function returns a possible short ID for libosinfo corresponding
|
|
|
d0ea73 |
+to the guest.
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+I<Note:> The returned ID is only a guess by libguestfs, and nothing
|
|
|
d0ea73 |
+ensures that it actually exists in osinfo-db.
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+If no ID could not be determined, then the string C<unknown> is
|
|
|
d0ea73 |
+returned." };
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
]
|
|
|
d0ea73 |
diff --git a/lib/Makefile.am b/lib/Makefile.am
|
|
|
d0ea73 |
index d075174d9..742b182cc 100644
|
|
|
d0ea73 |
--- a/lib/Makefile.am
|
|
|
d0ea73 |
+++ b/lib/Makefile.am
|
|
|
d0ea73 |
@@ -95,6 +95,7 @@ libguestfs_la_SOURCES = \
|
|
|
d0ea73 |
info.c \
|
|
|
d0ea73 |
inspect-apps.c \
|
|
|
d0ea73 |
inspect-icon.c \
|
|
|
d0ea73 |
+ inspect-osinfo.c \
|
|
|
d0ea73 |
journal.c \
|
|
|
d0ea73 |
launch.c \
|
|
|
d0ea73 |
launch-direct.c \
|
|
|
d0ea73 |
diff --git a/lib/inspect-osinfo.c b/lib/inspect-osinfo.c
|
|
|
d0ea73 |
new file mode 100644
|
|
|
d0ea73 |
index 000000000..816d317f1
|
|
|
d0ea73 |
--- /dev/null
|
|
|
d0ea73 |
+++ b/lib/inspect-osinfo.c
|
|
|
d0ea73 |
@@ -0,0 +1,75 @@
|
|
|
d0ea73 |
+/* libguestfs
|
|
|
d0ea73 |
+ * Copyright (C) 2018 Red Hat Inc.
|
|
|
d0ea73 |
+ *
|
|
|
d0ea73 |
+ * This library is free software; you can redistribute it and/or
|
|
|
d0ea73 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
d0ea73 |
+ * License as published by the Free Software Foundation; either
|
|
|
d0ea73 |
+ * version 2 of the License, or (at your option) any later version.
|
|
|
d0ea73 |
+ *
|
|
|
d0ea73 |
+ * This library is distributed in the hope that it will be useful,
|
|
|
d0ea73 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d0ea73 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d0ea73 |
+ * Lesser General Public License for more details.
|
|
|
d0ea73 |
+ *
|
|
|
d0ea73 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
d0ea73 |
+ * License along with this library; if not, write to the Free Software
|
|
|
d0ea73 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
d0ea73 |
+ */
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+#include <config.h>
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+#include "guestfs.h"
|
|
|
d0ea73 |
+#include "guestfs-internal.h"
|
|
|
d0ea73 |
+#include "guestfs-internal-actions.h"
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+char *
|
|
|
d0ea73 |
+guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root)
|
|
|
d0ea73 |
+{
|
|
|
d0ea73 |
+ CLEANUP_FREE char *type = NULL;
|
|
|
d0ea73 |
+ CLEANUP_FREE char *distro = NULL;
|
|
|
d0ea73 |
+ int major, minor;
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+ type = guestfs_inspect_get_type (g, root);
|
|
|
d0ea73 |
+ if (!type)
|
|
|
d0ea73 |
+ return NULL;
|
|
|
d0ea73 |
+ distro = guestfs_inspect_get_distro (g, root);
|
|
|
d0ea73 |
+ if (!distro)
|
|
|
d0ea73 |
+ return NULL;
|
|
|
d0ea73 |
+ major = guestfs_inspect_get_major_version (g, root);
|
|
|
d0ea73 |
+ minor = guestfs_inspect_get_minor_version (g, root);
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+ if (STREQ (type, "linux")) {
|
|
|
d0ea73 |
+ if (STREQ (distro, "centos")) {
|
|
|
d0ea73 |
+ if (major >= 7)
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d.0", distro, major);
|
|
|
d0ea73 |
+ else if (major == 6)
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d.%d", distro, major, minor);
|
|
|
d0ea73 |
+ }
|
|
|
d0ea73 |
+ else if (STREQ (distro, "debian")) {
|
|
|
d0ea73 |
+ if (major >= 4)
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d", distro, major);
|
|
|
d0ea73 |
+ }
|
|
|
d0ea73 |
+ else if (STREQ (distro, "fedora") || STREQ (distro, "mageia"))
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d", distro, major);
|
|
|
d0ea73 |
+ else if (STREQ (distro, "sles")) {
|
|
|
d0ea73 |
+ if (minor == 0)
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d", distro, major);
|
|
|
d0ea73 |
+ else
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%dsp%d", distro, major, minor);
|
|
|
d0ea73 |
+ }
|
|
|
d0ea73 |
+ else if (STREQ (distro, "ubuntu"))
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d.%02d", distro, major, minor);
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+ if (major > 0 || minor > 0)
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d.%d", distro, major, minor);
|
|
|
d0ea73 |
+ }
|
|
|
d0ea73 |
+ else if (STREQ (type, "freebsd") || STREQ (type, "netbsd") || STREQ (type, "openbsd"))
|
|
|
d0ea73 |
+ return safe_asprintf (g, "%s%d.%d", distro, major, minor);
|
|
|
d0ea73 |
+ else if (STREQ (type, "dos")) {
|
|
|
d0ea73 |
+ if (STREQ (distro, "msdos"))
|
|
|
d0ea73 |
+ return safe_strdup (g, "msdos6.22");
|
|
|
d0ea73 |
+ }
|
|
|
d0ea73 |
+
|
|
|
d0ea73 |
+ /* No ID could be guessed, return "unknown". */
|
|
|
d0ea73 |
+ return safe_strdup (g, "unknown");
|
|
|
d0ea73 |
+}
|
|
|
d0ea73 |
--
|
|
|
6b9fda |
2.21.0
|
|
|
d0ea73 |
|