@@ -24,6 +24,23 @@ func runExec(cmd string) ([]byte, error) {
24
24
return out , err
25
25
}
26
26
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
+
27
44
// ListVolumesOnDisk - returns back list of volumes(volumeIDs) in the disk (requested in diskID).
28
45
func (VolAPIImplementor ) ListVolumesOnDisk (diskID string ) (volumeIDs []string , err error ) {
29
46
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 {
110
127
finalSize = size
111
128
}
112
129
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 )
123
131
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 )
125
133
}
126
134
127
- currentSize := getPartitionSizing ["Size" ]
128
-
129
135
//if the partition's size is already the size we want this is a noop, just return
130
136
if currentSize >= finalSize {
131
137
return nil
0 commit comments