Last active
March 8, 2017 06:29
-
-
Save asangal/f325623326ccda31f91ac6b717ab77b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
# Define the connection | |
ec2 = boto3.resource('ec2', region_name="us-west-2") | |
# Find all volumes | |
volumes = ec2.volumes.all() | |
# Loop through all volumes and pass it to ec2.Volume('xxx') | |
for vol in volumes: | |
#iv = ec2.Volume(str(vol.id)) | |
formatted_tags = [] | |
if vol.tags: | |
for _ in vol.tags: | |
tag_string = '{}({})'.format(_.get('Key'), _.get('Value')) | |
formatted_tags.append(tag_string) | |
if formatted_tags: | |
comma = ',' | |
else: | |
comma = '' | |
print "created(" + str(vol.create_time) + "),availability_zone(" + str(vol.availability_zone) + "),volumeid(" + str(vol.volume_id) + "),volumetype(" + str(vol.volume_type) + "),state(" + str(vol.state) + "),size(" + str(vol.size) + "),iops(" + str(vol.iops) + "),isencrypted(" + str(vol.encrypted) + "),snapshotid(" + str(vol.snapshot_id) + "),kms_keyid(" + str(vol.kms_key_id) + "),instanceid(" + str(vol.attachments[0]['InstanceId']) + "),instancevolumestate(" + str(vol.attachments[0]['State']) + "),deleteonterminationprotection(" + str(vol.attachments[0]['DeleteOnTermination']) + "),device(" + str(vol.attachments[0]['Device']) + ")" + comma + ','.join(formatted_tags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I remove the space character before the , character from if I'm getting the following output.
Created(2015-07-14 20:22:38.829000+00:00),AZ(us-west-2c),VolumeID(vol-e1111111),VolumeType(gp2),State(in-use),Size(8),IOPS(100),IsEncrypted(False),SnapshotID(snap-bd977777),KMS_KEYID(None) ,InstanceID(i-e2222222),InstanceVolumeState(attached),DeleteOnTerminationProtection(True),Device(/dev/sda1) ,generation(2015071401) ,high_availability(1) ,hostname(Gamer-2a-ha1-2015071401) ,Name([Gamer-2a-ha1] 2015071401) ,chef_nodename(Gamer-2a-ha1-2015071401) ,role(ha) ,cluster(Gamer)