@@ -2622,6 +2622,7 @@ func (p *Provider) CreateVolume(
26222622 args = append (args , "--volume-type" , vco .Type )
26232623 case "" :
26242624 // Use the default.
2625+ args = append (args , "--volume-type" , defaultEBSVolumeType )
26252626 default :
26262627 return vol , errors .Newf ("Invalid volume type %q" , vco .Type )
26272628 }
@@ -2718,8 +2719,73 @@ func (p *Provider) DeleteVolume(l *logger.Logger, volume vm.Volume, v *vm.VM) er
27182719 return nil
27192720}
27202721
2721- func (p * Provider ) ListVolumes (l * logger.Logger , vm * vm.VM ) ([]vm.Volume , error ) {
2722- return vm .NonBootAttachedVolumes , nil
2722+ func (p * Provider ) ListVolumes (l * logger.Logger , v * vm.VM ) ([]vm.Volume , error ) {
2723+ if v .ProviderID == "" {
2724+ return nil , nil
2725+ }
2726+ region := v .Zone [:len (v .Zone )- 1 ]
2727+
2728+ // Describe this instance to get block device mappings and the root device
2729+ // name, which we need to identify (and exclude) the boot volume.
2730+ var descResp DescribeInstancesOutput
2731+ descArgs := []string {
2732+ "ec2" , "describe-instances" ,
2733+ "--region" , region ,
2734+ "--instance-ids" , v .ProviderID ,
2735+ }
2736+ if err := p .runJSONCommand (l , descArgs , & descResp ); err != nil {
2737+ return nil , err
2738+ }
2739+ var instance * DescribeInstancesOutputInstance
2740+ for _ , res := range descResp .Reservations {
2741+ for i := range res .Instances {
2742+ if res .Instances [i ].InstanceID == v .ProviderID {
2743+ instance = & res .Instances [i ]
2744+ break
2745+ }
2746+ }
2747+ }
2748+ if instance == nil {
2749+ l .Printf ("WARNING: instance %s not found in describe-instances response for region %s" , v .ProviderID , region )
2750+ return nil , nil
2751+ }
2752+
2753+ // Collect non-boot volume device names from the block device
2754+ // mappings. The root device is excluded so we only return data volumes.
2755+ deviceByVolumeID := make (map [string ]string )
2756+ for _ , bdm := range instance .BlockDeviceMappings {
2757+ if bdm .DeviceName != instance .RootDeviceName {
2758+ deviceByVolumeID [bdm .Disk .VolumeID ] = bdm .DeviceName
2759+ }
2760+ }
2761+ if len (deviceByVolumeID ) == 0 {
2762+ return nil , nil
2763+ }
2764+
2765+ // Describe the non-boot volumes to get their full metadata.
2766+ volsByInstance , err := p .getVolumesForInstances (
2767+ context .Background (), l , region , []string {v .ProviderID },
2768+ )
2769+ if err != nil {
2770+ return nil , err
2771+ }
2772+
2773+ var volumes []vm.Volume
2774+ for _ , vol := range volsByInstance [v .ProviderID ] {
2775+ if _ , ok := deviceByVolumeID [vol .ProviderResourceID ]; ok {
2776+ volumes = append (volumes , vol )
2777+ }
2778+ }
2779+
2780+ // Sort by device name to ensure deterministic ordering that matches
2781+ // the mount point assignment (/mnt/data1, /mnt/data2, etc.).
2782+ slices .SortFunc (volumes , func (a , b vm.Volume ) int {
2783+ return strings .Compare (
2784+ deviceByVolumeID [a .ProviderResourceID ],
2785+ deviceByVolumeID [b .ProviderResourceID ],
2786+ )
2787+ })
2788+ return volumes , nil
27232789}
27242790
27252791type snapshotOutput struct {
@@ -2761,21 +2827,11 @@ func (p *Provider) CreateVolumeSnapshot(
27612827 return vm.VolumeSnapshot {}, err
27622828 }
27632829
2764- // Wait for the snapshot to complete before returning. AWS snapshots
2765- // are asynchronous and cannot be used to create volumes while pending.
2766- waitArgs := []string {
2767- "ec2" , "wait" , "snapshot-completed" ,
2768- "--region" , region ,
2769- "--snapshot-ids" , so .SnapshotID ,
2770- }
2771- if _ , err := p .runCommand (l , waitArgs ); err != nil {
2772- return vm.VolumeSnapshot {}, errors .Wrapf (err , "waiting for snapshot %s to complete" , so .SnapshotID )
2773- }
2774-
27752830 return vm.VolumeSnapshot {
27762831 ID : so .SnapshotID ,
27772832 Name : vsco .Name ,
27782833 Region : region ,
2834+ Status : so .State ,
27792835 }, nil
27802836}
27812837
@@ -2839,6 +2895,7 @@ func (p *Provider) ListVolumeSnapshots(
28392895 ID : so .SnapshotID ,
28402896 Name : name ,
28412897 Region : r ,
2898+ Status : so .State ,
28422899 })
28432900 }
28442901 mu .Lock ()
0 commit comments