Fix root volume to show up in other EC2 volume API calls. Closes 470

This commit is contained in:
Steve Pulec 2015-11-28 09:19:45 -05:00
commit 44f0377cc4
5 changed files with 37 additions and 13 deletions

View file

@ -319,12 +319,6 @@ class Instance(BotoInstance, TaggedEC2Resource):
# If we are in EC2-Classic, autoassign a public IP
associate_public_ip = True
self.block_device_mapping = BlockDeviceMapping()
# Default have an instance with root volume should you not wish to override with attach volume cmd.
# However this is a ghost volume and wont show up in get_all_volumes or snapshot-able.
self.block_device_mapping['/dev/sda1'] = BlockDeviceType(volume_id=random_volume_id(), status='attached',
attach_time=utc_date_and_time())
amis = self.ec2_backend.describe_images(filters={'image-id': image_id})
ami = amis[0] if amis else None
@ -345,11 +339,23 @@ class Instance(BotoInstance, TaggedEC2Resource):
subnet = ec2_backend.get_subnet(self.subnet_id)
self.vpc_id = subnet.vpc_id
self.block_device_mapping = BlockDeviceMapping()
self.prep_nics(kwargs.get("nics", {}),
subnet_id=self.subnet_id,
private_ip=kwargs.get("private_ip"),
associate_public_ip=associate_public_ip)
def setup_defaults(self):
# Default have an instance with root volume should you not wish to override with attach volume cmd.
volume = self.ec2_backend.create_volume(8, 'us-east-1a')
self.ec2_backend.attach_volume(volume.id, self.id, '/dev/sda1')
def teardown_defaults(self):
volume_id = self.block_device_mapping['/dev/sda1'].volume_id
self.ec2_backend.detach_volume(volume_id, self.id, '/dev/sda1')
self.ec2_backend.delete_volume(volume_id)
@property
def get_block_device_mapping(self):
return self.block_device_mapping.items()
@ -420,6 +426,8 @@ class Instance(BotoInstance, TaggedEC2Resource):
for nic in self.nics.values():
nic.stop()
self.teardown_defaults()
self._state.name = "terminated"
self._state.code = 48
@ -546,6 +554,7 @@ class InstanceBackend(object):
for name in security_group_names]
security_groups.extend(self.get_security_group_from_id(sg_id)
for sg_id in kwargs.pop("security_group_ids", []))
self.reservations[new_reservation.id] = new_reservation
for index in range(count):
new_instance = Instance(
self,
@ -555,7 +564,7 @@ class InstanceBackend(object):
**kwargs
)
new_reservation.instances.append(new_instance)
self.reservations[new_reservation.id] = new_reservation
new_instance.setup_defaults()
return new_reservation
def start_instances(self, instance_ids):