Skip to content

Commit

Permalink
Merge pull request #17 from flyingcircusio/PL-131857-signal-cold-rebo…
Browse files Browse the repository at this point in the history
…ot-changes

Pass additional KVM environment parameters into guest on cold boot and in ensure
  • Loading branch information
ctheune authored Oct 16, 2024
2 parents 610cfa5 + 9e42515 commit 25d44d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/fc/qemu/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ def ensure_online_local(self):
# reduce the time we're unnecessarily waiting for timeouts.
self.ensure_thawed()
self.mark_qemu_binary_generation()
self.mark_qemu_guest_properties()

def cleanup(self):
"""Removes various run and tmp files."""
Expand All @@ -1102,6 +1103,24 @@ def ensure_thawed(self):
except Exception as e:
self.log.error("ensure-thawed-failed", reason=str(e))

def mark_qemu_guest_properties(self):
props = {
"binary_generation": self.binary_generation,
"cpu_model": self.cfg["cpu_model"],
"rbd_pool": self.cfg["rbd_pool"],
}
self.log.info(
"mark-qemu-guest-properties",
properties=props,
)
try:
self.qemu.write_file(
"/run/qemu-guest-properties-current",
(json.dumps(props)).encode("utf-8"),
)
except Exception as e:
self.log.error("mark-qemu-guest-properties", reason=str(e))

def mark_qemu_binary_generation(self):
self.log.info(
"mark-qemu-binary-generation", generation=self.binary_generation
Expand Down
18 changes: 18 additions & 0 deletions src/fc/qemu/hazmat/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ class Volume(Image):
),
}

# ENC parameters which should be seeded at boot-time into the VM
ENC_SEED_PARAMETERS = ["cpu_model", "rbd_pool"]

def __init__(self, ceph, name, label):
super(Volume, self).__init__(ceph, name)
self.label = label
Expand Down Expand Up @@ -416,6 +419,21 @@ def seed(self, enc, generation):
os.fchmod(f.fileno(), 0o640)
json.dump(enc, f)
f.write("\n")
# Seed boot-time VM properties which require a reboot to
# change. While some of these properties are copied from
# the ENC data, a separate file allows properties which
# are not exposed to guests through ENC to be added in the
# future.
guest_properties = p.join(fc_data, "qemu-guest-properties-booted")
with open(guest_properties, "w") as f:
props = {}
props["binary_generation"] = generation
for key in self.ENC_SEED_PARAMETERS:
if key in enc["parameters"]:
props[key] = enc["parameters"][key]
json.dump(props, f)
# For backwards compatibility with old fc-agent versions,
# write the Qemu binary generation into a separate file.
generation_marker = p.join(fc_data, "qemu-binary-generation-booted")
with open(generation_marker, "w") as f:
f.write(str(generation) + "\n")

0 comments on commit 25d44d2

Please sign in to comment.