Skip to content

Account for tagging the root volume after spot loss #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions nixops_aws/backends/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def get_type(cls):
)
spot_instance_price = nixops.util.attr_property("ec2.spotInstancePrice", None)
subnet_id = nixops.util.attr_property("ec2.subnetId", None)
first_boot = nixops.util.attr_property("ec2.firstBoot", True, type=bool)
virtualization_type = nixops.util.attr_property("ec2.virtualizationType", None)

def __init__(self, depl, name, id):
Expand Down Expand Up @@ -1521,14 +1520,12 @@ def create(self, defn, check, allow_reboot, allow_recreate):
nixops.known_hosts.add(self._ip_for_ssh_key(), self.public_host_key)

# Add disks that were in the original device mapping of image.
if self.first_boot:
for device_stored, dm in self._get_instance().block_device_mapping.items():
if device_stored not in self.block_device_mapping and dm.volume_id:
bdm = {"volumeId": dm.volume_id, "partOfImage": True}
self.update_block_device_mapping(
device_stored, bdm
) # TODO: it stores root device as sd though its really attached as nvme
self.first_boot = False
for device_stored, dm in self._get_instance().block_device_mapping.items():
if device_stored not in self.block_device_mapping and dm.volume_id:
bdm = {"volumeId": dm.volume_id, "partOfImage": True}
self.update_block_device_mapping(
device_stored, bdm
) # TODO: it stores root device as sd though its really attached as nvme

# Detect if volumes were manually detached. If so, reattach
# them.
Expand Down Expand Up @@ -1666,7 +1663,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self._conn, volume.id, self.logger
)

# Always apply tags to the volumes we just created.
# Always apply tags to the volumes created
for device_stored, v in self.block_device_mapping.items():
device_real = device_name_stored_to_real(device_stored)

Expand All @@ -1686,12 +1683,11 @@ def create(self, defn, check, allow_reboot, allow_recreate):
volume_tags.update(common_tags)
volume_tags.update(defn.tags)
volume_tags["Name"] = "{0} [{1} - {2}]".format(
self.depl.description, self.name, device_real
self.depl.name, self.name, device_real
)
self._retry(lambda: self._conn.create_tags([v["volumeId"]], volume_tags))
self.update_tags(v["volumeId"], user_tags=volume_tags, check=check)

# Attach missing volumes.

for device_stored, v in self.sorted_block_device_mapping():
if v.get("needsAttach", False):
self.attach_volume(device_stored, v["volumeId"])
Expand Down