-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
lang: funcs: core: os: Add is_virtual function #737
Labels
Comments
on it |
@purpleidea Is this closed? |
Send a patch =D |
@purpleidea Can you assign this to me. I'm basically just go to port what is done in https://github.com/systemd/systemd/blob/main/src/basic/virt.c#L674 I'm going to start with Docker, Podman, EC2 and GCE |
No need to assign anything, just send a patch and we'll be happy to review it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem statement:
We'd like to have an
is_virtual
function, so that we could detect if we're running on iron or in a virtual machine. We should implement this in pure golang if possible.Goal:
At least initially, let's just support Linux, as we can add other OS support in the future with
go build
drop-ins like we do for other similar functions (see:uptime
orload
for an example)Implementation details:
Of note, this can be a pure function using the simple function API and doesn't require any concurrency! Even though this is really a fact (in puppet terminology) we should probably just use the function API instead, since we'll probably get rid of the dedicated fact API.
If we can do this all in pure golang without having to exec a separate binary (eg: systemd-detect-virt or virt-what) then that is preferred. If we do however have to exec something, please cache the result for future calls.
Testing
I don't have a good story for how we would test this, since we don't have test runners in a variety of different setups yet. Ideas welcome. At a minimum run the function on any platform and make sure it doesn't error.
Edge cases
What about containers? Does an nspawn container running this return true or false for is_virtual? My guess is maybe false
Future work
What about is_container? What about virtual_type()? Do we want constants in $const.func.core.os.virtual_type.kvm ? And so on...
Events?
We don't think we need to worry about the case of this value changing at runtime, so this is okay as-is for now.
The text was updated successfully, but these errors were encountered: