Skip to content

Commit ad39b1f

Browse files
committed
cr updates
1 parent 0afe9b8 commit ad39b1f

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

internal/os/volume/api.go

+19-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ func runExec(cmd string) ([]byte, error) {
2424
return out, err
2525
}
2626

27+
func getVolumeSize(volumeID string) (int64, error) {
28+
cmd := fmt.Sprintf("(Get-Volume -UniqueId \"%s\" | Get-partition).Size", volumeID)
29+
out, err := runExec(cmd)
30+
31+
if err != nil || len(out) == 0 {
32+
return -1, fmt.Errorf("error getting size of the partition from mount. cmd %s, output: %s, error: %v", cmd, string(out), err)
33+
}
34+
35+
outString := strings.TrimSpace(string(out))
36+
volumeSize, err := strconv.ParseInt(outString, 10, 64)
37+
if err != nil {
38+
return -1, fmt.Errorf("error parsing size of volume %s received %v trimmed to %v err %v", volumeID, out, outString, err)
39+
}
40+
41+
return volumeSize, nil
42+
}
43+
2744
// ListVolumesOnDisk - returns back list of volumes(volumeIDs) in the disk (requested in diskID).
2845
func (VolAPIImplementor) ListVolumesOnDisk(diskID string) (volumeIDs []string, err error) {
2946
cmd := fmt.Sprintf("(Get-Disk -DeviceId %s |Get-Partition | Get-Volume).UniqueId", diskID)
@@ -110,22 +127,11 @@ func (VolAPIImplementor) ResizeVolume(volumeID string, size int64) error {
110127
finalSize = size
111128
}
112129

113-
cmd = fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-partition | Select Size", volumeID)
114-
out, err = runExec(cmd)
115-
116-
if err != nil || len(out) == 0 {
117-
return fmt.Errorf("error getting size of the partition from moun. cmd %s, output: %s, error: %v", cmd, string(out), err)
118-
}
119-
120-
var getPartitionSizing map[string]int64
121-
outString = string(out)
122-
err = json.Unmarshal([]byte(outString), &getPartitionSizing)
130+
currentSize, err := getVolumeSize(volumeID)
123131
if err != nil {
124-
return fmt.Errorf("out %v outstring %v err %v", out, outString, err)
132+
return fmt.Errorf("error getting the current size of volume (%s) with error (%v)", volumeID, err)
125133
}
126134

127-
currentSize := getPartitionSizing["Size"]
128-
129135
//if the partition's size is already the size we want this is a noop, just return
130136
if currentSize >= finalSize {
131137
return nil

0 commit comments

Comments
 (0)