@@ -240,7 +240,14 @@ func (self *SDisk) Reset(ctx context.Context, snapshotId string) (string, error)
240240 if self .State != "available" {
241241 return "" , errors .Wrapf (cloudprovider .ErrInvalidStatus , "invalid status %s" , self .State )
242242 }
243- disk , err := self .storage .zone .region .CreateDisk (self .AvailabilityZone , self .VolumeType , self .GetName (), self .GetDiskSizeMB ()/ 1024 , self .Iops , self .Throughput , snapshotId , self .GetDescription ())
243+ opts := & cloudprovider.DiskCreateConfig {
244+ Name : self .GetName (),
245+ SizeGb : self .GetDiskSizeMB () / 1024 ,
246+ Iops : self .Iops ,
247+ Throughput : self .Throughput ,
248+ SnapshotId : snapshotId ,
249+ }
250+ disk , err := self .storage .zone .region .CreateDisk (self .AvailabilityZone , self .VolumeType , opts )
244251 if err != nil {
245252 return "" , errors .Wrapf (err , "CreateDisk" )
246253 }
@@ -353,41 +360,47 @@ func GenDiskIops(diskType string, sizeGB int) int64 {
353360 return 0
354361}
355362
356- func (self * SRegion ) CreateDisk (zoneId string , volumeType string , name string , sizeGb , iops , throughput int , snapshotId string , desc string ) (* SDisk , error ) {
363+ func (self * SRegion ) CreateDisk (zoneId string , volumeType string , opts * cloudprovider. DiskCreateConfig ) (* SDisk , error ) {
357364 params := map [string ]string {
358365 "AvailabilityZone" : zoneId ,
359366 "ClientToken" : utils .GenRequestId (20 ),
360- "Size" : fmt .Sprintf ("%d" , sizeGb ),
367+ "Size" : fmt .Sprintf ("%d" , opts . SizeGb ),
361368 "VolumeType" : volumeType ,
362369 }
363370 tagIdx := 1
364- if len (name ) > 0 {
365- params [fmt .Sprintf ("TagSpecification.%d.ResourceType" , tagIdx )] = "volume"
366- params [fmt .Sprintf ("TagSpecification.%d.Tag.1.Key" , tagIdx )] = "Name"
367- params [fmt .Sprintf ("TagSpecification.%d.Tag.1.Value" , tagIdx )] = name
368- if len (desc ) > 0 {
369- params [fmt .Sprintf ("TagSpecification.%d.Tag.2.Key" , tagIdx )] = "Description"
370- params [fmt .Sprintf ("TagSpecification.%d.Tag.2.Value" , tagIdx )] = desc
371+ if len (opts .Name ) > 0 {
372+ params ["TagSpecification.1.ResourceType" ] = "volume"
373+ params [fmt .Sprintf ("TagSpecification.1.Tag.%d.Key" , tagIdx )] = "Name"
374+ params [fmt .Sprintf ("TagSpecification.1.Tag.%d.Value" , tagIdx )] = opts .Name
375+ tagIdx ++
376+ if len (opts .Desc ) > 0 {
377+ params [fmt .Sprintf ("TagSpecification.1.Tag.%d.Key" , tagIdx )] = "Description"
378+ params [fmt .Sprintf ("TagSpecification.1.Tag.%d.Value" , tagIdx )] = opts .Desc
371379 }
380+ }
381+ for k , v := range opts .Tags {
382+ params ["TagSpecification.1.ResourceType" ] = "volume"
383+ params [fmt .Sprintf ("TagSpecification.1.Tag.%d.Key" , tagIdx )] = k
384+ params [fmt .Sprintf ("TagSpecification.1.Tag.%d.Value" , tagIdx )] = v
372385 tagIdx ++
373386 }
374- if len (snapshotId ) > 0 {
375- params ["SnapshotId" ] = snapshotId
387+ if len (opts . SnapshotId ) > 0 {
388+ params ["SnapshotId" ] = opts . SnapshotId
376389 }
377- if throughput >= 125 && throughput <= 1000 && volumeType == api .STORAGE_GP3_SSD {
378- params ["Throughput" ] = fmt .Sprintf ("%d" , throughput )
390+ if opts . Throughput >= 125 && opts . Throughput <= 1000 && volumeType == api .STORAGE_GP3_SSD {
391+ params ["Throughput" ] = fmt .Sprintf ("%d" , opts . Throughput )
379392 }
380393
381- if iops == 0 {
382- iops = int (GenDiskIops (volumeType , sizeGb ))
394+ if opts . Iops == 0 {
395+ opts . Iops = int (GenDiskIops (volumeType , opts . SizeGb ))
383396 }
384397
385398 if utils .IsInStringArray (volumeType , []string {
386399 api .STORAGE_IO1_SSD ,
387400 api .STORAGE_IO2_SSD ,
388401 api .STORAGE_GP3_SSD ,
389402 }) {
390- params ["Iops" ] = fmt .Sprintf ("%d" , iops )
403+ params ["Iops" ] = fmt .Sprintf ("%d" , opts . Iops )
391404 }
392405 ret := & SDisk {}
393406 return ret , self .ec2Request ("CreateVolume" , params , ret )
0 commit comments