@@ -322,19 +322,21 @@ func (s *awsOps) InspectInstanceGroupForInstance(instanceID string) (*cloudops.I
322322 return nil , & cloudops.ErrNoInstanceGroup {}
323323}
324324
325- func (s * awsOps ) ApplyTags (volumeID string , labels map [string ]string ) error {
325+ func (s * awsOps ) ApplyTags (volumeID string , labels map [string ]string , options map [ string ] string ) error {
326326 req := & ec2.CreateTagsInput {
327327 Resources : []* string {& volumeID },
328328 Tags : s .tags (labels ),
329+ DryRun : dryRun (options ),
329330 }
330331 _ , err := s .ec2 .CreateTags (req )
331332 return err
332333}
333334
334- func (s * awsOps ) RemoveTags (volumeID string , labels map [string ]string ) error {
335+ func (s * awsOps ) RemoveTags (volumeID string , labels map [string ]string , options map [ string ] string ) error {
335336 req := & ec2.DeleteTagsInput {
336337 Resources : []* string {& volumeID },
337338 Tags : s .tags (labels ),
339+ DryRun : dryRun (options ),
338340 }
339341 _ , err := s .ec2 .DeleteTags (req )
340342 return err
@@ -660,15 +662,15 @@ func (s *awsOps) FreeDevices(
660662
661663func (s * awsOps ) rollbackCreate (id string , createErr error ) error {
662664 logrus .Warnf ("Rollback create volume %v, Error %v" , id , createErr )
663- err := s .Delete (id )
665+ err := s .Delete (id , nil )
664666 if err != nil {
665667 logrus .Warnf ("Rollback failed volume %v, Error %v" , id , err )
666668 }
667669 return createErr
668670}
669671
670672func (s * awsOps ) refreshVol (id * string ) (* ec2.Volume , error ) {
671- vols , err := s .Inspect ([]* string {id })
673+ vols , err := s .Inspect ([]* string {id }, nil )
672674 if err != nil {
673675 return nil , err
674676 }
@@ -707,8 +709,11 @@ func (s *awsOps) GetDeviceID(vol interface{}) (string, error) {
707709 }
708710}
709711
710- func (s * awsOps ) Inspect (volumeIds []* string ) ([]interface {}, error ) {
711- req := & ec2.DescribeVolumesInput {VolumeIds : volumeIds }
712+ func (s * awsOps ) Inspect (volumeIds []* string , options map [string ]string ) ([]interface {}, error ) {
713+ req := & ec2.DescribeVolumesInput {
714+ VolumeIds : volumeIds ,
715+ DryRun : dryRun (options ),
716+ }
712717 resp , err := s .ec2 .DescribeVolumes (req )
713718 if err != nil {
714719 return nil , err
@@ -739,6 +744,7 @@ func (s *awsOps) Enumerate(
739744 volumeIds []* string ,
740745 labels map [string ]string ,
741746 setIdentifier string ,
747+
742748) (map [string ][]interface {}, error ) {
743749 sets := make (map [string ][]interface {})
744750
@@ -778,6 +784,7 @@ func (s *awsOps) Enumerate(
778784func (s * awsOps ) Create (
779785 v interface {},
780786 labels map [string ]string ,
787+ options map [string ]string ,
781788) (interface {}, error ) {
782789 vol , ok := v .(* ec2.Volume )
783790 if ! ok {
@@ -797,6 +804,7 @@ func (s *awsOps) Create(
797804 VolumeType : vol .VolumeType ,
798805 SnapshotId : vol .SnapshotId ,
799806 Throughput : vol .Throughput ,
807+ DryRun : dryRun (options ),
800808 }
801809
802810 if len (s .outpostARN ) > 0 {
@@ -846,11 +854,14 @@ func (s *awsOps) Create(
846854}
847855
848856func (s * awsOps ) DeleteFrom (id , _ string ) error {
849- return s .Delete (id )
857+ return s .Delete (id , nil )
850858}
851859
852- func (s * awsOps ) Delete (id string ) error {
853- req := & ec2.DeleteVolumeInput {VolumeId : & id }
860+ func (s * awsOps ) Delete (id string , options map [string ]string ) error {
861+ req := & ec2.DeleteVolumeInput {
862+ VolumeId : & id ,
863+ DryRun : dryRun (options ),
864+ }
854865 _ , err := s .ec2 .DeleteVolume (req )
855866 return err
856867}
@@ -879,6 +890,7 @@ func (s *awsOps) Attach(volumeID string, options map[string]string) (string, err
879890 Device : & device ,
880891 InstanceId : & s .instance ,
881892 VolumeId : & volumeID ,
893+ DryRun : dryRun (options ),
882894 }
883895 if _ , err := s .ec2 .AttachVolume (req ); err != nil {
884896 if strings .Contains (err .Error (), "is already in use" ) {
@@ -904,20 +916,21 @@ func (s *awsOps) Attach(volumeID string, options map[string]string) (string, err
904916 return "" , fmt .Errorf ("failed to attach any of the free devices. Attempted: %v" , devices )
905917}
906918
907- func (s * awsOps ) Detach (volumeID string ) error {
908- return s .detachInternal (volumeID , s .instance )
919+ func (s * awsOps ) Detach (volumeID string , options map [ string ] string ) error {
920+ return s .detachInternal (volumeID , s .instance , options )
909921}
910922
911923func (s * awsOps ) DetachFrom (volumeID , instanceName string ) error {
912- return s .detachInternal (volumeID , instanceName )
924+ return s .detachInternal (volumeID , instanceName , nil )
913925}
914926
915- func (s * awsOps ) detachInternal (volumeID , instanceName string ) error {
927+ func (s * awsOps ) detachInternal (volumeID , instanceName string , options map [ string ] string ) error {
916928 force := false
917929 req := & ec2.DetachVolumeInput {
918930 InstanceId : & instanceName ,
919931 VolumeId : & volumeID ,
920932 Force : & force ,
933+ DryRun : dryRun (options ),
921934 }
922935 if _ , err := s .ec2 .DetachVolume (req ); err != nil {
923936 return err
@@ -932,6 +945,7 @@ func (s *awsOps) detachInternal(volumeID, instanceName string) error {
932945func (s * awsOps ) Expand (
933946 volumeID string ,
934947 newSizeInGiB uint64 ,
948+ options map [string ]string ,
935949) (uint64 , error ) {
936950 vol , err := s .refreshVol (& volumeID )
937951 if err != nil {
@@ -948,6 +962,7 @@ func (s *awsOps) Expand(
948962 request := & ec2.ModifyVolumeInput {
949963 VolumeId : vol .VolumeId ,
950964 Size : & newSizeInGiBInt64 ,
965+ DryRun : dryRun (options ),
951966 }
952967 output , err := s .ec2 .ModifyVolume (request )
953968 if err != nil {
@@ -995,16 +1010,19 @@ func (s *awsOps) Expand(
9951010func (s * awsOps ) Snapshot (
9961011 volumeID string ,
9971012 readonly bool ,
1013+ options map [string ]string ,
9981014) (interface {}, error ) {
9991015 request := & ec2.CreateSnapshotInput {
10001016 VolumeId : & volumeID ,
1017+ DryRun : dryRun (options ),
10011018 }
10021019 return s .ec2 .CreateSnapshot (request )
10031020}
10041021
1005- func (s * awsOps ) SnapshotDelete (snapID string ) error {
1022+ func (s * awsOps ) SnapshotDelete (snapID string , options map [ string ] string ) error {
10061023 request := & ec2.DeleteSnapshotInput {
10071024 SnapshotId : & snapID ,
1025+ DryRun : dryRun (options ),
10081026 }
10091027
10101028 _ , err := s .ec2 .DeleteSnapshot (request )
@@ -1201,3 +1219,8 @@ func reverse(a []string) []string {
12011219
12021220 return reversed
12031221}
1222+
1223+ func dryRun (options map [string ]string ) * bool {
1224+ _ , ok := options [cloudops .DryRunOption ]
1225+ return & ok
1226+ }
0 commit comments