Skip to content

Commit

Permalink
Fix ec2 terminate bug and pycurl string bug
Browse files Browse the repository at this point in the history
  • Loading branch information
imcleod committed Oct 3, 2011
1 parent aa692d9 commit efc7bfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion imgfac/ImageWarehouse.py
Expand Up @@ -203,7 +203,8 @@ def _progress(down_total, down_current, up_total, up_current):
# Upload the image itself
image_size = os.path.getsize(image_file_path)
curl = pycurl.Curl()
curl.setopt(pycurl.URL, object_url)
# Our URL can end up as unicode - only pycurl seems to object - cast to string
curl.setopt(pycurl.URL, str(object_url))
curl.setopt(pycurl.HTTPHEADER, ["User-Agent: Load Tool (PyCURL Load Tool)"])
curl.setopt(pycurl.PUT, 1)
curl.setopt(pycurl.INFILE, image_file)
Expand Down
13 changes: 11 additions & 2 deletions imgfac/builders/Fedora_ec2_Builder.py
Expand Up @@ -473,6 +473,15 @@ def correct_remote_manifest(self, guestaddr, manifest):
# not needed in fedora but unfortunately needed elsewhere
pass

def terminate_instance(self, instance):
# boto 1.9 claims a terminate() method but does not implement it
# boto 2.0 throws an exception if you attempt to stop() an S3 backed instance
# introspect here and do the best we can
if "terminate" in dir(instance):
instance.terminate()
else:
instance.stop()

def push_image_snapshot_ec2(self, target_image_id, provider, credentials):
def replace(item):
if item in [self.ec2_access_key, self.ec2_secret_key]:
Expand Down Expand Up @@ -676,7 +685,7 @@ def replace(item):
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
finally:
self.log.debug("Terminating EC2 instance and deleting temp security group")
instance.terminate()
self.terminate_instance(instance)
key_file_object.close()
conn.delete_key_pair(key_name)
try:
Expand Down Expand Up @@ -964,7 +973,7 @@ def ec2_push_image_upload_ebs(self, target_image_id, provider, credentials):
self.log.debug("Extracted AMI ID: %s " % (ami_id))
finally:
self.log.debug("Terminating EC2 instance and deleting temp security group and volume")
instance.terminate()
self.terminate_instance(instance)
factory_security_group.delete()
key_file_object.close()
conn.delete_key_pair(key_name)
Expand Down

0 comments on commit efc7bfc

Please sign in to comment.