Permalink
Browse files

New API: inspect_get_osinfo

Try to guess the possible osinfo-db short ID for the specified OS.

Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1544842
  • Loading branch information...
ptoscano committed Feb 21, 2018
1 parent 9e83f3a commit 286b88891c2288fb7f64c9538296599ece04bcb1
Showing with 90 additions and 0 deletions.
  1. +14 −0 generator/actions_inspection.ml
  2. +1 −0 lib/Makefile.am
  3. +75 −0 lib/inspect-osinfo.c
@@ -774,4 +774,18 @@ advice before using trademarks in applications.
=back" };
{ defaults with
name = "inspect_get_osinfo"; added = (1, 39, 1);
style = RString (RPlainString, "id"), [String (Mountable, "root")], [];
shortdesc = "get a possible osinfo short ID corresponding to this operating system";
longdesc = "\
This function returns a possible short ID for libosinfo corresponding
to the guest.
I<Note:> The returned ID is only a guess by libguestfs, and nothing
ensures that it actually exists in osinfo-db.
If no ID could not be determined, then the string C<unknown> is
returned." };
]
View
@@ -95,6 +95,7 @@ libguestfs_la_SOURCES = \
info.c \
inspect-apps.c \
inspect-icon.c \
inspect-osinfo.c \
journal.c \
launch.c \
launch-direct.c \
View
@@ -0,0 +1,75 @@
/* libguestfs
* Copyright (C) 2018 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include "guestfs.h"
#include "guestfs-internal.h"
#include "guestfs-internal-actions.h"
char *
guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root)
{
CLEANUP_FREE char *type = NULL;
CLEANUP_FREE char *distro = NULL;
int major, minor;
type = guestfs_inspect_get_type (g, root);
if (!type)
return NULL;
distro = guestfs_inspect_get_distro (g, root);
if (!distro)
return NULL;
major = guestfs_inspect_get_major_version (g, root);
minor = guestfs_inspect_get_minor_version (g, root);
if (STREQ (type, "linux")) {
if (STREQ (distro, "centos")) {
if (major >= 7)
return safe_asprintf (g, "%s%d.0", distro, major);
else if (major == 6)
return safe_asprintf (g, "%s%d.%d", distro, major, minor);
}
else if (STREQ (distro, "debian")) {
if (major >= 4)
return safe_asprintf (g, "%s%d", distro, major);
}
else if (STREQ (distro, "fedora") || STREQ (distro, "mageia"))
return safe_asprintf (g, "%s%d", distro, major);
else if (STREQ (distro, "sles")) {
if (minor == 0)
return safe_asprintf (g, "%s%d", distro, major);
else
return safe_asprintf (g, "%s%dsp%d", distro, major, minor);
}
else if (STREQ (distro, "ubuntu"))
return safe_asprintf (g, "%s%d.%02d", distro, major, minor);
if (major > 0 || minor > 0)
return safe_asprintf (g, "%s%d.%d", distro, major, minor);
}
else if (STREQ (type, "freebsd") || STREQ (type, "netbsd") || STREQ (type, "openbsd"))
return safe_asprintf (g, "%s%d.%d", distro, major, minor);
else if (STREQ (type, "dos")) {
if (STREQ (distro, "msdos"))
return safe_strdup (g, "msdos6.22");
}
/* No ID could be guessed, return "unknown". */
return safe_strdup (g, "unknown");
}

0 comments on commit 286b888

Please sign in to comment.