generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use WMI instead of PowerShell for OS operations
- Loading branch information
Showing
1,713 changed files
with
477,836 additions
and
411 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cim | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/microsoft/wmi/pkg/base/query" | ||
"github.com/microsoft/wmi/server2019/root/microsoft/windows/storage" | ||
) | ||
|
||
const ( | ||
// PartitionStyleUnknown indicates an unknown partition table format | ||
PartitionStyleUnknown = 0 | ||
// PartitionStyleGPT indicates the disk uses GUID Partition Table (GPT) format | ||
PartitionStyleGPT = 2 | ||
|
||
// GPTPartitionTypeBasicData is the GUID for basic data partitions in GPT | ||
// Used for general purpose storage partitions | ||
GPTPartitionTypeBasicData = "{ebd0a0a2-b9e5-4433-87c0-68b6b72699c7}" | ||
// GPTPartitionTypeMicrosoftReserved is the GUID for Microsoft Reserved Partition (MSR) | ||
// Reserved by Windows for system use | ||
GPTPartitionTypeMicrosoftReserved = "{e3c9e316-0b5c-4db8-817d-f92df00215ae}" | ||
) | ||
|
||
// QueryDiskByNumber retrieves disk information for a specific disk identified by its number. | ||
func QueryDiskByNumber(diskNumber uint32, selectorList []string) (*storage.MSFT_Disk, error) { | ||
diskQuery := query.NewWmiQueryWithSelectList("MSFT_Disk", selectorList, "Number", strconv.Itoa(int(diskNumber))) | ||
instances, err := QueryInstances(WMINamespaceStorage, diskQuery) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
disk, err := storage.NewMSFT_DiskEx1(instances[0]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to query disk %d. error: %v", diskNumber, err) | ||
} | ||
|
||
return disk, nil | ||
} | ||
|
||
// ListDisks retrieves information about all available disks. | ||
func ListDisks(selectorList []string) ([]*storage.MSFT_Disk, error) { | ||
diskQuery := query.NewWmiQueryWithSelectList("MSFT_Disk", selectorList) | ||
instances, err := QueryInstances(WMINamespaceStorage, diskQuery) | ||
if IgnoreNotFound(err) != nil { | ||
return nil, err | ||
} | ||
|
||
var disks []*storage.MSFT_Disk | ||
for _, instance := range instances { | ||
disk, err := storage.NewMSFT_DiskEx1(instance) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to query disk %v. error: %v", instance, err) | ||
} | ||
|
||
disks = append(disks, disk) | ||
} | ||
|
||
return disks, nil | ||
} |
Oops, something went wrong.