-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Allow QEMU scriptlets to read VM structs and edit QEMU config #1400
Comments
We've so far stayed away from trying to do anything like this, despite it being equally useful for things like cloud-init. Though in the cloud-init case you at least do have the benefit of having both We obviously don't want to change the general behavior of config key overriding through profiles and local config, even just for a few select keys as we really want consistency there. What we could do in theory is provide something like For the scriptlet case, my recommended solution would be to change the scriptlet so it's being fed the instance definition, then a single scriptlet could get through varying behavior based on the instance, its devices or config keys (including Obviously that wouldn't really help you with |
Yeah obviously
Oh I’m not a fan of that AT ALL :) I have two suggestions, both of them having the same pros and cons:
Pros: doesn’t pollute the namespace, processes properties in definition order
But… is it that bad? For the For the templating engine, this would open plenty of possibilities, such as renaming (single) network cards To be honest, I kinda like both solutions, and they are not incompatible. The second one is pretty hard though (e.g. which template parameters do we allow, and for which keys?).
That’s what |
Anything that can't be easily computed through database queries is going to become quite expensive pretty quickly. We have quite a few places, mostly around devices and networks where we need to pretty quickly go over every single instance in the database, pull specific configs (applying all profiles in the process) and then get a list of instances with a specific final value. That's the logic we need to run through to compute things like quotas, current project usage and the used_by field we have just about everywhere in the API. Typically that doesn't impact the So it's one of those cases where I think it's probably a better idea to take a big step back and look at exactly what the current problem is and see if there isn't a better way to solve that problem :) |
One example of something that could be done here is to just make more use of The name of that key means that it's not necessarily tied to QMP. So we could for example introduce a |
That would then in theory let you do everything that you currently want through a single scriptlet. Speaking of, it would probably make sense to expose the instance itself to the QEMU scriptlet, currently we're only passed a bunch of functions and the stage for the hook, but we don't even know the name of the VM we're working against :) |
I mean… sure, but it makes very little sense in most cases where extending an existing key doesn’t have an obvious meaning.
I think you actually summarized it quite well: we want a mechanism like this one at some places, not all of them!
Hey I’ll not be one to say no to a nice little scriptlet, but I feel like it’ll get very hard for people who just want to add something to the QEMU command-line (and there are cases where it cannot be done in the configuration file).
For the name, I’m sure we can get it from QMP :) |
I wouldn't let a scriptlet modify the instance configuration keys, but I would let the QEMU scriptlet specifically modify the QEMU command line and config files right before it's written to disk and executed (only in stage == config). So that would run after any existing This combined with having the instance struct exposed to the scriptlet means that you can write a generic enough scriptlet (in your case the MacOS stuff) which can vary based on the device list, based on instance config and have its own behavior altered by using |
Basically I'm thinking of a way where you can just ship a |
Well now I’m hyped :) (although we’re veeeeeery far from the original message) |
We should provide an Dealing with existing scriptlets is a bit more problematic indeed. |
Ok, pretty simple then (unfortunately not much introspection into devices, so it won’t help with my macOS side quest). As usual, my 200 questions. How do we want to handle the modification of QEMU command line/config file? Make the struct readonly and have the scriptlet in the
Oh yeah, that’s pretty easy. It will only break the last PR that prevents just that :D The real question feels more like “are there enough people that use the feature to actually do more than putting a red alert box in the Incus announcement message and in the forums?” |
What's missing in your case?
I think we can break it this time around. I believe you and I are likely the only two "production" users at this point :)
I'd provide a set of functions:
So you can get the current value, modify whatever you want and send it back. |
The thing is that I don’t know, hence my forum post…
Understandable; using it in prod is pretty cursed.
LGTM. We should trigger an error for the Starlark-go dicts preserve insertion order, so I can propose two transformations for the following: [device "sata0"]
driver = "virtio-blk-pci"
drive = "devzero"
share-rw = "on"
[device "sata1"]
driver = "virtio-blk-pci"
drive = "devzero"
share-rw = "on" Option 1This first option massively uses dicts, but reordering can be tricky, as it involves removing the key and reinserting it. Also, while Starlark-go guarantees to respect insertion order within scriptlets, unmarshalling can get tricky… {
'device "sata0"': {
"driver": "virtio-blk-pci",
"drive": "devzero",
"share-rw": "on"
},
'device "sata1"': {
"driver": "virtio-blk-pci",
"drive": "devzero",
"share-rw": "on"
}
} Option 2Feels easier to implement, but loses the nice dictionary lookup feature… [
{
"key": 'device "sata0"',
"parameters": {
"driver": "virtio-blk-pci",
"drive": "devzero",
"share-rw": "on"
}
},
{
"key": 'device "sata1"',
"parameters": {
"driver": "virtio-blk-pci",
"drive": "devzero",
"share-rw": "on"
}
}
] I’ll let you be the judge. And while we’re at it, we might as well do the same to present cmdline args nicely to the scriptlet (e.g. a list of Also, do we completely throw away the idea of having a function to recall previously defined scriptlets? OT1H, it could allow people to compose scriptlets and achieve some kind of inheritance; OTOH, it would require revamping quite some code handling configuration keys. I don’t mind giving up on that :) Anyway, I’m changing the issue title, and I can commit to implementing it for Incus 6.9, so feel free to assign me the issue. |
Yeah, the For what to expose, it may make sense to expose the config as a Making that code/type shared between the actual config file building and the scriptlet would also make it easy for us to expose a variation of
Yeah, for this one it would make sense to return the args part of
I think so, at least for now, lets wait for a use case that we can't fix cleanly otherwise :)
Excellent. I'll triage this as a new feature for 6.9! |
Any particular reason why I can either convert the entries to a map (and back) in the scriptlet definition, or remove the |
Also, I propose to prevent messing with |
Sounds good
I don't think so. It may have helped with tests but that sounds like a poor reason for it. |
I don’t think it’ll make things any easier, but having clean code feels like a good incentive for change! |
Well I’m getting cold feet… The override mechanism code is lacking precious comments; I can try to patch it, but IMO it will need to be rewritten from scratch. Coming from a safety and formal methods background, I’m not at ease having a configuration parser relying on a big uncommented regex and ad-hoc if-then-else statements… |
raw.qemu*
configuration keys override the ones defined in previous profiles. Sometimes, I’d like to write a profile that defines several keys inraw.qemu.conf
, adds some things inraw.qemu
and does additional processing inraw.qemu.qmp.scriptlet
.And sometimes I’d also like to further modify these QEMU options in my VM settings, without having to repeat everything the profile says.
Could we imagine a mechanism allowing, rather than replacing existing data, appending to them for the
raw.qemu
,raw.qemu.conf
andraw.qemu.qmp.{early,{post,pre}-start}
keys? (Forraw.qemu.qmp.scriptlet
, it gets trickier and I’m not sure what to propose…)The text was updated successfully, but these errors were encountered: