mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Changed to use cmd for getting system uuid
This commit is contained in:
parent
e56db7d407
commit
e242bbe12c
@ -20,6 +20,7 @@ package winstats
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
@ -221,13 +222,15 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
||||
}
|
||||
|
||||
func getSystemUUID() (string, error) {
|
||||
cmd := exec.Command("powershell.exe", "-Command", "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")
|
||||
out, err := cmd.CombinedOutput()
|
||||
result, err := exec.Command("wmic", "csproduct", "get", "UUID").Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
systemUUID := strings.TrimRight(string(out), "\r\n")
|
||||
return systemUUID, nil
|
||||
fields := strings.Fields(string(result))
|
||||
if len(fields) != 2 {
|
||||
return "", fmt.Errorf("received unexpected value retrieving vm uuid: %q", string(result))
|
||||
}
|
||||
return fields[1], nil
|
||||
}
|
||||
|
||||
func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
|
||||
|
@ -103,7 +103,7 @@ func (c *StatsClient) WinContainerInfos() (map[string]cadvisorapiv2.ContainerInf
|
||||
}
|
||||
|
||||
// WinMachineInfo returns a cadvisorapi.MachineInfo with details about the
|
||||
// node machine.
|
||||
// node machine. Analogous to cadvisor MachineInfo method.
|
||||
func (c *StatsClient) WinMachineInfo() (*cadvisorapi.MachineInfo, error) {
|
||||
return c.client.getMachineInfo()
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func (f fakeWinNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo, erro
|
||||
NumCores: 4,
|
||||
MemoryCapacity: 1.6e+10,
|
||||
MachineID: "somehostname",
|
||||
SystemUUID: "",
|
||||
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -116,12 +116,11 @@ func TestWinMachineInfo(t *testing.T) {
|
||||
|
||||
machineInfo, err := c.WinMachineInfo()
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, machineInfo.SystemUUID, "")
|
||||
assert.Equal(t, machineInfo, &cadvisorapi.MachineInfo{
|
||||
NumCores: 4,
|
||||
MemoryCapacity: 1.6e+10,
|
||||
MachineID: "somehostname",
|
||||
SystemUUID: machineInfo.SystemUUID})
|
||||
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906"})
|
||||
}
|
||||
|
||||
func TestWinVersionInfo(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user