-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
propagate windows license to the VMs
Signed-off-by: Shahriyar Jalayeri <[email protected]>
- Loading branch information
Showing
14 changed files
with
293 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Copyright (c) 2025 Zededa, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package hypervisor | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
|
||
uuid "github.com/satori/go.uuid" | ||
|
||
"github.com/lf-edge/eve/pkg/pillar/types" | ||
fileutils "github.com/lf-edge/eve/pkg/pillar/utils/file" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// TODO: move all the windows related OVMF code to this file | ||
|
||
// Struct to hold system information | ||
type DmiSystemInfo struct { | ||
Manufacturer string | ||
ProductName string | ||
Version string | ||
SerialNumber string | ||
UUID string | ||
SKUNumber string | ||
Family string | ||
} | ||
|
||
// getSmbiosString returns a SMBIOS type 1 string (system information) | ||
func getSmbiosString(sysInfo DmiSystemInfo) string { | ||
var fields []string | ||
|
||
if sysInfo.UUID != "" { | ||
fields = append(fields, fmt.Sprintf("uuid=%s", sysInfo.UUID)) | ||
} | ||
if sysInfo.Manufacturer != "" { | ||
fields = append(fields, fmt.Sprintf("manufacturer=%s", sysInfo.Manufacturer)) | ||
} | ||
if sysInfo.ProductName != "" { | ||
fields = append(fields, fmt.Sprintf("product=%s", sysInfo.ProductName)) | ||
} | ||
if sysInfo.Version != "" { | ||
fields = append(fields, fmt.Sprintf("version=%s", sysInfo.Version)) | ||
} | ||
if sysInfo.SerialNumber != "" { | ||
fields = append(fields, fmt.Sprintf("serial=%s", sysInfo.SerialNumber)) | ||
} | ||
if sysInfo.SKUNumber != "" { | ||
fields = append(fields, fmt.Sprintf("sku=%s", sysInfo.SKUNumber)) | ||
} | ||
if sysInfo.Family != "" { | ||
fields = append(fields, fmt.Sprintf("family=%s", sysInfo.Family)) | ||
} | ||
|
||
smbiosString := "type=1," + strings.Join(fields, ",") | ||
return smbiosString | ||
} | ||
|
||
// generateDmidecodeSmbiosString execute dmidecode and creates the SMBIOS string | ||
func generateDmidecodeSmbiosString() string { | ||
validate := func(a string) string { | ||
a = strings.TrimSpace(a) | ||
if strings.Contains(a, ",") { | ||
logrus.Warnf("Invalid value: %s", a) | ||
return "" | ||
} | ||
return a | ||
} | ||
|
||
dmidecode := func(arg string) string { | ||
cmd := exec.Command("dmidecode", "-s", arg) | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
logrus.Warnf("Failed to run dmidecode %s : %v", arg, err) | ||
return "" | ||
} | ||
|
||
return validate(string(output)) | ||
} | ||
|
||
sysInfo := DmiSystemInfo{} | ||
sysInfo.Manufacturer = validate(dmidecode("system-manufacturer")) | ||
sysInfo.ProductName = validate(dmidecode("system-product-name")) | ||
sysInfo.Version = validate(dmidecode("system-version")) | ||
sysInfo.SerialNumber = validate(dmidecode("system-serial-number")) | ||
sysInfo.SKUNumber = validate(dmidecode("system-sku-number")) | ||
sysInfo.Family = validate(dmidecode("system-family")) | ||
smbiosString := getSmbiosString(sysInfo) | ||
sysInfo.UUID = validate(dmidecode("system-uuid")) | ||
if sysInfo.UUID != "" { | ||
_, err := uuid.FromString(sysInfo.UUID) | ||
if err != nil { | ||
logrus.Warnf("Invalid UUID: %s", sysInfo.UUID) | ||
sysInfo.UUID = "" | ||
} | ||
} | ||
|
||
logrus.Infof("Generated SMBIOS string: %s", smbiosString) | ||
return smbiosString | ||
} | ||
|
||
// dumpWindowsLicenceFromACPI dumps the Windows licence from ACPI tables | ||
func dumpWindowsLicenceFromACPI() ([]string, error) { | ||
if _, err := os.Stat(types.MsWindowsLicenceStore); os.IsNotExist(err) { | ||
if err := os.MkdirAll(types.MsWindowsLicenceStore, 0600); err != nil { | ||
return nil, fmt.Errorf("failed to create directory %s: %v", types.MsWindowsLicenceStore, err) | ||
} | ||
} else { | ||
return nil, fmt.Errorf("erro while checking directory %s: %v", types.MsWindowsLicenceStore, err) | ||
} | ||
|
||
collectedLicences := []string{} | ||
// TODO: testing, revert this back | ||
//acpiTablePath := "/sys/firmware/acpi/tables" | ||
acpiTablePath := "/hostfs/etc/winlic" | ||
windowsLicenceTables := map[string]bool{ | ||
"MSDM": true, | ||
"SLIC": false, | ||
} | ||
|
||
for table, mandatory := range windowsLicenceTables { | ||
winLicStorePath := filepath.Join(types.MsWindowsLicenceStore, table) | ||
// skip if we already have the table dumped | ||
if _, err := os.Stat(winLicStorePath); err == nil { | ||
continue | ||
} | ||
|
||
sysFsPath := filepath.Join(acpiTablePath, table) | ||
if _, err := os.Stat(sysFsPath); err != nil { | ||
if mandatory { | ||
return nil, fmt.Errorf("error while checking mandatory %s table : %w", table, err) | ||
} else { | ||
logrus.Warnf("error while checkin %s table : %v", table, err) | ||
continue | ||
} | ||
} | ||
|
||
if err := fileutils.CopyFile(sysFsPath, winLicStorePath); err != nil { | ||
if mandatory { | ||
return nil, fmt.Errorf("failed to copy %s table: %w", table, err) | ||
} else { | ||
logrus.Warnf("failed to copy %s table: %v", table, err) | ||
continue | ||
} | ||
} | ||
|
||
collectedLicences = append(collectedLicences, winLicStorePath) | ||
} | ||
|
||
return collectedLicences, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.