mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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
This commit is contained in:
@@ -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." };
|
||||
|
||||
]
|
||||
|
||||
@@ -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 \
|
||||
|
||||
75
lib/inspect-osinfo.c
Normal file
75
lib/inspect-osinfo.c
Normal file
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user