diff --git a/src/fc/qemu/agent.py b/src/fc/qemu/agent.py index d0ef734..640e415 100644 --- a/src/fc/qemu/agent.py +++ b/src/fc/qemu/agent.py @@ -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.""" @@ -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 diff --git a/src/fc/qemu/hazmat/volume.py b/src/fc/qemu/hazmat/volume.py index e7927d5..390f50c 100644 --- a/src/fc/qemu/hazmat/volume.py +++ b/src/fc/qemu/hazmat/volume.py @@ -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 @@ -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")