Skip to content
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

Open
purpleidea opened this issue Feb 8, 2024 · 5 comments · May be fixed by #756
Open

lang: funcs: core: os: Add is_virtual function #737

purpleidea opened this issue Feb 8, 2024 · 5 comments · May be fixed by #756

Comments

@purpleidea
Copy link
Owner

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 or load 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.

@jfindlay
Copy link

jfindlay commented Feb 8, 2024

on it

@manojks1999
Copy link

@purpleidea Is this closed?

@purpleidea
Copy link
Owner Author

Send a patch =D

@bearrito
Copy link

bearrito commented Apr 27, 2024

@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

@purpleidea
Copy link
Owner Author

Can you assign this to me.

No need to assign anything, just send a patch and we'll be happy to review it.

@bearrito bearrito linked a pull request Apr 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants