Merge pull request #80486 from liyanhui1228/systemuuid

Set the systemUUID for windows nodes
This commit is contained in:
Kubernetes Prow Robot 2019-07-24 13:50:33 -07:00 committed by GitHub
commit 70521fbf32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -20,8 +20,11 @@ package winstats
import (
"errors"
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"sync"
"time"
"unsafe"
@ -136,10 +139,16 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo,
return nil, err
}
systemUUID, err := getSystemUUID()
if err != nil {
return nil, err
}
return &cadvisorapi.MachineInfo{
NumCores: runtime.NumCPU(),
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
MachineID: hostname,
SystemUUID: systemUUID,
}, nil
}
@ -212,6 +221,18 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
return cpuUsageNanoCores
}
func getSystemUUID() (string, error) {
result, err := exec.Command("wmic", "csproduct", "get", "UUID").Output()
if err != nil {
return "", err
}
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) {
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
// on Windows node for the following reasons:

View File

@ -56,6 +56,7 @@ func (f fakeWinNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo, erro
NumCores: 4,
MemoryCapacity: 1.6e+10,
MachineID: "somehostname",
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906",
}, nil
}
@ -118,7 +119,8 @@ func TestWinMachineInfo(t *testing.T) {
assert.Equal(t, machineInfo, &cadvisorapi.MachineInfo{
NumCores: 4,
MemoryCapacity: 1.6e+10,
MachineID: "somehostname"})
MachineID: "somehostname",
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906"})
}
func TestWinVersionInfo(t *testing.T) {