|
11 | 11 | volume_response=ec2_mgmt_console.describe_volumes()['Volumes']
|
12 | 12 |
|
13 | 13 | attachments=[]
|
14 |
| -volume_instance_infos=[] |
| 14 | +volume_infos=[] |
| 15 | +volume_infos1=[] |
15 | 16 | for each_item in volume_response:
|
16 | 17 | attachments.append(each_item['Attachments'])
|
17 | 18 |
|
18 |
| -for each_attachment in attachments: |
19 |
| - for each_item in each_attachment: |
20 |
| - volume_instance_infos.append(each_item['InstanceId']) |
21 |
| - volume_instance_infos.append(each_item['VolumeId']) |
22 |
| - volume_instance_infos.append(each_item['State']) |
23 |
| - volume_instance_infos.append(each_item['Device']) |
24 |
| - |
25 |
| - |
26 |
| - |
27 |
| - |
28 |
| - |
29 |
| - |
30 |
| -# Get list of all volumes |
31 |
| -#for each_volume in volume_response: |
32 |
| -# print(each_volume['VolumeId'],each_volume['Size'],each_volume['State'],each_volume['VolumeType'],each_volume['AvailabilityZone']) |
| 19 | +# for each_attachment in attachments: |
| 20 | +# for each_item in each_attachment: |
| 21 | +# volume_infos.append(each_item['InstanceId']) |
| 22 | + |
| 23 | +with open('./listvolumes.csv', 'w') as csvfile: |
| 24 | + # Write Header for csv file |
| 25 | + fields = [ 'VolumeId', |
| 26 | + 'Size', |
| 27 | + 'State', |
| 28 | + 'VolumeType', |
| 29 | + 'AvailabilityZone', |
| 30 | + ] |
| 31 | + csvwriter = csv.writer(csvfile) |
| 32 | + csvwriter.writerow(fields) |
| 33 | + |
| 34 | + for each_volume in volume_response: |
| 35 | + # volume_infos1.append(each_volume['VolumeId']) |
| 36 | + # volume_infos1.append(each_volume['Size']) |
| 37 | + # volume_infos1.append(each_volume['State']) |
| 38 | + # volume_infos1.append(each_volume['VolumeType']) |
| 39 | + # volume_infos1.append(each_volume['AvailabilityZone']) |
| 40 | + volume_details = [ |
| 41 | + each_volume['VolumeId'], |
| 42 | + each_volume['Size'], |
| 43 | + each_volume['State'], |
| 44 | + each_volume['VolumeType'], |
| 45 | + each_volume['AvailabilityZone'], |
| 46 | + ] |
| 47 | + csvwriter.writerow(volume_details) |
33 | 48 |
|
34 | 49 |
|
0 commit comments