import boto, os, time, crt
key_path= ''my keypath"
instance = crt.crtinst('ami-3c47a355')
env.hosts=[instance.dns_name]
print instance.dns_name
env.user='root'
env.key_filename=key_path
def testvol():
conn = boto.connect_ec2()
try:
fo = open('volume10.txt', 'a')
print ('Instance %s has
been created'%instance.id)
#Create Volume
print 'Creating Volume'
start_real_effective= start_real= time.time()
vol = conn.create_volume(10, instance.placement)
end_real=time.time()
while not vol.volume_state()=='available':
time.sleep(1)
vol.update()
end_real_effective=time.time()
fo.write("\nCall Create Volume: %f Real Seconds" % (end_real - start_real))
fo.write("\nEffective Create Volume: %f Real Seconds" % (end_real_effective - start_real_effective))
#Describe Volumes
print '--------Current Volumes------'
start_real=time.time()
print conn.get_all_volumes()
end_real=time.time()
fo.write("\nCall Get Volumes: %f Real Seconds" % (end_real - start_real))
print 'Current status of the volume:'
print vol.id,':',vol.volume_state()
#Attach Volume
print '----------Now the volume is ready to go---------'
start_real_effective=start_real=time.time()
if vol.attach(instance.id, '/dev/sdg'):
print '\nVolume %s has been successfully attached to %s'%(vol.id, instance.id)
end_real=time.time()
while vol.volume_state()!='in-use':
time.sleep(1)
vol.update()
end_real_effective=time.time()
fo.write("\nCall Volume Attachment: %f Real Seconds" % (end_real - start_real))
fo.write("\nEffective Volume Attachment: %f Real Seconds" % (end_real_effective - start_real_effective))
#Get attachment state
start_real_effective=start_real=time.time()
print 'Current Attachment state:', vol.attachment_state()
end_real=time.time()
while vol.attachment_state()!='attached':
time.sleep(1)
vol.update()
end_real_effective = time.time()
fo.write("\nCall Volume Attachment State: %f Real Seconds" % (end_real - start_real))
fo.write("\nEffective Volume
Attachment State: %f Real Seconds" % (end_real_effective - start_real_effective))
info()
#Make Volume Usable
start_real= time.time()
mount_ebs_volue()
end_real = time.time()
fo.write('\nMake Volume Usable: %f Real
Seconds'%(end_real-start_real))
run('df -h')
#Reboot instance
'''start_real_effective= start_real=time.time()
instance.reboot()
end_real=time.time()
while crt.ping(instance)!=True:
time.sleep(1)
print "Instance Rebooted, check to see if volume still mounted"
run('df
-h')'''
#unmount volume
run('umount /mnt/volume')
run('df -h')
#Create a snapshot of the volume
start_real_effective=start_real=time.time()
if vol.create_snapshot('mysnapshot'):
print 'Just created a snapshot of the volume %s' % vol.id
end_real=time.time()
while vol.snapshots()[0].status!='completed':
time.sleep(1)
vol.snapshots()[0].update()
end_real_effective= time.time()
fo.write("\nCall Create Snapshot: %f Real Seconds" % (end_real - start_real))
fo.write("\nEffective Create Snapshot: %f Real Seconds"%(end_real_effective-start_real_effective))
#detach volume
print "-----Now let's detach
the volume from the instance-----"
start_real_effective=start_real= time.time()
vol.detach()
end_real=time.time()
while vol.volume_state()!='available':
time.sleep(1)
vol.update()
end_real_effective=time.time()
fo.write("\nCall Detach Volume: %f Real Seconds" % (end_real - start_real))
fo.write("\nEffective
Detach Volume: %f Real Seconds" % (end_real_effective - start_real_effective))
#Get attachment state
print 'Current Attachment state:', vol.attachment_state()
while vol.attachment_state()=='attached':
time.sleep(1)
vol.update()
snaps = vol.snapshots()[0]
#Delete Volume
print
"--------Now let's delete the volume-----"
start_real_effective=start_real= time.time()
vol.delete()
end_real=time.time()
while vol.id in conn.get_all_volumes():
time.sleep(1)
end_real_effective=time.time()
fo.write("\nCall Delete Volume: %f Real Seconds" % (end_real - start_real))
fo.write("\nEffective Delete Volume: %f Real Seconds" % (end_real_effective - start_real_effective))
#Delete Snapshot
print "------------Let's delete the snapshot-----------"
start_real_effective = start_real = time.time()
snaps.delete()
end_real = time.time()
'''while snaps.status=='completed':
time.sleep(1)
snaps.update()
end_real_effective=time.time()'''
fo.write("\nCall Delete Snapshot: %f Real Seconds" % (end_real - start_real))
#fo.write("\nEffective Delete Snapshot: %f Real Seconds" % (end_real_effective - start_real_effective))
except IOError:
print "Error: can't find file or read data"
finally:
instance.terminate()
while not instance.state == 'terminated':
time.sleep(1)
instance.update()
fo.close()