@@ -10,9 +10,11 @@ import (
10
10
"strconv"
11
11
"strings"
12
12
13
+ "github.com/lxc/incus/v6/internal/linux"
13
14
"github.com/lxc/incus/v6/internal/server/response"
14
15
"github.com/lxc/incus/v6/shared/api"
15
16
"github.com/lxc/incus/v6/shared/logger"
17
+ "github.com/lxc/incus/v6/shared/osarch"
16
18
"github.com/lxc/incus/v6/shared/util"
17
19
)
18
20
@@ -39,6 +41,7 @@ func renderState() *api.InstanceState {
39
41
Network : networkState (),
40
42
Pid : 1 ,
41
43
Processes : processesState (),
44
+ OSInfo : osState (),
42
45
}
43
46
}
44
47
@@ -242,3 +245,35 @@ func processesState() int64 {
242
245
243
246
return int64 (len (pids ))
244
247
}
248
+
249
+ func osState () * api.InstanceStateOSInfo {
250
+ osInfo := & api.InstanceStateOSInfo {}
251
+
252
+ // Get information about the OS.
253
+ lsbRelease , err := osarch .GetLSBRelease ()
254
+ if err == nil {
255
+ osInfo .OS = lsbRelease ["NAME" ]
256
+ osInfo .OSVersion = lsbRelease ["VERSION" ]
257
+ }
258
+
259
+ // Get information about the kernel version.
260
+ uname , err := linux .Uname ()
261
+ if err == nil {
262
+ osInfo .KernelVersion = uname .Release
263
+ }
264
+
265
+ // Get the hostname.
266
+ hostname , err := os .Hostname ()
267
+ if err == nil {
268
+ osInfo .Hostname = hostname
269
+ }
270
+
271
+ // Get the FQDN. To avoid needing to run `hostname -f`, do a reverse host lookup for 127.0.1.1, and if found, return the first hostname as the FQDN.
272
+ fqdn , err := net .LookupAddr ("127.0.1.1" )
273
+ if err == nil {
274
+ // Take the first returned hostname and trim the trailing dot.
275
+ osInfo .FQDN = strings .TrimSuffix (fqdn [0 ], "." )
276
+ }
277
+
278
+ return osInfo
279
+ }
0 commit comments