@@ -2658,6 +2658,7 @@ func (p *Provider) CreateVolume(
26582658 args = append (args , "--volume-type" , vco .Type )
26592659 case "" :
26602660 // Use the default.
2661+ args = append (args , "--volume-type" , defaultEBSVolumeType )
26612662 default :
26622663 return vol , errors .Newf ("Invalid volume type %q" , vco .Type )
26632664 }
@@ -2754,8 +2755,73 @@ func (p *Provider) DeleteVolume(l *logger.Logger, volume vm.Volume, v *vm.VM) er
27542755 return nil
27552756}
27562757
2757- func (p * Provider ) ListVolumes (l * logger.Logger , vm * vm.VM ) ([]vm.Volume , error ) {
2758- return vm .NonBootAttachedVolumes , nil
2758+ func (p * Provider ) ListVolumes (l * logger.Logger , v * vm.VM ) ([]vm.Volume , error ) {
2759+ if v .ProviderID == "" {
2760+ return nil , nil
2761+ }
2762+ region := v .Zone [:len (v .Zone )- 1 ]
2763+
2764+ // Describe this instance to get block device mappings and the root device
2765+ // name, which we need to identify (and exclude) the boot volume.
2766+ var descResp DescribeInstancesOutput
2767+ descArgs := []string {
2768+ "ec2" , "describe-instances" ,
2769+ "--region" , region ,
2770+ "--instance-ids" , v .ProviderID ,
2771+ }
2772+ if err := p .runJSONCommand (l , descArgs , & descResp ); err != nil {
2773+ return nil , err
2774+ }
2775+ var instance * DescribeInstancesOutputInstance
2776+ for _ , res := range descResp .Reservations {
2777+ for i := range res .Instances {
2778+ if res .Instances [i ].InstanceID == v .ProviderID {
2779+ instance = & res .Instances [i ]
2780+ break
2781+ }
2782+ }
2783+ }
2784+ if instance == nil {
2785+ l .Printf ("WARNING: instance %s not found in describe-instances response for region %s" , v .ProviderID , region )
2786+ return nil , nil
2787+ }
2788+
2789+ // Collect non-boot volume device names from the block device
2790+ // mappings. The root device is excluded so we only return data volumes.
2791+ deviceByVolumeID := make (map [string ]string )
2792+ for _ , bdm := range instance .BlockDeviceMappings {
2793+ if bdm .DeviceName != instance .RootDeviceName {
2794+ deviceByVolumeID [bdm .Disk .VolumeID ] = bdm .DeviceName
2795+ }
2796+ }
2797+ if len (deviceByVolumeID ) == 0 {
2798+ return nil , nil
2799+ }
2800+
2801+ // Describe the non-boot volumes to get their full metadata.
2802+ volsByInstance , err := p .getVolumesForInstances (
2803+ context .Background (), l , region , []string {v .ProviderID },
2804+ )
2805+ if err != nil {
2806+ return nil , err
2807+ }
2808+
2809+ var volumes []vm.Volume
2810+ for _ , vol := range volsByInstance [v .ProviderID ] {
2811+ if _ , ok := deviceByVolumeID [vol .ProviderResourceID ]; ok {
2812+ volumes = append (volumes , vol )
2813+ }
2814+ }
2815+
2816+ // Sort by device name to ensure deterministic ordering that matches
2817+ // the mount point assignment (/mnt/data1, /mnt/data2, etc.).
2818+ slices .SortFunc (volumes , func (a , b vm.Volume ) int {
2819+ return strings .Compare (
2820+ deviceByVolumeID [a .ProviderResourceID ],
2821+ deviceByVolumeID [b .ProviderResourceID ],
2822+ )
2823+ })
2824+ return volumes , nil
27592825}
27602826
27612827type snapshotOutput struct {
@@ -2797,21 +2863,11 @@ func (p *Provider) CreateVolumeSnapshot(
27972863 return vm.VolumeSnapshot {}, err
27982864 }
27992865
2800- // Wait for the snapshot to complete before returning. AWS snapshots
2801- // are asynchronous and cannot be used to create volumes while pending.
2802- waitArgs := []string {
2803- "ec2" , "wait" , "snapshot-completed" ,
2804- "--region" , region ,
2805- "--snapshot-ids" , so .SnapshotID ,
2806- }
2807- if _ , err := p .runCommand (l , waitArgs ); err != nil {
2808- return vm.VolumeSnapshot {}, errors .Wrapf (err , "waiting for snapshot %s to complete" , so .SnapshotID )
2809- }
2810-
28112866 return vm.VolumeSnapshot {
28122867 ID : so .SnapshotID ,
28132868 Name : vsco .Name ,
28142869 Region : region ,
2870+ Status : so .State ,
28152871 }, nil
28162872}
28172873
@@ -2875,6 +2931,7 @@ func (p *Provider) ListVolumeSnapshots(
28752931 ID : so .SnapshotID ,
28762932 Name : name ,
28772933 Region : r ,
2934+ Status : so .State ,
28782935 })
28792936 }
28802937 mu .Lock ()
0 commit comments