]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-sysinfo.c
discover/sysinfo: Set IPv6 addresses
[petitboot] / ui / ncurses / nc-sysinfo.c
1 /*
2  *  Copyright (C) 2013 IBM Corporation
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #include <string.h>
23
24 #include <talloc/talloc.h>
25 #include <types/types.h>
26 #include <log/log.h>
27 #include <util/util.h>
28 #include <i18n/i18n.h>
29
30 #include "nc-cui.h"
31 #include "nc-textscreen.h"
32 #include "nc-sysinfo.h"
33
34 struct sysinfo_screen {
35         struct text_screen text_scr;
36 };
37
38 extern const struct help_text sysinfo_help_text;
39
40 struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
41 {
42         return text_screen_scr(&screen->text_scr);
43 }
44
45 static void if_info_mac_str(struct interface_info *info,
46                 char *buf, unsigned int buflen)
47 {
48         return mac_str(info->hwaddr, info->hwaddr_size, buf, buflen);
49 }
50
51 static void sysinfo_screen_populate(struct sysinfo_screen *screen,
52                 const struct system_info *sysinfo)
53 {
54         char macbuf[32];
55         unsigned int i;
56
57         text_screen_clear(&screen->text_scr);
58
59 #define line(...) text_screen_append_line(&screen->text_scr, __VA_ARGS__)
60         if (!sysinfo) {
61                 line(_("Waiting for system information..."));
62                 return;
63         }
64
65         line("%-12s %s", _("System type:"), sysinfo->type ?: "");
66         line("%-12s %s", _("System id:"),   sysinfo->identifier ?: "");
67
68         if (sysinfo->n_primary) {
69                 line(NULL);
70                 line("%s", _("Primary platform versions:"));
71                 for (i = 0; i < sysinfo->n_primary; i++) {
72                         line("\t%s", sysinfo->platform_primary[i] ?: "");
73                 }
74         }
75
76         if (sysinfo->n_other) {
77                 line(NULL);
78                 line("%s", _("Alternate platform versions:"));
79                 for (i = 0; i < sysinfo->n_other; i++) {
80                         line("\t%s", sysinfo->platform_other[i] ?: "");
81                 }
82         }
83
84         if (sysinfo->n_bmc_current) {
85                 line(NULL);
86                 line("%s", _("BMC current side:"));
87                 for (i = 0; i < sysinfo->n_bmc_current; i++) {
88                         line("\t%s", sysinfo->bmc_current[i] ?: "");
89                 }
90         }
91
92         if (sysinfo->n_bmc_golden) {
93                 line(NULL);
94                 line("%s", _("BMC golden side:"));
95                 for (i = 0; i < sysinfo->n_bmc_golden; i++) {
96                         line("\t%s", sysinfo->bmc_golden[i] ?: "");
97                 }
98         }
99
100         if (sysinfo->n_blockdevs) {
101                 line(NULL);
102                 line(_("Storage devices"));
103         }
104
105         for (i = 0; i < sysinfo->n_blockdevs; i++) {
106                 struct blockdev_info *info = sysinfo->blockdevs[i];
107
108                 line("%s:", info->name);
109                 line(_(" UUID:       %s"), info->uuid);
110                 line(_(" mounted at: %s"), info->mountpoint);
111                 line(NULL);
112         }
113
114         if (sysinfo->bmc_mac) {
115                 line(NULL);
116                 mac_str(sysinfo->bmc_mac, HWADDR_SIZE, macbuf, sizeof(macbuf));
117                 line(_("Management (BMC) interface"));
118                 line(_(" MAC:  %s"), macbuf);
119         }
120
121         if (sysinfo->n_interfaces) {
122                 line(NULL);
123                 line(_("Network interfaces"));
124         }
125
126         for (i = 0; i < sysinfo->n_interfaces; i++) {
127                 struct interface_info *info = sysinfo->interfaces[i];
128
129                 if_info_mac_str(info, macbuf, sizeof(macbuf));
130
131                 line("%s:", info->name);
132                 line(_(" MAC:        %s"), macbuf);
133                 line(_(" IP Address: %s"), info->address ?: _("none"));
134                 if (info->address_v6)
135                         line(_(" IPv6 Address: %s"),
136                                         info->address_v6 ?: _("none"));
137                 /* TRANSLATORS: these "up" / "down" strings refer to the
138                  * link status for a network connection. */
139                 line(_(" link:       %s"), info->link ? _("up") : _("down"));
140                 line(NULL);
141         }
142
143 #undef line
144 }
145
146 void sysinfo_screen_update(struct sysinfo_screen *screen,
147                 const struct system_info *sysinfo)
148 {
149         sysinfo_screen_populate(screen, sysinfo);
150
151         if (screen->text_scr.cui->help_screen)
152                 screen->text_scr.need_update = true;
153         else
154                 text_screen_draw(&screen->text_scr);
155 }
156
157 struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
158                 const struct system_info *sysinfo,
159                 void (*on_exit)(struct cui *))
160 {
161         struct sysinfo_screen *screen;
162
163         screen = talloc_zero(cui, struct sysinfo_screen);
164         text_screen_init(&screen->text_scr, cui,
165                         _("Petitboot System Information"), on_exit);
166         text_screen_set_help(&screen->text_scr,
167                         _("System Information"), &sysinfo_help_text);
168
169         sysinfo_screen_update(screen, sysinfo);
170
171         return screen;
172 }