You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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: