Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send arrays to ConvertTo-Json in the internal disk implementation #154

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions pkg/os/disk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (DiskAPI) ListDiskLocations() (map[uint32]shared.DiskLocation, error) {
// "number": 0,
// "location": "PCI Slot 3 : Adapter 0 : Port 0 : Target 1 : LUN 0"
// }, ...]
cmd := fmt.Sprintf("Get-Disk | select number, location | ConvertTo-Json")
cmd := fmt.Sprintf("ConvertTo-Json @(Get-Disk | select Number, Location)")
out, err := runExec(cmd)
if err != nil {
return nil, fmt.Errorf("failed to list disk location. cmd: %q, output: %q, err %v", cmd, string(out), err)
Expand All @@ -93,8 +93,8 @@ func (DiskAPI) ListDiskLocations() (map[uint32]shared.DiskLocation, error) {

m := make(map[uint32]shared.DiskLocation)
for _, v := range getDisk {
str := v["location"].(string)
num := v["number"].(float64)
str := v["Location"].(string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change location --> Location?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is actually not needed and I can revert it back, it's because I also changed this line above:

cmd := fmt.Sprintf("ConvertTo-Json @(Get-Disk | select Number, Location)")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can skip making this change, I already run the integration tests on #155 and they're passing with the v1 API too

num := v["Number"].(float64)

found := false
s := strings.Split(str, ":")
Expand Down Expand Up @@ -237,15 +237,18 @@ func (DiskAPI) GetDiskPage83ID(disk syscall.Handle) (string, error) {
}

func (imp DiskAPI) GetDiskNumberWithID(page83ID string) (uint32, error) {
cmd := "(Get-Disk | Select Path) | ConvertTo-Json"
cmd := "ConvertTo-Json @(Get-Disk | Select Path)"
out, err := runExec(cmd)
if err != nil {
return 0, fmt.Errorf("Could not query disk paths")
}

outString := string(out)
disks := []Disk{}
json.Unmarshal([]byte(outString), &disks)
err = json.Unmarshal([]byte(outString), &disks)
if err != nil {
return 0, err
}

for i := range disks {
diskNumber, diskPage83ID, err := imp.GetDiskNumberAndPage83ID(disks[i].Path)
Expand Down Expand Up @@ -293,16 +296,19 @@ func (imp DiskAPI) ListDiskIDs() (map[uint32]shared.DiskIDs, error) {
// {
// "Path": "\\\\?\\scsi#disk\u0026ven_msft\u0026prod_virtual_disk#2\u00261f4adffe\u00260\u0026000001#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}",
// "SerialNumber": null
// },
cmd := "(Get-Disk | Select Path, SerialNumber) | ConvertTo-Json"
// }, ]
cmd := "ConvertTo-Json @(Get-Disk | Select Path, SerialNumber)"
out, err := runExec(cmd)
if err != nil {
return nil, fmt.Errorf("Could not query disk paths")
}

outString := string(out)
disks := []Disk{}
json.Unmarshal([]byte(outString), &disks)
err = json.Unmarshal([]byte(outString), &disks)
if err != nil {
return nil, err
}

m := make(map[uint32]shared.DiskIDs)

Expand Down