summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-sysinfo.c
blob: 8252b4529586329fe99da95c06f04dfe50dbf281 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 *  Copyright (C) 2013 IBM Corporation
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif

#include <string.h>

#include <talloc/talloc.h>
#include <types/types.h>
#include <log/log.h>
#include <util/util.h>
#include <i18n/i18n.h>

#include "nc-cui.h"
#include "nc-textscreen.h"
#include "nc-sysinfo.h"

struct sysinfo_screen {
	struct text_screen text_scr;
};

extern const struct help_text sysinfo_help_text;

struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
{
	return text_screen_scr(&screen->text_scr);
}

static void if_info_mac_str(struct interface_info *info,
		char *buf, unsigned int buflen)
{
	return mac_str(info->hwaddr, info->hwaddr_size, buf, buflen);
}

static void sysinfo_screen_populate(struct sysinfo_screen *screen,
		const struct system_info *sysinfo)
{
	char macbuf[32];
	unsigned int i;

	text_screen_clear(&screen->text_scr);

#define line(...) text_screen_append_line(&screen->text_scr, __VA_ARGS__)
	if (!sysinfo) {
		line(_("Waiting for system information..."));
		return;
	}

	line("%-12s %s", _("System type:"), sysinfo->type ?: "");
	line("%-12s %s", _("System id:"),   sysinfo->identifier ?: "");

	if (sysinfo->n_primary) {
		line(NULL);
		line("%s", _("Primary platform versions:"));
		for (i = 0; i < sysinfo->n_primary; i++) {
			line("\t%s", sysinfo->platform_primary[i] ?: "");
		}
	}

	if (sysinfo->n_other) {
		line(NULL);
		line("%s", _("Alternate platform versions:"));
		for (i = 0; i < sysinfo->n_other; i++) {
			line("\t%s", sysinfo->platform_other[i] ?: "");
		}
	}

	if (sysinfo->n_bmc_current) {
		line(NULL);
		line("%s", _("BMC current side:"));
		for (i = 0; i < sysinfo->n_bmc_current; i++) {
			line("\t%s", sysinfo->bmc_current[i] ?: "");
		}
	}

	if (sysinfo->n_bmc_golden) {
		line(NULL);
		line("%s", _("BMC golden side:"));
		for (i = 0; i < sysinfo->n_bmc_golden; i++) {
			line("\t%s", sysinfo->bmc_golden[i] ?: "");
		}
	}

	if (sysinfo->n_blockdevs) {
		line(NULL);
		line(_("Storage devices"));
	}

	for (i = 0; i < sysinfo->n_blockdevs; i++) {
		struct blockdev_info *info = sysinfo->blockdevs[i];

		line("%s:", info->name);
		line(_(" UUID:       %s"), info->uuid);
		line(_(" mounted at: %s"), info->mountpoint);
		line(NULL);
	}

	if (sysinfo->bmc_mac) {
		line(NULL);
		mac_str(sysinfo->bmc_mac, HWADDR_SIZE, macbuf, sizeof(macbuf));
		line(_("Management (BMC) interface"));
		line(_(" MAC:  %s"), macbuf);
	}

	if (sysinfo->n_interfaces) {
		line(NULL);
		line(_("Network interfaces"));
	}

	for (i = 0; i < sysinfo->n_interfaces; i++) {
		struct interface_info *info = sysinfo->interfaces[i];

		if_info_mac_str(info, macbuf, sizeof(macbuf));

		line("%s:", info->name);
		line(_(" MAC:        %s"), macbuf);
		line(_(" IP Address: %s"), info->address ?: _("none"));
		/* TRANSLATORS: these "up" / "down" strings refer to the
		 * link status for a network connection. */
		line(_(" link:       %s"), info->link ? _("up") : _("down"));
		line(NULL);
	}

#undef line
}

void sysinfo_screen_update(struct sysinfo_screen *screen,
		const struct system_info *sysinfo)
{
	sysinfo_screen_populate(screen, sysinfo);

	if (screen->text_scr.cui->help_screen)
		screen->text_scr.need_update = true;
	else
		text_screen_draw(&screen->text_scr);
}

struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
		const struct system_info *sysinfo,
		void (*on_exit)(struct cui *))
{
	struct sysinfo_screen *screen;

	screen = talloc_zero(cui, struct sysinfo_screen);
	text_screen_init(&screen->text_scr, cui,
			_("Petitboot System Information"), on_exit);
	text_screen_set_help(&screen->text_scr,
			_("System Information"), &sysinfo_help_text);

	sysinfo_screen_update(screen, sysinfo);

	return screen;
}
OpenPOWER on IntegriCloud